View previous topic :: View next topic
|
Author |
Message |
jpsiddharth
New User
Joined: 21 Feb 2005 Posts: 7
|
|
|
|
Hi,
I have coded following logic
MOVE WS-ABC (1) TO WS-XYZ-LIST
PERFORM VARYING X-CNT FROM 2 BY 1
UNTIL X-CNT > WS-CNT
STRING WS-XYZ-LIST DELIMITED BY SPACE
C-COMMA DELIMITED BY SIZE
WS-ABC (X-CNT) DELIMITED BY SPACE
INTO WS-XYZ-LIST
END-STRING
END-PERFORM
I need O/P as
ABC, DEF, GHI
but its Coming as
ABC,,GHI
Need to know what I am doing wrong...
Thanks for your help |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Your post is as clear as mud. Where did the DEF come from? You ARE aware, aren't you, that a STRING VAR-1 C-COMMA VAR-2 will NEVER result in more than two variables going into the output variable, right? And using PERFORM just means you repeat the STRING multiple times -- you don't get each additional variable tacked onto the end?
Why don't you go back to the beginning, tell us what problem you are wanting to solve, and let us provide suggestions? |
|
Back to top |
|
|
jpsiddharth
New User
Joined: 21 Feb 2005 Posts: 7
|
|
|
|
Hi Robert,
I need to string all the occurence of a table.
For ex:
If
WS-TABLE(1) = ABC
WS-TABLE(2) = DEF
WS-TABLE(3) = GHI
WS-TABLE(4) = JKL
Then I need to string all the values of the table and o/p should be as
ABC, DEF, GHI, JKL
And the table occurence is not fix it could vary from 0 to n. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what is the size of element ws-table? |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Also please specify what is the size of WS-XYZ-LIST in which your combining all occurances of the table.
Size of WS-XYZ-LIST should be that much enough to accomodate all occurances of table.
Regards,
Chandan |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Size of WS-XYZ-LIST should be that much enough to accomodate all occurances of table. |
plus 1 comma for each used item. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
Quote: |
Having problen while using string |
You asked for it
You are going to lose Your shoe |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Quote: |
Code: |
MOVE WS-ABC (1) TO WS-XYZ-LIST
PERFORM VARYING X-CNT FROM 2 BY 1
UNTIL X-CNT > WS-CNT
STRING WS-XYZ-LIST DELIMITED BY SPACE
C-COMMA DELIMITED BY SIZE
WS-ABC (X-CNT) DELIMITED BY SPACE
INTO WS-XYZ-LIST
END-STRING
END-PERFORM |
I need O/P as
but its Coming as
Code: |
WS-TABLE(1) = ABC
WS-TABLE(2) = DEF
WS-TABLE(3) = GHI
WS-TABLE(4) = JKL |
Then I need to string all the values of the table and o/p should be as
And the table occurence is not fix it could vary from 0 to n. |
jpsiddharth,
Putting together the information from your earlier posts, and "coding" them (don't they look easier to use that way?), I have the above.
You say your table can contain zero entries? The code you have shown does not cater for that.
You say you want spaces after the commas? The code you have shown does not cater for that.
If you had spaces after the commas, you'd "loose" data every time you did other than the first STRING, as you DELIMIT by space. Curiously, you'd get the output you describe (ABC,,GHI).
So, let's take a guess and say you have a definition something like this:
Code: |
01 C-COMMA PIC XX VALUE ", ". |
For what you want, you should look at the POINTER part of the STRING statement in the Language Reference. Save all that continually stringing of your output field as well.
You need to deal correctly with zero and one entries in your table.
The output field I imagine you have the length of from your program specification. It does not need to be long enough to hold all the entries. Ideally it should be long enough to hold all the data in the entries, plus, as dbz has said, the commas (one less than number of entries), plus the space associated with the commas. Ideally doesn't always happen. You also need code to check that you haven't exhausted your output field, and deal with that appropriately if it occurs. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you never did bother to answer the question of length of item
but,
TS hasn't been back so i imagine he has cobbled together
something that get his ass bitten if he has a decent QA team
otherwise his garbage will go into production.
be we don't care about that.
paying attention to all the caveats about lengths that Bill brought up
i will share a little routine that I use when I have to include a space between 'STRUNG' values:
if you would string ',@' instead of ', '
in your perform, it will work.
then when you are finished,
INSPECT CONVERTING '@' BY SPACE.
obviously, you can use any character that you want to represent a space.
i find the 'at-sign' and 'hashmark' to quite usable.
I find that the code is easier to follow using the 'dummy' place marker and then converting when finished.
sort of like dealing with single and double quotes in rexx.
dealing with POINTER, i believe, is beyond the TS's ability,
especially since he could not get this to work.
Bill, anything you would like to add? |
|
Back to top |
|
|
jpsiddharth
New User
Joined: 21 Feb 2005 Posts: 7
|
|
|
|
Hi DBZ,
Thanks for the suggestion...
I have corrected my code and its working fine now....
Once again Thank you all for your time.
Regards,
Siddharth |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
One entry does work as you have it.
Zero entries does not, picks up whatever rubbish is left lying around in the table from the previous thing through it. Bearing in mind that the "rubbish" will look pretty normal, I'm sure it'll at least got caught by a user at some point.
You done anything about checking the size of your created field?
The pointer would also be useful for knowing the total size strung... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
if you were to modify this:
Quote: |
PERFORM VARYING X-CNT FROM 2 BY 1
UNTIL X-CNT > WS-CNT
STRING WS-XYZ-LIST DELIMITED BY SPACE
C-COMMA DELIMITED BY SIZE
WS-ABC (X-CNT) DELIMITED BY SPACE
INTO WS-XYZ-LIST
END-STRING
END-PERFORM
|
To this:
Code: |
INITIALIZE WS-XYZ-LIST
PERFORM VARYING X-CNT
FROM 2 BY 1
UNTIL X-CNT > WS-CNT
IF WS-ABC (X-CNT) > SPACE
THEN
STRING WS-XYZ-LIST
DELIMITED BY SPACE
C-COMMA
DELIMITED BY SIZE
WS-ABC (X-CNT)
DELIMITED BY SPACE
INTO WS-XYZ-LIST
END-STRING
END-IF
END-PERFORM
|
you won't incur the problem of having ,,,,, due to empty items.
and as Bill said,
initialize your table before populating
and
insure that WS-XYZ-LIST is of appropriate length. |
|
Back to top |
|
|
|