DFSort reformat dataset

We can use DFSort to reformat the input data and customize the output dataset fields.

  • By reformatting, the output dataset fields can be specified by selecting specific columns from input file and sort on those columns.
  • Since the start data-byte in the sort-key can be only within the first 4092 data bytes, to consider data beyond 4092 bytes as the start column, you can reformat using INREC FIELDS and OUTREC 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.

Reformat data BEFORE 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

  • EMPID starting at absolute byte 1, for 5 bytes long
  • EMPLOYEENAME at absolute byte 6, for 25 bytes long
  • PROJECT at absolute byte 31, for 15 bytes long
  • SALARY at byte 46, for 9 bytes long

input-dataset

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)
/*

dfsort-inrec-fields

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)
/*

Reformat data AFTER SORTING:

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

input-dataset

The following image shows the output file when both the SYSIN cards SORT and OUTREC FIELDS are executed. The output file is

dfsort-outrec-fields-no-space

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

DFSORT-outrec-fields

Add comment

Subscribe for more goodness!

Do you like what I'm writing? Sign up to receive new content straight into your mailbox!