DFSORT – Skip and read selective records – SKIPREC and STOPAFT
This tutorial will teach you how to read selective lines from the beginning of a Physical Sequential (PS File) file using SORT. Like many features, SORT provides two control keyword – SKIPREC and STOPAFT which can be used to skip records and read selective no of lines.
SKIPREC=n : How many “n” lines to be skipped from the first line.
STOPAFT=n : Once “n” lines are read, stop reading.
We will use a simple example to demonstrate this. Say you have a input file of employee records including various descriptions.
//SORTIN DD * FIRST NAME: JOHN LAST NAME: DOE DEPT: HR SALARY: 10000 JOIN DATE: 4/5/2012 /*
We want to read the DEPT and SALARY using sort and put it in output file. DEPT is in 3rd line and we will read only 2 lines from there. Thus SORT control card would look like:
//SYSIN DD * SORT FIELDS=COPY, SKIPREC=2, STOPAFT=2 /*
If you run the JOB, your output would be:
DEPT: HR SALARY: 10000
//YOUR.JOB.CARD.HERE //* //STEP1 EXEC PGM=SORT //** You can give your input PS file here instead of in stream data //SORTIN DD * FIRST NAME: JOHN LAST NAME: DOE DEPT: HR SALARY: 10000 JOIN DATE: 4/5/2012 /* //** You can give your Output PS file here instead of in stream data //SORTOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY, SKIPREC=2, STOPAFT=2 /*
Drop a comment below if you face any problem using the above example.