August 2004 Technical Tip Recoding records with SyncSort

The CHANGE operand of the OUTREC statement is a feature of SyncSort which allows the programmer to recode records. Consider the following dataset containing pet information with the pet name in positions 1-8, the gender (M or F) in position 9, and the species (D = dog, C = cat, R = rabbit) in position 10:

BUFFY   FD
WAFFLES MC
OREO    MR
HERSHEYSFC

Let's assume I desire the following output with the name remaining in positions 1-8, a blank in position 9, the gender (recoded as 1 = male, 2 = female) in position 10, a blank in position 11, and the species (spelled out as DOG, CAT, or OTHER) in positions 12-16:

BUFFY    2 DOG
WAFFLES  1 CAT
OREO     1 OTHER
HERSHEYS 2 CAT

My SyncSort control cards would appear as follows:

//SYSIN   DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(1:1,8,                NAME
     9:1X,                             BLANK
    10:9,1,CHANGE=(1,C'M',C'1',        RECODE GENDER
                     C'F',C'2'),
    11:1X,                             BLANK
    12:10,1,CHANGE=(5,C'D',C'DOG  ',   RECODE SPECIES
                      C'C',C'CAT  '),
            NOMATCH=(C'OTHER'))

Let's quickly explain the last field: 12 is the position in the output record, 10 is the position in the input record, 1 is the length in the input record, 5 is the length in the output record, C'D' and C'C' are the change-from values, and C'DOG ' and C'CAT ' are the change-to values. Note the NOMATCH operand is optional (it wasn't used with gender), but if it is omitted and an unmatched condition is encountered, SyncSort will abend with U0016 return code. As always, be careful of misplaced blanks, commas and parentheses. Proper alignment is not required by SyncSort, but may be required by your peers!

Want to know more about SyncSort? Give us a call! You can count on Caliber Data Training for top quality mainframe and/or internet programming education.


Go to the articles index. Written by Bill Qualls. Copyright 2004 by Caliber Data Training 800.938.1222