OUTFIL Reformatting


The OUTFIL statement can be used to reformat records in the output dataset. Reformatting allows us to rearrange fields, select specific portions of records, insert constants, convert data formats, or manipulate the output layout. This is commonly done using in combination with the PARSE, BUILD, OUTREC, OVERLAY, FINDREP, or IFTHEN parameters.

Syntax -

//SYSIN DD *
  SORT FILEDS=...
  OUTFIL FNAMES=DDname-n, 
	INCLUDE/OMIT COND=(……),
	BUILD=(…………) or OUTREC=(…………)
/*
OUTRECSimilar to BUILD, used to reformat the output records by selecting and arranging specific fields.

DFSORT automatically sets the LRECL of each OUTFIL file to the reformatted output record length.

Examples -


Scenario1 - Simple Reformatting with BUILD

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTFIL FNAMES=SORTOUT,BUILD=(1,5,15,10)
/*

This reformatting copies the first 5 bytes from position 1 and the next 10 bytes starting from position 15 in the input records. The output record will only contain these fields.

Scenario2 - Reformatting and Inserting Constants.

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTFIL FNAMES=SORTOUT,BUILD=(1,10,20:C'HELLO',35,5)
/*

Copies the first 10 bytes from position 1, inserts the constant 'HELLO' starting at position 20 and copies 5 bytes starting at position 35.

Scenario3 - Reformatting and Converting Data Types.

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTFIL FNAMES=SORTOUT,BUILD=(1,10,20,4,ZD,M11,LENGTH=6)
/*

Copies the first 10 bytes from position 1 and converts the 4-byte zoned decimal field starting at position 20 to an M11 numeric format with a length of 6 bytes.