SORT with INCLUDE/OMIT
Problem Description
Sort employee file, include only active employees (status=A in pos 50), sort by department and name.
Expected Output
Filtered and sorted output
Hints
Use INCLUDE/OMIT COND with SORT FIELDS.
Solution
//SORTJOB JOB (ACCT),CLASS=A
//*
//STEP1 EXEC PGM=SORT
//SORTIN DD DSN=MY.EMPLOYEE.FILE,DISP=SHR
//SORTOUT DD DSN=MY.ACTIVE.SORTED,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(10,5)),
// DCB=(RECFM=FB,LRECL=80)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
INCLUDE COND=(50,1,CH,EQ,C'A')
SORT FIELDS=(20,10,CH,A,1,20,CH,A)
OUTREC FIELDS=(1,80)
/*
//
Explanation:
INCLUDE filters records. SORT by dept (pos 20-29) then name (pos 1-20).