OUTREC Squeezing Data
The OUTREC statement with the SQZ (squeeze) function is used to remove leading, trailing, or embedded blanks (spaces) from data fields, or to replace multiple consecutive blanks with a single blank. This is useful when we want to squeeze data by eliminating unnecessary spaces.
Syntax1 - Justify with LEAD and TRAIL.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(...,
starting_pos_of_field1,
length_of_field1,
SQZ=(SHIFT=LEFT|RIGHT,
LEAD=charset,
TRAIL=charset),...)
/*
Syntax2 - Justify with PREBLANK, PAIR and MID.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(...,
starting_pos_of_field1,
length_of_field1,
SQZ=(SHIFT=LEFT|RIGHT,
PAIR=QUOTE,
PREBLANK=charset,
MID=String),...)
/*
starting_pos_of_field1 | Specifies field1 starting position in the input file. |
length_of_field1 | Specifies field1 length in input file. |
SHIFT | Specifies the justification SHIFT=LEFT specifies the data should be left justified SHIFT=RIGHT specifies the data should be right justified |
LEAD=charset | Specifies the leading characters added to data |
TRAIL=Charset | Specifies the trailing characters added to data |
PREBLANK=charset | Specifies the characters that replaced or blank out as leading and trailing to data |
MID=String | specifies the string to replace removed blanks or PREBLANK characters as a character. |
PAIR=QUOTE | used to "ignore" blanks and PREBLANK characters between pairs of quotes |
Examples -
Scenario1 - Removing leading blanks and shifting left.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,10,11:11,20,SQZ=(SHIFT=LEFT))
/*
Removes leading blanks from the 20-byte field starting at position 11 and shifts the data to the left.
Scenario2 - Removing trailing blanks and shifting right.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,10,11:11,20,SQZ=(SHIFT=RIGHT))
/*
Removes trailing blanks from the 20-byte field starting at position 11 and shifts the data to the right.
Scenario3 - Squeezing multiple spaces in the middle.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,10,11:11,20,SQZ=(SHIFT=LEFT,MIDDLE=(X'40')))
/*
Removes leading blanks from the 20-byte field starting at position 11, shifts the data to the left, and replaces multiple consecutive blanks between words with a single blank (hexadecimal X'40').