DFSORT – Skip and read selective records – SKIPREC and STOPAFT

1 min


A tutorial on skip and select records using DFSORT.

Skip and Select Records Using DFSORT

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 keywords – SKIPREC and STOPAFT which can be used to skip records and read selective no of lines.

SKIPREC=n : How many “n” lines are 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 an 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 them in the output file. DEPT is in 3rd line and we will read only 2 lines from there. Thus SORT control card would look like this:

//SYSIN DD *
SORT FIELDS=COPY,
SKIPREC=2,
STOPAFT=2
/*

If you run the JOB, your output would be:

DEPT: HR
SALARY: 10000

Complete JCL:

//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 problems using the above example.


Arindam

Creator of debugpoint.com. All time Linux user and open-source supporter. Connect with me via Telegram, Twitter, LinkedIn, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
1
0
Would love your thoughts, please comment.x
()
x