IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Having problen while using string


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jpsiddharth

New User


Joined: 21 Feb 2005
Posts: 7

PostPosted: Wed Mar 07, 2012 5:39 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 07, 2012 6:21 am
Reply with quote

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
View user's profile Send private message
jpsiddharth

New User


Joined: 21 Feb 2005
Posts: 7

PostPosted: Wed Mar 07, 2012 1:14 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Mar 07, 2012 1:20 pm
Reply with quote

what is the size of element ws-table?
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Mar 07, 2012 1:36 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Mar 07, 2012 1:40 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Wed Mar 07, 2012 2:50 pm
Reply with quote

Quote:
Having problen while using string

You asked for it
You are going to lose Your shoe icon_biggrin.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Mar 07, 2012 10:04 pm
Reply with quote

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

Code:
ABC, DEF, GHI


but its Coming as

Code:
ABC,,GHI


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
Code:
ABC, DEF, GHI, JKL


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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Mar 07, 2012 10:46 pm
Reply with quote

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
View user's profile Send private message
jpsiddharth

New User


Joined: 21 Feb 2005
Posts: 7

PostPosted: Thu Mar 08, 2012 12:02 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Mar 08, 2012 1:03 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Mar 08, 2012 1:29 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts ICETOOL to SUM String DFSORT/ICETOOL 1
No new posts Mark Previous & next lines when a... DFSORT/ICETOOL 9
No new posts sort to find out the char which repea... Mainframe Interview Questions 10
No new posts Help with C character vs C string All Other Mainframe Topics 3
Search our Forums:

Back to Top