View previous topic :: View next topic
|
Author |
Message |
vinit_infy Warnings : 1 New User
Joined: 07 Apr 2005 Posts: 56
|
|
|
|
I want to break up a string having words concated with '.' as:
aaaa.bbbb.ddddfdfdf.ttrttrtr.eeeee.ffff
but every time the words lengh can be vary. I would like to know can we specify
variables varying with the numbers of words with the INTO clause of UNSTRING
I.e.,
here UNSTRING ..... DELIMITED BY '.'
INTO TEMP1 TEMP2 TEMP3 TEMP4 ..
SO I WANT THE ALLOCATION OF TEMP VARIABLE DYNAMICALLY. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Been discussed lately, start here |
|
Back to top |
|
|
pingte
Active User
Joined: 03 Dec 2005 Posts: 120 Location: india
|
|
|
|
u can use a dynamic array in cobol for this purpose....
then u don't need to specify length of the variable... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post some code to show how your solution would be implemented. |
|
Back to top |
|
|
pingte
Active User
Joined: 03 Dec 2005 Posts: 120 Location: india
|
|
|
|
u can declare the array as...
Code: |
01 ws-array.
05 ws-var occurs 1 to 999 times
depending on ws-length. |
in this dynamic array you do not need to specify the length. you can dynamically count length (after using unstring operation)and move it to ws-length variable.
hope this works.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post the unstring code as well. |
|
Back to top |
|
|
pingte
Active User
Joined: 03 Dec 2005 Posts: 120 Location: india
|
|
|
|
suppose you store ur string in a variable WS-STR
then try using this code...
Code: |
UNSTRING WS-STR DELIMITED BY '.'
INTO WS-ARRAY(1) COUNT IN WS-LENGTH
WS-ARRAY(2) COUNT IN WS-LENGTH
WS-ARRAY(3) COUNT IN WS-LENGTH
.........
.........
WS-ARRAY(999) COUNT IN WS-LENGTH
END-UNSTRING.
hope this works.. :) |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Your unstring does not match your variable names.
WS-ARRAY cannot be subscripted - it is the overall group item.
The UNSTRING moves delimited data from one field (string) into multiple fields. The posted solution only has 1 field. If it worked at all, i do not believe the result would be what is desired. Please try that solution and post your results.
Back to the original question - there is a limit to the number of delimited fields that will be present in the string. Define a series of working data fields (in an array) of that number plus 1 (your "business rules" will determine that maximum number of fields that could be present). Each of these fields must be long enough to hold the largest possible field length. When these fields are defined, also define a second array for a "length field" for each. Process the unstring recording the length for each unstrung field. Include the "tallying" option. After the unstring, the field specified for tallying will have the field count of the number of items that were unstrung. You need to set that field to zero before each unstring. The array needs to be cleared before each unstring also to make sure there is no "leftover" data from the previous unstring. If you use 2 arrays for the fields and the lengths, a simple "move spaces" will clear the field array.
When the unstring completes, you will have a table of the unstrung fields as well as the length of the data in those fields. You will also have a count of how many components the unstring broke the "string" into.
Now, write a loop to process the array one field at a time, doing whatever you need to do. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Quote: |
You can unstring each field in a perform loop until overflow using the pointer function of the unstring to maintain position.
And because you are going to ask, something like this:
Code: |
move 1 to P
perform varying sub from 1 by 1
until UOVER
unstring field delimited by thingy
into area(sub)
with pointer P
on overflow set UOVER to true
end-unstring
end-perform |
|
|
|
Back to top |
|
|
|