Example 1: Alocate PS dataset using IEFBR14 UTILITY
//STEP01 EXEC PGM=IEFBR14 //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSDUMP DD SYSOUT=* //DD1 DD DSN=userid.IBMMF.PSFILE, // DISP=(NEW,CATLG,DELETE),VOLUME=SER=DEVL, // SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA, // DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800) //* |
Example 2: Input file has one or more records for same employee number. Write unique records to output.
//STEP010 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SORTIN DD DSN=userid.IBMMF.INPUT,DISP=SHR //SORTOUT DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //SYSIN DD * SORT FIELDS=(1,15,ZD,A) SUM FIELDS=NONE /* |
SUM FIELDS=NONE removes duplicates on fields specified in SORT FIELDS. In the above example, employee number is in the field position 1,15. The output file will contain the unique employee numbers sorted in ascending order.
Example 3: A file has 100 records. The first 10 records need to be written to output file unsing ICETOOL utility.
//STEP01 EXEC PGM=ICETOOL //TOOLMSG DD SYSOUT=* //DFSMSG DD SYSOUT=* //IN1 DD DSN=userid.IBMMF.INPUT,DISP=SHR //OUT1 DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //TOOLIN DD * COPY FROM(IN1) TO(OUT1) USING(CTL1) /* //CTL1CNTL DD * OPTION STOPAFT=10 /* |
The option STOPAFT will stop reading the input file after 10th record and terminates the program. Hence, 10 records are written to output.
Example 4: A file has 100 records. The first 10 records need to be written to output file using SORT utility.
//STEP01 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SORTIN DD DSN=userid.IBMMF.INPUT,DISP=SHR //SORTOUT DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //SYSIN DD * OPTION COPY,STOPAFT=50 /* |
The option STOPAFT will stop reading the input file after 10th record and terminates the program. Hence, 10 records are written to output.
Example 4: A file has 100 records. The first 10 records need to be written to output file using IDCAMS utility.
//STEP1 EXEC PGM=IDCAMS,REGION=6M //SYSPRINT DD SYSOUT=* //DD01 DD DSN=userid.IBMMF.INPUT,DISP=SHR //DD02 DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //SYSIN DD * REPRO IFILE(DD01) OFI |
The option COUNT will stop reading the input file after 10th record and terminates the program. Hence, 10 records are written to output.
Example 5: Adding a sequence number to the output file.
//STEP01 EXEC PGM=SORT //SORTIN DD * input record1 input record2 input record3 /* //SORTOUT DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSIN DD * OPTION COPY BUILD=(1:1,15,16:SEQNUM,4,ZD,START=1000,INCR=2) /* |
4-digit sequence number is added in output at position 10, starting at 1000 and incremented by 2 for every record.
Ouput File:
12345678901234567890 ---> Column input record1 1000 input record2 1002 input record3 1004 |
Example 6: Overwrite input record content.
//STEP01 EXEC PGM=SORT //SORTIN DD DSN=userid.IBMMF.INPUT,DISP=SHR //SORTOUT DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSIN DD * OPTION COPY INREC OVERLAY=(47:1,6) /* |
In the input file, the content in position 1,6 is overwritten to the position 47,6 and then copied to the output file. INREC OVERLAY operation is used in order to rewrite data in input file before copying to output.
Example 7: Adding Header/Trailer to output file.
//STEP01 EXEC PGM=SORT //SORTIN DD * indata1 indata2 indata3 /* //SORTOUT DD DSN=userid.IBMMF.OUTPUT,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTFIL REMOVECC, HEADER1=(1:C'HDR',11:X'020200825C'), TRAILER1=(1:C'TRL',TOT=(11,9,PD,TO=PD,LENGTH=5)) /* |
TOT calculates the number of records in the input file. HDR and TRL are added as identifiers to header/trailer, which is user defined and can be customised as per the users' needs.
Ouput File:
12345678901234567890 ---> Column HDR 20110131 indata1 indata2 indata3 TRL 00003 |
Example 8: Backing up a file.
//STEP001 EXEC PGM=IEBGENER //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //SYSOUT DD SYSOUT=* //SYSUT1 DD DSN=userid.IBMMF.INPUT,DISP=SHR //SYSUT2 DD DSN=userid.IBMMF.OUTPUT, // DISP=(NEW,CATLG,DELETE), // DCB=*.SYSUT1,SPACE=(CYL,(50,1),RLSE) |
IEBGENER copies the file in SYSUT1 to file in SYSUT2. Please note that file in SYSUT2 takes the same DCB as that of the SYSUT1 in this example.
Example 9: Conditional Processing in SORT.
//STEP001 EXEC PGM=SORT //SORTIN DD * 123456789012345 ---> Column HEADRselect DETAL TRIALselect /* //SORTOUT DD DSN=userid.IBMMF.OUTPUT, // DISP=(NEW,CATLG,DELETE), // DCB=*.SYSUT1,SPACE=(CYL,(50,1),RLSE) //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSIN DD * INREC IFTHEN=(WHEN=(6,1,CH,NE,C' '),BUILD=(1:1,15), IFTHEN=(WHEN=(6,1,CH,EQ,C' '),BUILD=(1:1,5,7:C'RECORD') OPTION COPY /* |
Based on the 6th position of the file, the BUILD of output file varies. If 6th position is SPACES, then text "RECORD" is appended to input record. Else, the input record is written to output, as-is.
Output File:
123456789012345 ---> Column HEADRselect DETAL RECORD TRIALselect |
Example 10: File Comparison using SORT utility.
//STEP001 EXEC PGM=SORT //MAIN DD * 1000 1001 1003 1005 //LOOKUP DD * 1000 1002 1003 //MATCH DD DSN=userid.IBMMF.MATCH,DISP=OLD //NOMATCH1 DD DSN=userid.IBMMF.NOMATCH1,DISP=OLD //NOMATCH2 DD DSN=userid.IBMMF.NOMATCH2,DISP=OLD //SYSOUT DD SYSOUT=* //SYSIN DD * JOINKEYS F1=MAIN,FIELDS=(1,4,A) JOINKEYS F2=LOOKUP,FIELDS=(1,4,A) JOIN UNPAIRED,F1,F2 REFORMAT FIELDS=(?,F1:1,4,F2:1,4) OPTION COPY OUTFIL FNAMES=MATCH,INCLUDE=(1,1,CH,EQ,C'B'),BUILD=(1:2,4) OUTFIL FNAMES=NOMATCH1,INCLUDE=(1,1,CH,EQ,C'1'),BUILD=(1:2,4) OUTFIL FNAMES=NOMATCH2,INCLUDE=(1,1,CH,EQ,C'2'),BUILD=(1:2,4) /* |
JOINKEYS specifies the field on which the two files are compared.
REFORMAT FIELDS=? places 'B' (matched records), '1' (present in file1, but not in file2), or '2' (present in file2 but not in file1) in the 1st position of the output BUILD.
JOIN UNPAIRED does a full outer join on the two files.
The output will be:
MATCH File 1000 1003 NOMATCH1 File 1001 1005 NOMATCH2 File 1002 |
The same functionality can be achieved using ICETOOL also.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!