Converting Numeric fields to Different formats Using SORT

 

There are might be instances when you need to convert the internal storage of a numeric filed , DFSORT allows you to accomplish this outside your program , lets look at the various options available.

 

Converting Binary to Displayable Zoned Decimal

If you want a binary value to made readable , you can do so by converting it to an equivalent Zoned Decimal.

 OPTION COPY
 OUTREC FIELDS=(1,4,BI,TO=ZD)

The TO=ZD parameter converts the 4 byte binary fields to its equivalent zoned decimal value in the output file.

By default, a 4-byte BI value produces a 10-byte ZD value,if you wish to modify this and give a custom value , we can use the LENGTH option along with TO

OUTREC FIELDS=5,4,BI,TO=ZD,LENGTH=6

BI values can also be converted to readable FS or floating sign values using TO=FS

 

Converting Packed Decimal to Displayable Format

PD values are stored as integers in a compressed internal format but if you know what kind of value is stored in the filed you can use the EDIT feature of DFSORT to make these readable, the EDIT feature also allows you to insert comas , hyphens to make the fields more interpretable as well.

A 7 byte PD field which holds the value “+3721500532006″ can be made readable using the below sort card.

 OPTION COPY
 OUTREC FIELDS=(1,7,PD,EDIT=(SI,III,III,IIT.TTT)

Output :  3,721,500,532.006

Lets look at the EDIT mask closely

  • I  Indicates a leading digit to be displayed as 1-9, or as blank for a leading 0.
  • T  Indicates a significant digit to be displayed as 0-9.
  • S before the digits indicates a leading sign. S after the digits indicates a  trailing sign

DFSORT provides a set of 27 predefined mask to be used directly for formatting, these masks can be directly mentioned in the sort card like shown below

OPTION COPY
 OUTREC FIELDS=(1,7,PD,M4)

 

Screen Shot 2015-05-16 at 10.25.43 PM

Screen Shot 2015-05-16 at 10.50.57 PMScreen Shot 2015-05-16 at 10.51.18 PM 

Converting Data to Hexadecimal and Binary

You can convert data to its  HEX or BI equivalent using the TRAN function in your sort card . An input file with the 5 records can be converted to HEX and BI values as shown below.

Input File 

A
Z
0
9
$

Sort Card to converting to HEX 

 OPTION COPY
 OUTREC FIELDS=(1,1,TRAN=HEX)
C1
E9
F0
F9
5B

Sort Card to converting to Binary 

OPTION COPY
 OUTREC FIELDS=(1,1,TRAN=BIT)
11000001
11101001
11110000
11111001
01011011
Mainframe Wiki © 2015 Frontier Theme