MainframeMaster

OPTION Statement

The OPTION control statement sets various options that control how DFSORT runs: whether to sort at all (COPY), how to treat equal keys (EQUALS vs NOEQUALS), how many records to skip or stop after (SKIPREC, STOPAFT), variable-length handling (VLSHRT), memory and work allocation (SIZE, DYNALLOC), and others. This page explains the most common options, what each one does, and how they affect behavior and performance.

Control Statements
Progress0 of 0 lessons

What the OPTION Statement Does

The OPTION statement is optional. When you omit it, DFSORT uses default behavior for each option. When you code it, you list one or more option keywords (and sometimes values). Each keyword turns on or changes a specific behavior. You can combine several options in a single statement, separated by commas. The order of options in the statement usually does not matter. Example:

text
1
OPTION COPY,EQUALS,SKIPREC=1

This says: do not sort (COPY), preserve order of equal keys (EQUALS), and skip the first record of input (SKIPREC=1).

OPTION COPY — No Sort, Copy Only

OPTION COPY tells DFSORT to skip the sort (or merge) phase. Records are read from SORTIN, optionally filtered by INCLUDE/OMIT and reformatted by INREC, then written to SORTOUT (and OUTFIL) in the same order they were read. No SORT FIELDS= or MERGE FIELDS= is used. So the output order is the input order (after filtering). Use COPY when you only need to filter records, reformat them, or copy from one dataset to another without changing order. It is faster than a full sort because no comparison or reordering is done. If you code both OPTION COPY and SORT FIELDS=, the behavior is product-dependent; typically COPY takes precedence and the sort is skipped, or one may be ignored. To be clear, use either COPY (no sort) or SORT FIELDS= (sort), not both.

EQUALS and NOEQUALS — Stable vs Unstable Sort

When two or more records have the same sort key, the question is: in what order do they appear in the output? EQUALS means DFSORT preserves the relative order of such records—the order they had in the input (or after the merge). So if record A and record B have the same key and A was read before B, then A will appear before B in the output. This is called a stable sort. NOEQUALS means DFSORT does not guarantee that order; it may output B before A. NOEQUALS can allow DFSORT to use a faster or more memory-efficient algorithm, so it may improve performance when you have many equal keys and you do not care about their relative order. Use EQUALS when the order of equal-key records matters (e.g. you sorted by region and want to preserve a secondary order that was in the input). Use NOEQUALS when you only care that records are grouped by key and the order within the group does not matter.

SKIPREC — Skip First n Input Records

OPTION SKIPREC=n tells DFSORT to skip the first n records of the input. Those records are not read into the sort/merge logic and are not written to the output. So if you have a file with a one-line header and you code SKIPREC=1, the first record (the header) is skipped and only the rest are processed. If you have 100 records and SKIPREC=5, the first 5 are skipped and the next 95 are processed. SKIPREC applies to the input stream(s)—for SORT, that is SORTIN; for MERGE, it typically applies to each input (check product documentation for MERGE). Useful for skipping headers, trailers you do not want in the middle of the file, or bad leading records.

STOPAFT — Stop After n Output Records

OPTION STOPAFT=n tells DFSORT to stop after writing n records to the output. Once the nth record has been written to SORTOUT (and any OUTFIL), DFSORT stops reading and processing. Remaining input is not processed. So you get exactly n output records (or fewer if the input had fewer than n records after filtering). Useful for creating a sample of the sorted data, limiting output size for testing, or capping the number of records when you only need the first n. Note: STOPAFT counts output records, not input records. If you use INCLUDE and only half the records pass, STOPAFT=100 means 100 records written, which might require reading more than 200 input records.

VLSHRT and Variable-Length Records

VLSHRT (and the alternative NOVLSHRT) affect how DFSORT handles variable-length (VB) records, especially when record length is shorter than the maximum (LRECL). VLSHRT can improve performance or correctness when you have variable-length records of different sizes. NOVLSHRT uses a different handling that may be required for compatibility or when using SUM with variable-length records. The exact effect is product- and version-dependent; see the SUM and variable-length tutorials and product documentation. In general: if you use VB input and have issues with SUM or record length, try NOVLSHRT; otherwise the default (or VLSHRT) is often used.

SIZE — Memory and Sort Work

OPTION SIZE=n (or SIZE=MAX, etc.) influences how much memory DFSORT uses for the sort and how much data it tries to hold in memory before using work datasets. A larger size can reduce the number of passes over the data and improve performance for large sorts, but it consumes more region memory. The exact meaning of n (e.g. bytes, kilobytes, or a scale factor) and the allowed values depend on the product and installation. SIZE=MAX often means "use the maximum allowed by the region." Tuning SIZE is an advanced topic; for beginners, omitting it (using the default) is usually fine unless your site gives you a value to use.

DYNALLOC — Dynamic Allocation of Work Datasets

OPTION DYNALLOC (or the absence of it) controls whether DFSORT is allowed to dynamically allocate work datasets (SORTWKnn) when they are not provided in the JCL. When dynamic allocation is allowed and you do not allocate SORTWK01, SORTWK02, etc., DFSORT can request the system to create work datasets for it. When it is not allowed (or disabled), you must provide explicit SORTWKnn DDs or the step may fail. Your installation may set a default. Use explicit SORTWKnn when you need to control volume or space; omit them and rely on DYNALLOC when your site permits it.

Other Options (Brief)

MSGPRT — Controls how much or what kind of messages DFSORT writes to SYSOUT (e.g. MSGPRT=NONE to suppress some messages). FILSZ — Used to estimate input size for allocation or tuning. RESALL — Affects resource allocation. THREADS — Relates to parallel processing when supported. Details for these are in the OPTION deep-dive and performance sections of the documentation. If you need a specific option not covered here, check the IBM DFSORT/Beyond Sort documentation or your site's standards.

Example: Copy with Header Skip and Limit

text
1
2
3
OPTION COPY,SKIPREC=1,STOPAFT=1000 INCLUDE COND=(1,1,CH,EQ,C'A') OUTREC FIELDS=(1,80)

COPY: no sort. SKIPREC=1: skip the first input record (e.g. header). STOPAFT=1000: write at most 1000 output records. INCLUDE: keep only records where byte 1 is 'A'. OUTREC: write the full 80-byte record. So you get up to 1000 records that have 'A' in position 1, in input order, without the first record.

Explain It Like I'm Five

OPTION is like a control panel with switches. COPY is the switch that says "don't sort—just pass the cards through in the same order." EQUALS says "when two cards have the same first word, keep them in the order they were in the pile." SKIPREC says "ignore the first few cards (like a title card)." STOPAFT says "only put this many cards in the output pile, then stop." So the OPTION statement is where you set these switches before the machine runs.

Exercises

  1. You want to copy an 80-byte file to a new dataset but skip the first record (header) and only output the first 500 data records. Write the OPTION and any other needed control statements.
  2. What is the difference between EQUALS and NOEQUALS? When would you choose each?
  3. Does OPTION COPY affect INCLUDE and OUTREC? Why or why not?
  4. What does SKIPREC=10 do to the input? What does STOPAFT=10 do to the output?

Quiz

Test Your Knowledge

1. What does OPTION COPY do?

  • Copies the first record only
  • Skips the sort phase; records pass through in input order (after INCLUDE/OMIT)
  • Copies SYSIN to SYSOUT
  • Copies SORTOUT to SORTIN

2. What is the difference between EQUALS and NOEQUALS?

  • EQUALS sorts faster
  • EQUALS preserves the order of records with equal keys; NOEQUALS does not guarantee it
  • NOEQUALS is for MERGE only
  • They are the same

3. What does SKIPREC=n do?

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

4. What does STOPAFT=n do?

  • Stops after n output records
  • Stops after n seconds
  • Stops after n control statements
  • Stops after n input streams

5. When might you use OPTION COPY?

  • When you need to sort by a key
  • When you only need to filter (INCLUDE/OMIT) or reformat (INREC/OUTREC) without reordering
  • When you have two inputs
  • When SORTOUT is full