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

Concatenate string in a loop into same variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2146
Location: At my coffee table

PostPosted: Tue Oct 09, 2007 6:03 am
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

Moderator Emeritus


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

PostPosted: Tue Oct 09, 2007 8:07 am
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: India

PostPosted: Tue Oct 09, 2007 12:33 pm
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

Moderator Emeritus


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

PostPosted: Tue Oct 09, 2007 6:14 pm
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: India

PostPosted: Tue Oct 09, 2007 7:04 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Oct 09, 2007 11:31 pm
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: India

PostPosted: Wed Oct 10, 2007 9:41 am
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: India

PostPosted: Wed Oct 10, 2007 9:47 am
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

Moderator Emeritus


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

PostPosted: Wed Oct 10, 2007 6:14 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
This topic is locked: you cannot edit posts or make replies. REXX - Do - Not able to LOOP CLIST & REXX 10
Search our Forums:

Back to Top