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

Cobol Unstring by two tags


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Thu Feb 03, 2011 7:14 pm
Reply with quote

Hi,

I have a string which looks like below:

Code:
InitialData[Data1][Data2]...[Datan]FinalData


I was planning to unstring in a loop to get Data1, Data2... and so on.

I am aware we can use the below command
Code:
UNSTRING ws-variable
DELIMITED BY '[' OR ']'
INTO dummy-variable, data-variable
END-UNSTRING


With this command, "InitialData" goes into dummy-variable; and "Data1" goes into data-variable.

Is there a way to retrieve the rest of the string in a third variable ??

-Thanks,
Rakesh.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 03, 2011 7:40 pm
Reply with quote

Yes, if you modify your code slightly to use refernce modification:
Code:
           05  DUMMY-COUNT             PIC 9(02) VALUE ZERO.
           05  DATA-COUNT              PIC 9(02) VALUE ZERO.
           05  WS-B                    PIC X(80) VALUE
               'INITIALDATA[DATA1][DATA2]...[DATAN]FINALDATA'.
           05  DUMMY-VARIABLE          PIC X(80).
           05  DATA-VARIABLE           PIC X(80).
           05  REST-VARIABLE           PIC X(80).
       PROCEDURE DIVISION.
           UNSTRING WS-B
               DELIMITED BY [ยท' OR ']'
               INTO DUMMY-VARIABLE COUNT IN DUMMY-COUNT,
                    DATA-VARIABLE  COUNT IN DATA-COUNT
               ON OVERFLOW MOVE WS-B (DUMMY-COUNT + DATA-COUNT + 3 :)
                                       TO  REST-VARIABLE
           END-UNSTRING.
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Thu Feb 03, 2011 8:44 pm
Reply with quote

Thank You Robert! It worked.

I never thought of the OVERFLOW thing.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 03, 2011 8:55 pm
Reply with quote

OVERFLOW in UNSTRING is helpful when you want to use the rest of the variable for something -- it's not just for errors!

Anyway, glad to hear it worked! icon_smile.gif
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Feb 08, 2011 3:17 pm
Reply with quote

Hi Robert !

Many thanks, you made an old man wiser.
Never thought about overflow.

Only one question: why +3 and not +2 ???
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Feb 08, 2011 5:30 pm
Reply with quote

UmeySan, I have no idea why +3 and not +2. I tested with +2 originally and REST-VARIABLE started with the right bracket instead of the left bracket. Since I cut and pasted the data from the post, maybe there's a non-printing character in there?

If I get a chance, I'll do some more testing to see if I can figure out what's going on.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Tue Feb 08, 2011 7:39 pm
Reply with quote

If the OP's requirement was accurate, then REST-VARIABLE actually SHOULD start with the left bracket following the right bracket that terminates DATA1, not the 'D' that begins DATA2.
To start REST-VARIABLE with the 'D' of DATA2, the offset must be 3, not 2.
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Thu Feb 10, 2011 2:01 pm
Reply with quote

Hi,

The 'ON OVERFLOW' MOVE statement is using the reference modification to move the rest of the string....

We use +2 for the left and the right bracket which would give the end location where the first right bracket ends;

The additional +1 is because of the reference modification where we need to specify the starting position.

Please correct me if I m mistaken.

-Rakesh Handi.
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top