DeshBhakt
DeshBhakt

Reputation: 157

JCL Combine records in one line

I have 4 datasets each with only one record containing a two digit number. For eg:

File1: 45
File2: 78
File3: 83
File4: 52

I want the data to be merged into a new dataset in this way:

4578
8352

How can I code this in Mainframe-JCL?

Upvotes: 0

Views: 2595

Answers (1)

RainMoose
RainMoose

Reputation: 73

To complete this task, concatenate your four input files to sortin:

//STEP1  EXEC PGM=SORT
//SORTIN DD DSN=File1,DISP=SHR
//       DD DSN=File2,DISP=SHR
//       DD DSN=File3,DISP=SHR
//       DD DSN=File4,DISP=SHR
//SORTOUT DD DSN=Combined
//SYSIN DD *
* Combine each pair of records into a single record
 SORT FIELDS=COPY
* Append a sequence number 00,50,00,50,00,...
 INREC BUILD=(1,2,2X,SEQNUM,2,ZD,START=0,INCR=50)
* Reformat the output record depending on the sequence number
 OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(5,2,CH,EQ,C'00'),
  PUSH=(7:1,2)),
  IFTHEN=(WHEN=GROUP,BEGIN=(5,2,CH,EQ,C'50'),
  PUSH=(9:1,2))
* Include only the second record of each group (the 50 records)
 OUTFIL FILES=OUT,INCLUDE=(5,2,CH,EQ,C'50'),BUILD=(7,4)
 END

For the four Input files:

File1:

45

File2:

78

File3:

83

File4:

52

The Combined output file should be:

4578
8352

This has been verified with AHLSORT for Windows v14r3 but should work with DFSORT or SYNCSORT on z/OS.

Upvotes: 2

Related Questions