Friday, February 28, 2014

Editing Numeric Fields in DFSORT/SYNCSORT

EDIT Feature of OUTREC in DFSORT/SYNCSORT gives us great flexibility to mask and represent the data in our very own format.We can play around with PD or ZD data format.We can insert commas,hyphens,slashes,signs with this edit feature. I have tried out some functions randomly.

Suppose this is how the input looks like with the file structure like NAME(14 bytes) ,SALARY(6 bytes),COUNTRY(8bytes)

1. Lets put in some commas(,) in the salary part after first 4 digits.

//STEP02   EXEC PGM=SORT
//SORTIN   DD DSN=R0XXC.TEST.SORTIN,DISP=SHR 
//SORTOUT  DD DSN=R0XXC.TEST.SORT.OUT1,
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
//            DCB=*.SORTIN,
//            SPACE=(TRK,(100,200),RLSE)
//SYSOUT   DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
      SORT FIELDS=COPY
      OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,EDIT=(IIII,II))
/*
Output:







Similarly the Below SYSIN Card will put the comma after first 2 bytes.
OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,EDIT=(II,IIII))








2 .Now , lets put a dollar sign '$' using EDIT in Outrec
we need to use the below statements.

//SYSIN    DD *
 SORT FIELDS=COPY
OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,EDIT=($II,IIII))
/*
Output:








3. Include the Decimal point using EDIT.
We need to use the below SYSIN card to place a decimal point using EDIT.
OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,EDIT=(IIII.II)) 
Output:
HARLEY    1234.56
DAVID       6589.99

4. Include a positive sign ('+') before the digits using EDIT.
OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,EDIT=(SIIII.II),SIGNS=(+))
Output:
HARLEY   +1234.56
DAVID      +6589.99

Note: There are  for 27 predefined Edit masks available;  M0 -M26. They can be straight way used in our code instead of coding 'EDIT= ' parameter. Like we can write the control card like:

OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,M6)   instead of writing
OUTFIL  OUTREC=(1:1,6,11:10,6,ZD,EDIT=(III-TTT-TTTT))
Both giving the same output result:
HARLEY        012-3456
DAVID           065-8999

Explanation: 
'I' is used to display digits (1-9) and blanks for leading zeros.
'T' is used to display digits (0-9)
'S' indicates Sign which can be leading or Trailing.

No comments:

Post a Comment