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
 

 

UNSTRING the First occurence Alone

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

New User


Joined: 25 Jul 2006
Posts: 24

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

Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
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: 24

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

Active Member


Joined: 13 Feb 2004
Posts: 551
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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

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
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 Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts Problem with UNSTRING of CSV data Bill Woodger COBOL Programming 14 Tue Dec 15, 2015 5:32 pm
This topic is locked: you cannot edit posts or make replies. Stripping off only first occurence of... Jay Villaverde All Other Mainframe Topics 7 Tue Mar 18, 2014 12:38 am
No new posts Unstring in Cobol Govardhana krishna COBOL Programming 7 Thu Oct 17, 2013 8:52 pm
No new posts Unstring the message d katkuri COBOL Programming 13 Wed Aug 14, 2013 12:28 pm


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