MainframeMaster

SKIPREC

The DFSORT OPTION SKIPREC=n tells the sort step to skip the first n records of the input. Those records are never read into the sort or merge logic and never appear in the output. SKIPREC is useful when your input has a fixed number of leading records you do not want to process—for example a one-line header, multiple header lines, or a few bad or control records at the start of the file. This page explains how SKIPREC works, how it interacts with other control statements, and when to use it instead of INCLUDE or OMIT.

OPTION Statement
Progress0 of 0 lessons

What SKIPREC Does

When you specify OPTION SKIPREC=n, DFSORT behaves as if the first n records of the input do not exist. It does not read them into memory for sorting, merging, or reformatting; it does not pass them to INCLUDE or OMIT; and it does not write them to SORTOUT or any OUTFIL. So the effective input to your step is "everything after the first n records." The value n must be a non-negative integer. Common values are 1 (skip one header line) or a small number (e.g. 3 or 5) when you have multiple header or control lines at the top of the file.

Syntax and Placement

Code SKIPREC as part of the OPTION statement in SYSIN. You can combine it with other options, separated by commas. The OPTION statement usually appears before the SORT FIELDS= or MERGE FIELDS= statement (or before OPTION COPY if you are not sorting). Example:

text
1
2
OPTION SKIPREC=1 SORT FIELDS=(1,20,CH,A)

To skip the first five records and also use a stable sort:

text
1
2
OPTION EQUALS,SKIPREC=5 SORT FIELDS=(10,4,PD,D)

If you omit SKIPREC (or use SKIPREC=0 where that is allowed), no input records are skipped; processing starts from the first record.

When to Use SKIPREC

  • Single or multiple header lines. Many flat files have one or more header records (column titles, file identifiers, or control information). If those headers are always the first n records, SKIPREC=n is the simplest way to exclude them so they do not get sorted or written to output.
  • Bad or test data at the start. If the first few records of a file are known to be invalid or used for testing, SKIPREC lets you skip them without writing INCLUDE/OMIT conditions.
  • Fixed-format leading records. When the file layout has a fixed number of "preamble" records (e.g. one summary line followed by detail), SKIPREC=1 or more ensures only the detail records are processed.

SKIPREC vs INCLUDE/OMIT

SKIPREC is purely positional: it skips the first n records regardless of their content. INCLUDE and OMIT are conditional: they keep or drop records based on field values, ranges, or patterns. Use SKIPREC when the records you want to skip are always the first n. Use INCLUDE or OMIT when you identify records by content (e.g. "drop all records where byte 1 is 'H'" or "keep only records where the type field is 'D'"). If your "header" can appear in different positions or you have multiple types of records to exclude by value, INCLUDE/OMIT is the right tool. If you always have exactly one header line at the top, SKIPREC=1 is simpler and avoids building a condition.

SKIPREC at a glance
AspectBehavior
What is skippedFirst n records of input only
When appliedBefore any INCLUDE/OMIT, INREC, or sort
OutputSkipped records do not appear in SORTOUT or OUTFIL
Typical useHeaders, bad leading records, fixed-position trailers

Order of Operations

SKIPREC is applied at the very beginning of input processing. The sequence is: (1) read input; (2) skip the first n records (SKIPREC); (3) for the remaining records, apply INCLUDE/OMIT; (4) apply INREC if present; (5) sort or merge (or copy with OPTION COPY); (6) apply SUM if present; (7) apply OUTREC/OUTFIL. So skipped records never participate in filtering, reformatting, or sorting. They are simply not seen by the rest of the step.

Effect on Record Counts and Performance

Because skipped records are not read into the sort/merge logic, they are typically not counted in the "records in" total that DFSORT reports in its completion messages. The input dataset still contains those records on disk; DFSORT just advances past them. So your job output might show something like "100000 records in, 100000 records out" when the file actually has 100005 records—the 5 skipped are not in the count. From a performance perspective, skipping is cheap: DFSORT still reads the skipped records from the dataset (to move the read position forward) but does no further work on them. So SKIPREC does not reduce I/O for the skipped portion; it only reduces how many records are processed by the sort/merge and downstream logic.

Using SKIPREC with MERGE

With MERGE, you have multiple input streams. Whether SKIPREC applies to each stream, only the first stream, or in some other way depends on your DFSORT product and version. In some implementations, SKIPREC=n causes each merge input to skip its first n records. In others, it may apply only to the first DD or be documented differently. If you use MERGE and need to skip leading records, check your product documentation and, if necessary, test with a small file to confirm behavior. For a single-input SORT, SKIPREC always applies to SORTIN.

Examples

Skip one header and sort by position 1–10 character ascending:

text
1
2
OPTION SKIPREC=1 SORT FIELDS=(1,10,CH,A)

Skip three header lines and copy (no sort) with reformatting:

text
1
2
OPTION COPY,SKIPREC=3 OUTREC FIELDS=(1,80)

In the second example, no SORT FIELDS= is used, so OPTION COPY is in effect. The first three records are skipped; the rest are copied with OUTREC formatting.

Explain It Like I'm Five

Imagine a stack of cards where the first few cards are instructions (e.g. "This stack has 100 cards"). You want to sort only the real data cards. SKIPREC is like saying: "Ignore the first 3 cards and sort the rest." So you take the first 3 off and put them aside, then sort everything that is left. The first 3 never get sorted and never go into the result pile.

Exercises

  1. Your file has two header lines and 50,000 data records. Write the OPTION statement to skip the headers and sort by bytes 20–25 (assume CH,A).
  2. When would you use INCLUDE/OMIT instead of SKIPREC to exclude a "header" record?
  3. If you use SKIPREC=10 and STOPAFT=100, how many input records can DFSORT read at most? (Consider: SKIPREC skips 10; then STOPAFT limits output to 100.)
  4. Does SKIPREC change the content of the output file, or only which records are included?

Quiz

Test Your Knowledge

1. What does OPTION SKIPREC=n do?

  • Skips the first n records of output
  • Skips the first n records of input before processing
  • Skips n control statements in SYSIN
  • Skips n work datasets

2. You have a file with one header record and 10,000 data records. You want to sort the data only. What do you use?

  • INCLUDE to filter out the header
  • OPTION SKIPREC=1
  • OMIT with a condition for the header
  • OUTREC to drop the first record

3. Does SKIPREC affect the record count in DFSORT messages?

  • No; skipped records are still counted as input
  • Yes; skipped records are not read, so they are not counted in the input record total
  • SKIPREC only affects output count
  • It depends on OPTION MSGPRT

4. Can you use SKIPREC with MERGE?

  • No; SKIPREC is SORT only
  • Yes; behavior is product-dependent—often SKIPREC applies per input stream or to the first input only
  • Only with OPTION COPY
  • SKIPREC applies to SORTOUT

5. What happens if you specify SKIPREC=0?

  • No records are processed
  • Zero records are skipped; all input is processed (same as omitting SKIPREC)
  • It is invalid and causes an error
  • Only record 0 is skipped