Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

usage of STRING in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Sun Apr 05, 2009 10:42 am    Post subject: usage of STRING in COBOL
Reply with quote

Hi

I have two variable VAR1 and VAR2 which i need to concatenate or string using STRING.

VAR 1 - is of var length (but max is 20)
VAR2 - is of var length (but max is 30)

VAR3 - is o/p and max length is 30.

VAR1 is input . For e.g let there be to cases where VAR1 - can be " Hello" or " Excellent" ..So length in both cases is diferent . It's 5 for 1st case and 9 for 2nd case.

VAR2 - "Good Work,keep it up"

Now when i string VAR1 and VAR2 , i should get o/p as
"Hello Good work,keep it up" with 1st input. and
"Excellent Good work,keep it up" with 2nd input.

My doubt is how should VAR1 and VAR2 be declared and what should be syntax of STRING to get the desired result as data present in VAR1 and VAR2 keep varyng.
Back to top
View user's profile Send private message

CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Sun Apr 05, 2009 7:12 pm    Post subject:
Reply with quote

Assuming that var1 & var2 have double spaces only after the data and not between the words....
Code:
var1 pic x(20)
var2 pic x(30)
var3 pic x(30)

Move whatever to var1
Move whatever-else to var2
Move spaces to var3               (very important)

String var1 delimited by '  '     (two spaces)
       ' ' delimited by size      (single space)
       var2 delimited by size
    into var3

STRING statement
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Apr 07, 2009 11:40 am    Post subject: Reply to: usage of STRING in COBOL
Reply with quote

Ambili S, what if var1 and var2 use their maximum lengths provided.In that case it would certainly exceed the output variable var3 length (i.e. 30).
Its better to increase the length of the output variable to 50 as to avoid data truncation.

WTF
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us