We use cookies to improve user experience. By continuing to browse our website or by clicking accept, you agree to our use of cookies.
Read more about how we use cookies and how you can refuse them.
We can use DFSort to reformat the input data and customize the output dataset fields.
INREC FIELDS:
INREC FIELDS are used to select the specified data from input file to reformat before sorting.
OUTREC FIELDS:
OUTREC FIELDS are used to select the specified data from input file to reformat after sorting.
Lets consider the following example with the file structure where we will reformat the data to include only employee number and salary field and to sort in descending order of salary field:
01 WS-DATE-RNAME.
05 EMPID PIC 9(05).
05 EMPLOYEENAME PIC A(25).
05 PROJECT PIC X(15).
05 SALARY PIC 9(09).
05 FILLER PIC x(26).
The example Input file is PS with fixed length
To sort in ascending order of EMPID, the JCL is:
//PROGPUBA JOB NOTIFY=PROGPUB
//STEP010 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=
//SORTOUT DD DSN=
//SYSIN DD *
INREC FIELDS=(1,5,46,5)
SORT FIELDS=(6,5,CH,D)
/*
Incase if the column which needs to be included in the output file is after than 4092 bytes then we have to use the INREC FIELDS like shown in the example
//PROGPUBA JOB NOTIFY=PROGPUB
//STEP010 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=
//SORTOUT DD DSN=
//SYSIN DD *
INREC FIELDS=(1,5,5000,3)
SORT FIELDS=(6,3,CH,A)
/*
Inorder to reformat data after sorting the input file, we need to use OUTREC FIELDS as a SYSIN card.
Lets consider the same example as above and we will obtain only the Empid and Salary fields in the output, but to sort on Empname field in ascending order:
//PROGPUBA JOB NOTIFY=PROGPUB
//STEP010 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=
//SORTOUT DD DSN=
//SYSIN DD *
SORT FIELDS=(6,25,CH,A)
OUTREC FIELDS=(1,5,46,5)
/*
In this step where the sort card is executed, the intermittent output file will look like the following
The following image shows the output file when both the SYSIN cards SORT and OUTREC FIELDS are executed. The output file is
In the above example, the output is not readable without the copybook layout and certainly its confusing where the fields start and end. Inorder to have a better readable output format, we can include character-literals, spaces between the fields in the output dataset.
Example JCL to include 2spaces between Empid and Salary fields in the output dataset from the example above.
//PROGPUBA JOB NOTIFY=PROGPUB
//STEP010 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=
//SORTOUT DD DSN=
//SYSIN DD *
SORT FIELDS=(6,25,CH,A)
OUTREC FIELDS=(1,5,2X,46,5)
/*
The output file will look like the following with 2x space between fields
Add comment