Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Having problen while using string

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Having problen while using string
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: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 07, 2012 6:21 am    Post subject:
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    Post subject: Reply to: Having problen while using string
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    Post subject:
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: 269
Location: Mumbai

PostPosted: Wed Mar 07, 2012 1:36 pm    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Wed Mar 07, 2012 2:50 pm    Post subject: Reply to: Having problen while using string
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Wed Mar 07, 2012 10:04 pm    Post subject: Re: Having problen while using string
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    Post subject:
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    Post subject: Reply to: Having problen while using string
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Thu Mar 08, 2012 1:03 am    Post subject: Reply to: Having problen while using string
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us