View previous topic :: View next topic
|
Author |
Message |
rakesh1155
New User
Joined: 21 Jan 2009 Posts: 84 Location: India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
rakesh1155
New User
Joined: 21 Jan 2009 Posts: 84 Location: India
|
|
|
|
Thank You Robert! It worked.
I never thought of the OVERFLOW thing. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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! |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
rakesh1155
New User
Joined: 21 Jan 2009 Posts: 84 Location: India
|
|
|
|
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 |
|
|
|