Left-justifying and right-justifying data
Suppose you had input records that looked like this:
History
Psychology
Business
Biology
Computer Science
Since this is rather messy looking, you can use the following statements
to left-justify the data to make it more presentable:
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=LEFT))
SHIFT=LEFT indicates that you want to left-justify. The results
produced for this OUTREC statement are:
History
Psychology
Business
Biology
Computer Science
Alternatively, you can use the following statements to right-justify
the data:
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=RIGHT))
SHIFT=RIGHT indicates that you want to right-justify. The results
produced for this OUTREC statement are:
History
Psychology
Business
Biology
Computer Science
DFSORT's justify feature also lets you add a leading string, a
trailing string, or both, to the data. For example, you can use the
following statements to surround the left-justified data with '<'
and '>':
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=LEFT,LEAD=C'<',TRAIL=C'>'))
The results produced for this OUTREC statement are:
<History>
<Psychology>
<Business>
<Biology>
<Computer Science>
LEAD=string specifies the leading string as a character or hexadecimal constant (1 to 50 bytes). TRAIL=string specifies the trailing string as a character or hexadecimal constant (1 to 50 bytes).
Notice that when you left-justify, the trailing string is placed directly to the right of the last non-blank character in your data.
If you want to right-justify instead of left-justify, you can use
the following statements:
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=RIGHT,LEAD=C'<',TRAIL=C'>'))
The results produced for this OUTREC statement are:
<History>
<Psychology>
<Business>
<Biology>
<Computer Science>
Notice that when you right-justify, the leading string is placed directly to the left of the first non-blank character in your data.
If your leading or trailing string causes the output field to be
longer than the input field, you will lose characters. In order to
avoid that, you can increase the length of the output field with the
LENGTH parameter. For example, suppose you had input records that
looked like this:
rats
bats
cats
and you added a leading string with these control statements: OPTION COPY
OUTREC FIELDS=(1,7,JFY=(SHIFT=LEFT,LEAD=C'*I love ',TRAIL=C'*'))
Since your input field is 7 bytes, your output field is also 7
bytes by default, so your output fields are truncated to:
*I love
*I love
*I love
To avoid truncation, you can use LENGTH=16 to increase the output
field length by the 9 characters you added for the leading and trailing
strings:
OPTION COPY
OUTREC FIELDS=(1,7,JFY=(SHIFT=LEFT,LEAD=C'*I love ',TRAIL=C'*',
LENGTH=16))
The larger output field can accommodate your leading and trailing
strings so you can show your appreciation for these wonderful creatures
with the following output:
*I love rats*
*I love bats*
*I love cats*
The justify feature can also be used to remove leading and trailing
characters other than blanks from your data. Suppose you had input
records that looked like this:
(History)
(Psychology)
(Business)
(Biology)
(Computer Science)
You can use the following statements to remove the leading '('
character and the trailing ')' character before you left-justify the
data:
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=LEFT,PREBLANK=C'()'))
PREBLANK=list
specifies a list of characters you want to replace with blanks before
DFSORT starts to justify the data. You can specify the list as a
character or hexadecimal constant (1 to 10 bytes). Remember that each
character in the list is independent of the other characters. For
example, PREBLANK=C'*/' replaces each leading or trailing '*' character
and '/' character with a blank before justify procssing begins (for
example, leading and trailing character sequences of /*, //*, */,
// and * are all replaced with blanks).The results produced for this OUTREC statement are:
History
Psychology
Business
Biology
Computer Science
You could use the following statements to right-justify the data
and replace the leading '(' character and trailing ')' character with
a leading '<' character and a trailing '>' character:
OPTION COPY
OUTREC FIELDS=(1,30,JFY=(SHIFT=RIGHT,PREBLANK=C'()',
LEAD=C'<',TRAIL=C'>'))
The results produced for this OUTREC statement are:
<History>
<Psychology>
<Business>
<Biology>
<Computer Science>
For complete details on justify, see z/OS DFSORT Application Programming Guide.