View previous topic :: View next topic
|
Author |
Message |
rajeshwarch
New User
Joined: 24 Mar 2008 Posts: 29 Location: mumbai
|
|
|
|
Hi Everybody,
I have a string of length 1000. I need to unstring it based on interim spaces and then load these unstringed strings into internal table.
For Example:
01 ws-string pic x(1000).
ws-string having the below data:
AB RES MAIN ADA JCL CICS
And i have a internal table defined like:
01 ws-table.
05 ws-unstring pic x(4) occurs 250 times.
After unstring the above exampled string Iam expecting to load the ws-table like
ws-unstring(1) - AB
ws-unstring(2) - RES
ws-unstring(3) - MAIN
ws-unstring(4) - ADA
ws-unstring(5) - JCL
ws-unstring(6) - CICS
Can we do this by using UNSTRING or INSPECT verbs. If so Please update me. |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
i think the better option is UNSTRING DELIMITED BY SPACES option |
|
Back to top |
|
|
hemantasr
New User
Joined: 28 Jan 2006 Posts: 1
|
|
|
|
See if the below Code works :-
PERFORM UNTIL WS-COUNT-SPACES > 0
Unstring WS-STRING delimited by Spaces into
WS-UNSTRING(W-IDX),WS-STRING-REST
MOVE WS-STRING-REST to WS-STRING
INSPECT WS-STRING TALLYING WS-COUNT-SPACES FOR ALL SPACES
ADD +1 TO WS-IDX
END-PERFORM
I think above code should work.I did not test it but just wrote it over a paper to test if it work fine. |
|
Back to top |
|
|
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
Hi rajeshwarch,
We had similar condition in one of our program. I specified below what we did to achieve this task.
1. UNSTRING WS-STRING (WS-START-POS:WS-STR-LEN)
DELIMITED BY SPACE
INTO WS-UNSTRING (WS-IDX)
COUNT IN WS-UNSTRING-LEN
2. ADD WS-UNSTRING-LEN TO WS-START-POS
3. ADD 1 TO WS-START-POS
4. SUBTRACT WS-START-POS FROM WS-STR-LEN
5. SUBTRACT 1 FROM WS-STR-LEN
6. Repeat the steps 1 to 5 until input string extraction completes(if you know how manu sub strings you are expecting in the input string) OR
WS-STRING (WS-START-POS:WS-STR-LEN) equal to SPACES
Hope this information is useful to you |
|
Back to top |
|
|
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
oops,
I missed WS-IDX increment inside the loop in my earlier reply.
We have to have that statement inside the loop |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Possibly there is something i misunderstand, but why is anything more than the single UNSTRING needed? |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Dick,
I guess more than one will be required as rajesh wants the output in a table. If i am correct, we can do the same in a single UNSTRING, but the code would look something like this
Code: |
UNSTRING ws-string
DELIMITED BY SPACE INTO
ws-unstring (1)
ws-unstring (2)
ws-unstring (3)
ws-unstring (4)
:::::
ws-unstring(249)
ws-unstring(250)
|
which i guess is not appreciated...
Please do correct me if i am wrong... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
which i guess is not appreciated.. |
Possibly. . . I'd not want to sacrifice all of the cpu cycles needed to do this using iterative loops to accomplish the moves. |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi,
I guess the performance v/s readability is an argument which will always be there...
Some time back i remember our clients had raised a concern coz we included an IF condition which looked like
Code: |
if <cond1>
stat1
else if <cond2>
stat2
else if <cond3>
stat3
:: ::
else
statn
|
which was spread across a couple of pages. They were concerned that a single statement ( IF ) is taking more than one page. I guess they were okay with having everything as simple IF statments with no ELSE so that the same is a little more readable... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I guess the performance v/s readability is an argument which will always be there. |
Please explain how an unstring is less readable than the convoluted looping. . .
From my perspective, the unstring both reads easily and far outperforms looping.
I also believe that it is quite do-able to write code that both performs well and is easily maintainable/readable. |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi,
Quote: |
Please explain how an unstring is less readable than the convoluted looping. . . |
I was merely trying to say that some clients dont consider it readable, as a single statement takes more than one page...
And to be frank... i also do think its better to loop than have it as a single statement...
Maybe as time goes on i might realize that its stupid... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Maybe as time goes on i might realize that its stupid... |
There are many things to learn and there are many opinions that vary. . .
In program code (as with sql) often the smallest amount code is not the better alternative.
Quote: |
some clients dont consider it readable, as a single statement takes more than one page |
If such code is performed, there is only 1 line of code in the mainline. This retains the readability and the performance. . . |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Thanks for the inputs Dick... |
|
Back to top |
|
|
|