MainframeSupports
tip week 49/2012:

Did you know that SORT is able to convert binary and packed fields into readable numbers? I did not. However it is quite easy to make SORT do such conversions. This makes it much easier to read a file filled with a lot of binary and packed fields. Just send it through SORT.

Now imagine a dataset containing a ten digit customer number stored as a packed field equal to a FIXED DECIMAL(10) in PL/I, DECIMAL(10) in DB2 or PIC 9(10) COMP-3/DECIMAL in COBOL followed by a count of transactions stored as a binary field equal to a FIXED BINARY(31) in PL/I, INTEGER in DB2 or PIC S9(9) COMP/BINARY in COBOL. This is complete nonsense to read and hard to search in using FIND in ISPF EDIT, unless you are fond of hexadecimal conversions and is an expert in the internal representation of packed fields. Instead you can choose to send the file through the following SORT step:

//NUM2READ EXEC PGM=SORT
//SORTIN   DD DISP=SHR,DSN=MY.CUSTOMER.FILE
//SORTOUT  DD DISP=(NEW,CATLG),SPACE=(TRK,(99,99),RLSE),
//         DSN=MY.READABLE.FILE
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(C'CUST.NO=',
                 1,6,PD,TO=ZD,LENGTH=10,
                 C' TRANS.COUNT=',
                 7,4,BI,TO=ZD,LENGTH=10)
/*

Each record in MY.READABLE.FILE will look like this:

CUST.NO=9999999999 TRANS.COUNT=9999999999

I hope you understand the basics of how OUTREC operates otherwise click on help for OUTREC. Please note that OUTREC includes a function called EDIT which can be used to make even more sophisticated formatting than demonstrated above. For instance my formatting will not display a nice dash in front of a negative numbers, but instead display the last digit as a letter or special character. And you cannot display a decimal comma unless you use EDIT.

Previous tip in english        Forrige danske tip        Tip list