Page 1 of 1

Records having same value in the key field

PostPosted: Thu Oct 28, 2010 5:31 pm
by Nazma
Hi,

Can anyone suggest me how to do this using Cobol

input data
x1 abc
x1 def
x2 efr
x2 gre

Need the output lik this
x1 abc def
x2 efr gre

Input is the VSAM file with key having the values of x1,x2,....

Please suggest if someone knows the logic.


Thanks,
Nazma

Re: Records having same value in the key field

PostPosted: Thu Oct 28, 2010 5:51 pm
by Robert Sample
Since the primary key values for a VSAM file must be unique, either your input is wrong:
input data
x1 abc
x1 def
x2 efr
x2 gre
or you are not telling us everything. With only partial information, we can only provide partial solutions. You need to create a variable in working storage with your key value and room for each value you need to output. What is the maximum number you can have? Are they all three bytes long? Do you need a space separating them?

Pseudocode (untested) to do this:
Read first record and move key, data to hold area
Loop
Read record
If key matches hold key, append data to end of hold record
Otherwise, output record and move key, data to hold area
until end-of-file

Re: Records having same value in the key field

PostPosted: Fri Oct 29, 2010 7:40 am
by littlechicken
you do not say how long your keys are can they sustain two records merging? I suspect not.

the previous sample is correct.