Records having same value in the key field



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Records having same value in the key field

Postby Nazma » Thu Oct 28, 2010 5:31 pm

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
Nazma
 
Posts: 8
Joined: Fri Jun 13, 2008 4:25 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Records having same value in the key field

 

Re: Records having same value in the key field

Postby Robert Sample » Thu Oct 28, 2010 5:51 pm

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
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Records having same value in the key field

Postby littlechicken » Fri Oct 29, 2010 7:40 am

you do not say how long your keys are can they sustain two records merging? I suspect not.

the previous sample is correct.
littlechicken
 
Posts: 25
Joined: Thu Oct 28, 2010 10:15 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post