Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Concatenate string in a loop into same variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sudhirk63

New User


Joined: 08 Oct 2006
Posts: 19
Location: Bangalore

PostPosted: Tue Oct 09, 2007 5:42 am    Post subject: Concatenate string in a loop into same variable
Reply with quote

Hello All,

Any clues as how can I achive to concatenate records into same variable.

My requirement is to read from a file and concatenate several records into one output record based on certain conditions.

The input can be as :

001AAAA
001BBBBBBB
002CCCCCCCCCC
003DDDDDDDDDDDDD
003EEEEEEEEEE
003FFFFFFFFFF

The output I want to achieve is as, assuming that for a record if first three bytes are same, they merge together into one record. The number of records with same key values are not fixed nor the maximum number of occurence of the same value of the key is know.
001AAAA001BBBBBBB
002CCCCCCCCCC
003DDDDDDDDDDDDD003EEEEEEEEEE003FFFFFFFFFF


In the code, performing in a loop and writing to the same output varaibe does not concatenate the string together.

STRING MOD77IN-FILE-I
DELIMITED BY SIZE
INTO OUT-DATA

This snippet wipes out the previously written data to the OUT-DATA varaible.

Can any one help me as how can I use the STRING function or any other technique to get the desired result.

Thanks in advance for your help.

Sudhir
Back to top
View user's profile Send private message

CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Oct 09, 2007 6:03 am    Post subject: Re: Concatenate string in a loop into same variable
Reply with quote

sudhirk63 wrote:
In the code, performing in a loop and writing to the same output varaibe does not concatenate the string together.
Have you thought of using the POINTER phrase of the STRING statement
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Oct 09, 2007 8:07 am    Post subject:
Reply with quote

Hello,

You may have added difficulty that is not needed. . .

What is the maximum lrecl of an output record?

Seems ike you could read the records and compare the "key". If thi key is the same, simply append "this" record to the "output area" using reference modification and keeping track of where you are in the output area. If the record just read would exceed maximum lrecl, write the record already in the output area, clear the area, and move in the first entry of the next output record.

Unless i've misunderstood, there is no need for a loop or string, just reference-modified moves.

If i've misunderstood, please advise icon_confused.gif
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: Chennai

PostPosted: Tue Oct 09, 2007 12:33 pm    Post subject:
Reply with quote

Hi All,

Use Like this,

Code:
01 WS-NEW-FIELD.
    05 WS-NEW-FIELD-1   PIC X(UR 1ST VARIABLE LENGHT)
    05 WS-NEW-FIELD-1   PIC X(UR 2ND VARIABLE LENGHT)


        EVALUATE TRUE

                 WHEN

                       WS-FIELD-1(WS-INDEXED-1)(1:3) =
                                         WS-FIELD-2(WS-INDEXED-2)(1:3)

                       MOVE WS-FIELD-1(WS-INDEXED-1) TO WS-NEW-FIELD-1
                       MOVE WS-FIELD-2(WS-INDEXED-2) TO WS-NEW-FIELD-2

                       DISPLAY 'COMBINED RECORD' WS-NEW-FIELD

                       WRITE OUT-REC FROM WS-NEW-FIELD


No need to declare index but performance ways, it is better to declare and do it in loop.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Oct 09, 2007 6:14 pm    Post subject:
Reply with quote

Hello,

Please re-read the requirement.

I believe the posted code will not handle the requirement. . .
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: Chennai

PostPosted: Tue Oct 09, 2007 7:04 pm    Post subject:
Reply with quote

Hi Dick,

Quote:
Please re-read the requirement


Quote:
MOVE WS-FIELD-1(WS-INDEXED-1) TO WS-NEW-FIELD-1
MOVE WS-FIELD-2(WS-INDEXED-2) TO WS-NEW-FIELD-2


You are right Dick, But before this need to code some logic I mean For lenght.

Let us know if you got answer.

Thanks DICK.
Back to top
View user's profile Send private message
sudhirk63

New User


Joined: 08 Oct 2006
Posts: 19
Location: Bangalore

PostPosted: Tue Oct 09, 2007 8:51 pm    Post subject: Reply to: Concatenate string in a loop into same variable
Reply with quote

Thanks Cics_guy and Dick. Both pointer and reference modification worked for me.
I have used reference modification as it seemed easier.

Sudhir
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Oct 09, 2007 11:31 pm    Post subject:
Reply with quote

Hello Sudhir,

Thank you for posting your progress icon_smile.gif

Hemanth,

Is there something in my earlier reply that is not clear to you?

If you have a question, please explain what is not clear and i will try to clarify.
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: Chennai

PostPosted: Wed Oct 10, 2007 9:41 am    Post subject:
Reply with quote

Hi Dick,

I got It.. Thanks..
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: Chennai

PostPosted: Wed Oct 10, 2007 9:47 am    Post subject:
Reply with quote

Hi Sudhir,

Quote:
Thanks Cics_guy and Dick. Both pointer and reference modification worked for me.
I have used reference modification as it seemed easier.


Post your answer so that other can also refer the same..
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Oct 10, 2007 6:14 pm    Post subject:
Reply with quote

You're welcome icon_smile.gif
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
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us