IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

usage of STRING in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2146
Location: At my coffee table

PostPosted: Sun Apr 05, 2009 7:12 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top