z/OS DFSORT: Getting Started
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Left-squeezing and right-squeezing data

z/OS DFSORT: Getting Started
SC23-6880-00

Suppose you had input records that looked like this
<tag>   History  </tag>
   <tag> Psychology      </tag>
 <tag>      Business </tag>
<tag>Biology</tag>
  <tag>   Science  </tag>
If you want to remove the white space (blanks), you can use the following statements to left-squeeze the data:
  OPTION COPY
  OUTREC FIELDS=(1,40,SQZ=(SHIFT=LEFT))
SHIFT=LEFT indicates that you want to left-squeeze by removing all of the blanks, shifting the remaining characters to the left and padding on the right with blanks if needed. The results produced for this OUTREC statement are:
<tag>History</tag>
<tag>Psychology</tag>
<tag>Business</tag>
<tag>Biology</tag>
<tag>Science</tag>
Alternatively, you can use the following statements to right-squeeze the data:
  OPTION COPY
  OUTREC FIELDS=(1,40,SQZ=(SHIFT=RIGHT))
SHIFT=RIGHT indicates that you want to right-squeeze by removing all of the blanks, shifting the remaining characters to the right and padding on the left with blanks if needed. The results produced for this OUTREC statement are:
                      <tag>History</tag>
                   <tag>Psychology</tag>
                     <tag>Business</tag>
                      <tag>Biology</tag>
                      <tag>Science</tag>
DFSORT's squeeze 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-squeezed data with '<tag1>' and '</tag1>':
  OPTION COPY
  OUTREC FIELDS=(1,40,SQZ=(SHIFT=LEFT,LEAD=C'<tag1>',
     TRAIL=C'</tag1>'))
The results produced for this OUTREC statement are:
<tag1><tag>History</tag></tag1>
<tag1><tag>Psychology</tag></tag1>
<tag1><tag>Business</tag></tag1>
<tag1><tag>Biology</tag></tag1>
<tag1><tag>Science</tag></tag1>
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-squeeze, the trailing string is placed directly to the right of the last non-blank character in your data.

If you want to right-squeeze instead of left-squeeze, you can use the following statements:
  OPTION COPY
  OUTREC FIELDS=(1,40,SQZ=(SHIFT=RIGHT,LEAD=C'<tag1>',
     TRAIL=C'</tag1>'))
The results produced for this OUTREC statement are:
         <tag1><tag>History</tag></tag1>
      <tag1><tag>Psychology</tag></tag1>
        <tag1><tag>Business</tag></tag1>
         <tag1><tag>Biology</tag></tag1>
         <tag1><tag>Science</tag></tag1>

Notice that when you right-squeeze, 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 as discussed previously under Left-justifying and right-justifying data.

The squeeze feature can also be used to remove characters other than blanks from your data. Suppose you had input records that looked like this:
<tag>   (History) </tag>
   <tag> (Psychology)    </tag>
 <tag>      (Business) </tag>
<tag>(Biology)</tag>
  <tag>   (Science)  </tag>
You can use the following statements to remove the '(' and ')' characters before you left-squeeze the data:
  OPTION COPY
  OUTREC FIELDS=(1,40,SQZ=(SHIFT=LEFT,PREBLANK=C'()'))

PREBLANK=list specifies a list of characters you want to replace with blanks before DFSORT starts to squeeze 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 '*' character and '/' character with a blank before squeeze procssing begins (for example, character sequences of /*, //*, */, // and * are all replaced with blanks).

The results produced for this OUTREC statement are:
<tag>History</tag>
<tag>Psychology</tag>
<tag>Business</tag>
<tag>Biology</tag>
<tag>Science</tag>
You could use the following statements to right-squeeze the data and remove the '(' character and ')' character:
  OPTION COPY
  OUTREC FIELDS=(1,40,SQZ=(SHIFT=RIGHT,PREBLANK=C'()'))
The results produced for this OUTREC statement are:
                      <tag>History</tag>
                   <tag>Psychology</tag>
                     <tag>Business</tag>
                      <tag>Biology</tag>
                      <tag>Science</tag>
The squeeze feature can be used to replace groups of blanks between the first nonblank and last nonblank with other characters. Suppose you had input records that looked like this:
   Manufacturing    California    +100000
   Research         Arizona        +50000
   Marketing        Texas          +75000
You could use the following statements to create comma separated variable records:
  OPTION COPY
  OUTREC FIELDS=(1,80,SQZ=(SHIFT=LEFT,MID=C','))
The results produced for this OUTREC statement are:
Manufacturing,California,+100000
Research,Arizona,+50000
Marketing,Texas,+75000

MID=string specifies the string to replace removed blanks or PREBLANK characters as a character or hexadecimal constant (1 to 10 bytes).

If you want DFSORT to "ignore" blanks and PREBLANK characters between pairs of quotes, you can use PAIR=QUOTE with SQZ.

Suppose you had input records that looked like this:
   "Computer Science A+"       +123
   "Ancient Civilization B-"   +521
   "Sanskrit A-"               -263
You could use the following statements to "protect" the blanks, + and - signs inside the paired quotes while removing them outside the paired quotes, and leave only one blank between the two squeezed fields:
  OPTION COPY
  OUTREC FIELDS=(1,80,SQZ=(SHIFT=LEFT,PAIR=QUOTE,
    PREBLANK=C'+-',MID=C' '))
The results produced for this OUTREC statement are:
"Computer Science A+" 123
"Ancient Civilization B-" 521
"Sanskrit A-" 263

If you want DFSORT to "ignore" blanks and PREBLANK characters between pairs of apostrophes, you can use PAIR=APOST with SQZ.

Suppose you had input records that looked like this:
   'Computer Science A+'       +123
   'Ancient Civilization B-'   +521
   'Sanskrit A-'               -263
You could use the following statements to "protect" the blanks, + and - signs inside the paired apostrophes while removing them outside the paired apostrophes, and leave only one blank between the two squeezed fields:
  OPTION COPY
  OUTREC FIELDS=(1,80,SQZ=(SHIFT=LEFT,PAIR=APOST,
    PREBLANK=C'+-',MID=C' '))
The results produced for this OUTREC statement are:
'Computer Science A+' 123
'Ancient Civilization B-' 521
'Sanskrit A-' 263

For complete details on squeeze, see z/OS DFSORT Application Programming Guide.

So far
Now you know how to use the many features available with the BUILD or FIELDS parameter of the OUTREC statement to reformat your input records in many ways for output. Keep in mind that you can use all of these reformatting features with the BUILD or FIELDS parameter of the INREC statement and with the BUILD or OUTREC parameter of the OUTFIL statement, as well as with the OUTREC statement. In fact, you can use all of these statements together, when appropriate. Next, you will learn how to use the OVERLAY parameter of the OUTREC statement to change one or more fields without affecting the rest of your record.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014