MainframeMaster

REFORMAT Statement

The REFORMAT control statement is used only with JOINKEYS. It defines how the joined output record is built from the two input files. You code REFORMAT FIELDS= with items like F1:position,length (bytes from the first file) and F2:position,length (bytes from the second file). The items are concatenated in the order you list them to form the output record. So REFORMAT answers: "Which parts of file 1 and file 2 go into the joined record, and in what order?" Without REFORMAT, DFSORT does not know the joined record layout. This page covers REFORMAT FIELDS= syntax, F1: and F2: references, and how REFORMAT fits with JOINKEYS.

Control Statements
Progress0 of 0 lessons

What REFORMAT Does

When you join two files with JOINKEYS, each matched pair (or unpaired record in an outer join) becomes one output record. REFORMAT defines the layout of that output record: which fields from the first file (F1) and which from the second file (F2) are placed in the output, and in what order. So REFORMAT does not filter or sort—it only specifies how to build the joined record from the two sides.

REFORMAT FIELDS= Syntax

REFORMAT FIELDS=(item1,item2,...). Each item is either:

  • F1:position,length — Copy length bytes from the first join file starting at position. The first file is the one in the first JOINKEYS statement (e.g. F1=JOIN1).
  • F2:position,length — Copy length bytes from the second join file starting at position. The second file is the one in the second JOINKEYS statement.

Positions are 1-based. The output record length is the sum of all the lengths. Example: FIELDS=(F1:1,80,F2:11,70) → 80 + 70 = 150 bytes: full 80-byte record from F1, then bytes 11–80 from F2 (70 bytes).

Example with JOINKEYS

text
1
2
3
4
JOINKEYS F1=MASTER,FIELDS=(1,10,CH,A) JOINKEYS F2=TRANS,FIELDS=(1,10,CH,A) REFORMAT FIELDS=(F1:1,80,F2:11,50) SORT FIELDS=COPY

Joined output: 80 bytes from MASTER (positions 1–80), then 50 bytes from TRANS (positions 11–60). Total 130 bytes per joined record. The join key (bytes 1–10) is in both files; REFORMAT includes the full master record and part of the transaction record.

REFORMAT vs INREC/OUTREC

INREC and OUTREC reformat a single record stream (one input file). REFORMAT builds a record from two files that have been paired by JOINKEYS. So you use REFORMAT only in join applications; for non-join steps you use INREC (before sort) or OUTREC (after sort).

Explain It Like I'm Five

When you join two stacks of cards, you get one new card per match. REFORMAT is the rule for what to write on that new card: "Take this part from the first card and that part from the second card, and put them in this order." So REFORMAT doesn't decide who matches—JOINKEYS does—it only decides how the combined card looks.

Exercises

  1. Write REFORMAT FIELDS= to output: first 30 bytes of F1, then bytes 5–20 of F2. What is the output length?
  2. Why is REFORMAT required when using JOINKEYS?

Quiz

Test Your Knowledge

1. When do you use the REFORMAT statement?

  • With every SORT
  • With JOINKEYS to define the layout of the joined output record
  • Instead of OUTREC
  • With INCLUDE only

2. REFORMAT FIELDS=(F1:1,50,F2:11,40) produces an output record of what length?

  • 50 bytes
  • 40 bytes
  • 90 bytes
  • 51 bytes

3. What do F1: and F2: mean in REFORMAT FIELDS=?

  • Sort keys
  • F1: = bytes from the first join file, F2: = bytes from the second join file
  • File names
  • Format types

4. Can you use REFORMAT without JOINKEYS?

  • Yes, for normal SORT
  • No—REFORMAT is only used with JOINKEYS to build the joined record
  • Only with MERGE
  • Only with OPTION COPY

5. In REFORMAT FIELDS=(F1:1,20,F2:5,15), where do bytes 5–19 of the second file go?

  • Nowhere
  • Into the output, as the second segment (15 bytes) after the first 20 bytes from F1
  • Into SORTOUT only
  • Into F1