View previous topic :: View next topic
Author
Message
gy3c New User Joined: 31 Aug 2022Posts: 5 Location: India
Hello All,
Could someone please help me with a logic for the below requirement. I have two input files
Input file 1:(no duplicates)
100 data1
101 data2
102 data3
103 data4
File 2:
100 1
100 2
100 3
100 4
101 1
101 2
102 1
102 2
103 1
103 2
103 3
104 4
Output file 1:
100 1 data1
100 2
100 3
100 4
101 1 data2
101 2
102 1 data3
102 2
103 1 data4
103 2
103 3
103 4
Can someone help me how to accomplish this using cobol or sort ?
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2144 Location: USA
This question is not related in any manner neither to “COBOL programming”, nor to any other programming language.
This requires only your ability to think logically, and to design algorithms for various tasks.
In your case: you only need to join records from both inputs when 3-bytes keys are equal in both of them, AND the sequence number from the second input equals to 1.
In all other cases you need to use only the record from input two.
P.S.
Usually, this is covered at the Lesson #1 of any programming classes…
P.P.S.
It would be nice if you learned how to use the Code button, when posting your questions.
Back to top
Joerg.Findeisen Senior Member Joined: 15 Aug 2015Posts: 1337 Location: Bamberg, Germany
It's 10 lines of SORT (or less) to achieve this. Also, z/OS mostly knows only Datasets.
Back to top
gy3c New User Joined: 31 Aug 2022Posts: 5 Location: India
Thanks all for the response. The sequence number will not be always 1,2,3,4.It could be a random 3 digit code.sortee in ascending order.
I just posted an example..i will also try some coding today and let know for any doubts.
Back to top
Joerg.Findeisen Senior Member Joined: 15 Aug 2015Posts: 1337 Location: Bamberg, Germany
The beginning of the sequence number doesn't matter. It will always be the first entry from F2 that gets the additional data added. Sample:
Code:
100 2 data1
100 3
100 4
100 9
101 1 data2
101 2
102 1 data3
102 2
103 1 data4
103 2
103 3
Back to top
gy3c New User Joined: 31 Aug 2022Posts: 5 Location: India
Yes,the beginning of sequence number doesn't matter.its always the first one. Because , the input file 2 will be anyways sorted
Back to top
gy3c New User Joined: 31 Aug 2022Posts: 5 Location: India
can someone please let me know if the below logic would work ? and if there is any other easier way of doing it ?
read file1
read file 2
perform until EOF-FILE 1 OR EOF -FILE 2
If file1-key = file2-key
if FLAG-NOT SET
move data to output file
set flag-set to true
end-if
move file 2 to output layout
read file 1
read file 2
end-if
if file 1 < file 2
Write Output file from file 2
read file 1
end if
if file 1 > FILE 2
Write Output file from file 2
READ FILE 2
END-IF
END-PERFORM
Back to top
Joerg.Findeisen Senior Member Joined: 15 Aug 2015Posts: 1337 Location: Bamberg, Germany
Sample, free of charge:
Code:
//WHATEVER EXEC PGM=ICEMAN
//F1 DD *
100 data1
101 data2
102 data3
103 data4
/*
//F2 DD *
100 2
100 3
100 6
100 9
101 5
101 6
102 8
102 9
103 1
103 2
103 6
104 8
/*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=F1,FIELDS=(1,3,A),SORTED
JOINKEYS F2=F2,FIELDS=(1,3,A),SORTED
REFORMAT FIELDS=(F2:1,5,F1:5,8)
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,4,ZD,RESTART=(1,3)))
OUTFIL FNAMES=(SORTOUT),
REMOVECC,
IFTHEN=(WHEN=(81,4,ZD,EQ,+1),BUILD=(1,5,X,6,8)),
IFTHEN=(WHEN=NONE,BUILD=(1,5))
END
/*
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2144 Location: USA
Again:
It would be nice if you learned how to use the Code button, when posting your questions.
Back to top
Lynne Active User Joined: 15 Jan 2015Posts: 107 Location: USA
Read up on the JOIN for Sort (ICEMAN or Syncsort)
and then go thru Joerg.Findeisen's excellent simple example.
Back to top
gy3c New User Joined: 31 Aug 2022Posts: 5 Location: India
Joerg.Findeisen wrote:
Sample, free of charge:
Code:
//WHATEVER EXEC PGM=ICEMAN
//F1 DD *
100 data1
101 data2
102 data3
103 data4
/*
//F2 DD *
100 2
100 3
100 6
100 9
101 5
101 6
102 8
102 9
103 1
103 2
103 6
104 8
/*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=F1,FIELDS=(1,3,A),SORTED
JOINKEYS F2=F2,FIELDS=(1,3,A),SORTED
REFORMAT FIELDS=(F2:1,5,F1:5,8)
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,4,ZD,RESTART=(1,3)))
OUTFIL FNAMES=(SORTOUT),
REMOVECC,
IFTHEN=(WHEN=(81,4,ZD,EQ,+1),BUILD=(1,5,X,6,8)),
IFTHEN=(WHEN=NONE,BUILD=(1,5))
END
/*
Back to top
hyeamit New User Joined: 16 Apr 2009Posts: 1 Location: Jaipur
Thank you. This is useful.
Back to top
Please enable JavaScript!