OUTREC Justifying Data
The OUTREC statement with allows us to justify data fields within records using JFY (Justify) keywords. We can justify the data to the left, right, or center within a specified field length. This is useful for aligning text or numbers in a specific way for reports or other output requirements.
Syntax1 - Justify with LEAD and TRAIL.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(...,
starting_pos_of_field1,
length_of_field1,
JFY=(SHIFT=LEFT|RIGHT,
LEAD=charset,
TRAIL=charset),...)
/*
Syntax2 - Justify with PREBLANK.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(...,
starting_pos_of_field1,
length_of_field1,
JFY=(SHIFT=LEFT|RIGHT,
PREBLANK=charset),...)
/*
Syntax3 - Justify with LEAD, TRAIL, PREBLANK.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(...,
starting_pos_of_field1,
length_of_field1,
JFY=(SHIFT=LEFT|RIGHT,
PREBLANK=charset,
LEAD=charset,
TRAIL=charset),...)
/*
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 |
Examples -
Scenario1 - Left-Justifying Data (Default Behavior).
//SYSIN DD *
OPTION COPY
OUTREC FIELDS=(1,29,JFY=(SHIFT=LEFT,PREBLANK=C'()',
LEAD=C'<',TRAIL=C'>'),30,30)
/*
Left-justifies a 30-byte character field starting from position 1 in the input, and places the result in the output. This aligns the data to the left within the specified field length.
Scenario2 - Right-Justifying Data.
//SYSIN DD *
OPTION COPY
OUTREC FIELDS=(1,29,JFY=(SHIFT=RIGHT,PREBLANK=C'()',
LEAD=C'<',TRAIL=C'>'),30,30)
/*
Right-justifies a 30-byte character field starting from position 1 in the input, and places the result in the output. This aligns the data to the right within the specified field length.