Module 8: JCL Sort & Merge
It is used to reformat each record by specifying just the items that overlay specific columns.
Overlay lets you change specific existing columns without affecting the entire record.
As compared to FIELD or BUILD statement, in OVERLAY we don’t have to specify information regarding the fields which has to be copied as it is, in OVERLAY, we just have to specify information and specification for those field which need to be changed or to be overwritten.
Requirement: Need to copy all records from input file to output file, however while writing output records, field at position 11 to 20 needs to be converted to lower case letters
JCL Code - Solution:-
- Statement ‘SORT FIELDS=COPY’ is used here to indicate that all records will be copied from input file to output file.
- Statement ‘OUTREC OVERLAY=(11:11,10,TRAN=UTOL), is used here to specify that the field at position (11-20 i.e. length=10) of input file should be converted to lowercase and then it should be written to 11th position of output file.
IMP Note: In above example, while coding OUTREC OVERLAY statement, we do not have to worry about field at positions (1-10 and 21-30) as they will be copied and written as it is. If we have used OUTREC FIELDS statement then it would have look like OUTREC FIELDS=( 1,10,11:11,10,TRAN=UTOL,21,10).
Requirement: Need to calculate yearly salary from field at position (26-30 i.e. length=5) of input file and should be written at 41th position of output file
JCL Code Soution:
- Statement 'SORT FIELDS=COPY' is used here to indicate that all records will be copied from input file to output file.
- Statement 'OUTREC FIELDS=(1,30,41:26,5,ZD,MUL,+12,TO=FS,LENGTH=10) ', is used here to specify that the field at position (1-30 i.e. length=30) of input file will be written as it is followed by the value at position (26-30 i.e. length=5 ) of input file will be multiplied by 12 and resultant value will be converted to FS value with length 10. The resultant value will be written to 41 position in output file