Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
UNSTRING the First occurence Alone

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL
Author Message
rathinakarthik

New User


Joined: 25 Jul 2006
Posts: 22

PostPosted: Thu Apr 24, 2008 6:16 pm    Post subject: UNSTRING the First occurence Alone
Reply with quote

Hi,

I have a string
Say Str1 = 'a,b,c,d,e'

I want to split this into two variables based on comma as separator. The values of two variables need to be

Var1 = 'a'
Var2 = 'b,c,d,e'

Again i have to take var2 and split based on comma into 'b' and 'c,d,e' and similarly it goes on.

I used UNSTRING to try this

UNSTRING Str1
DELIMITED BY ','
INTO VAR1, VAR2
END-UNSTRING

But the values i got are
Var1 = 'a'
Var2 = 'b'

I need value of var2 as 'b,c,d,e'
Can we prevent Unstring option from delimiting the receiving field?
I want to Delimit based in First occerenc alone
Is there any Option for this. Please advise

Thank you
Back to top
View user's profile Send private message
References
PostPosted: Thu Apr 24, 2008 6:16 pm    Post subject: Re: UNSTRING the First occurence Alone Reply with quote

Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 67
Location: chennai

PostPosted: Thu Apr 24, 2008 6:27 pm    Post subject:
Reply with quote

Hi,

Could you please post declarations of var1 and var2.
Back to top
View user's profile Send private message
rathinakarthik

New User


Joined: 25 Jul 2006
Posts: 22

PostPosted: Thu Apr 24, 2008 6:56 pm    Post subject: Reply to: UNSTRING the First occurence Alone
Reply with quote

Hi,

var1 will be pic x(1)
var2 will be pix x(20)

Thanks
Back to top
View user's profile Send private message
ashimer

Senior Member


Joined: 13 Feb 2004
Posts: 348
Location: Bangalore

PostPosted: Thu Apr 24, 2008 7:10 pm    Post subject:
Reply with quote

try this way ...

var1 pic x(1)
vart pic x(1)
var2 pic x(20)


UNSTRING Str1
INTO VAR1, VART, VAR2
END-UNSTRING

after this stmt ull get a in var1 comma in vart and b,c,d,e in var2

now move var2 to str1 and do the following steps again for b,c,d,e

try and let us know ...

thanks
ashimer
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 8034
Location: 221 B Baker St

PostPosted: Thu Apr 24, 2008 9:18 pm    Post subject:
Reply with quote

Hello,

Quote:
Again i have to take var2 and split based on comma into 'b' and 'c,d,e' and similarly it goes on.
Do you really need this or is the requirement to get 5 vars with the values a thru e (var1 = a, var2 = b, etc.)? What use is a variable with 'c,d,e' (other than to further break it down)?

A single unstring delimited by ',' naming 5 vars would break the entire field - which sounds like what your are coding to reach.
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 8034
Location: 221 B Baker St

PostPosted: Thu Apr 24, 2008 9:55 pm    Post subject:
Reply with quote

Hello again,

If you really wanted to unstring the first comma-delimited value into a variable and all of the other values into a second variable you could use:

Code:
      01  SOME-DATA.                               
          05 STR1  PIC X(09) VALUE 'A,B,C,D,E'.     
          05 VAR1  PIC X(20).                       
          05 VAR2  PIC X(20).                       
     *                                             
      PROCEDURE DIVISION.                           
      000-STUFF.                                   
          DISPLAY 'STR1 = ' STR1.                   
          INSPECT STR1 REPLACING FIRST ',' BY '\'   
          UNSTRING STR1 DELIMITED BY '\'           
              INTO VAR1                             
                   VAR2.                           
          DISPLAY 'STR1 = ' STR1.                   
          DISPLAY 'VAR1 = ' VAR1.                   
          DISPLAY 'VAR2 = ' VAR2.                   
          GOBACK.           


which gives:
Code:
STR1 = A,B,C,D,E       
STR1 = A\B,C,D,E       
VAR1 = A               
VAR2 = B,C,D,E


This approach will work even if the delimited values are variable length, not just 1 byte.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1