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
 

 

Cobol Unstring by two tags

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Cobol Unstring by two tags
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: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Thu Feb 03, 2011 7:40 pm    Post subject:
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    Post subject: Reply to: Cobol Unstring by two tags
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: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Thu Feb 03, 2011 8:55 pm    Post subject:
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: 755
Location: Germany

PostPosted: Tue Feb 08, 2011 3:17 pm    Post subject:
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: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Tue Feb 08, 2011 5:30 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Cobol Unstring by two tags
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    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 XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm


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