Reputation: 1
I have a input with comma delimited records Each field will be of different variables length Example 5467,2,567.82 243,10,856
Now I want output to be written as below first field length in the output should be 10 second field length should be 15 and third field length should be 15 with leading zeroes
Order 0000005467 count 000000000000002 amount 000000000567.82 Order 0000000243 count 000000000000010 amount 000000000000856
i have tried below jcl but the amount field is not populated to right justified its populating to left justified as 567820000000.00
//STEP1 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=input,DISP=SHR
//SORTOUT DD DSN=output1,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(5,5),RLSE)
//SYSIN DD *
OPTION COPY
INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=10),
%01=(ENDBEFR=C',',FIXLEN=15),
%02=(FIXLEN=15)),
BUILD=(%00,%01,%02)
OUTREC BUILD=(1,10,UFF,M11,LENGTH=10,
11,15,UFF,M11,LENGTH=15,
26,10,ZD,EDIT=(TTTTTTTT.TT))
/*
//STEP2 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=output1,DISP=SHR
//SORTOUT DD DSN=outputfinal,
// DISP=(NEW,CATLG,DELETE),
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=TSO.TESTFIS.CDS.CNTRL.RPTS.TT61824,DISP=SH
//SORTOUT DD DSN=TSO.TESTFIS.CDS.CNTRL.RPTS.TT61824.FINALB,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(5,5),RLSE)
//SYSIN DD *
OPTION COPY
INREC PARSE=(%00=(FIXLEN=10),
%01=(FIXLEN=15),
%02=(FIXLEN=15)),
BUILD=(C'ORDER # ',
%00,
C' COUNT = ',
%01,
C' AMOUNT = ',
%02)
/*
output should be Order 0000005467 count 000000000000002 amount 000000000567.82 Order 0000000243 count 000000000000010 amount 000000000000856
Upvotes: 0
Views: 138
Reputation: 556
Your input has both numeric digits with decimal dot as well as pure integers. so you need to handle them a bit differently
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
5467,2,567.82
243,10,856
1,2,59.8
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
ALTSEQ CODE=(40F0)
* parse the comma separated fields
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(ENDBEFR=C',',FIXLEN=10),
%02=(ENDBEFR=C',',FIXLEN=15),
%03=(ENDBEFR=C',',FIXLEN=15)),
BUILD=(%01,UFF,M11,LENGTH=10,
%02,UFF,M11,LENGTH=15,
%03)),
* Check if the amount has decimal dot and parse it as number & decimal
IFTHEN=(WHEN=(26,15,SS,EQ,C'.'),
PARSE=(%04=(ABSPOS=26,ENDBEFR=C'.',FIXLEN=12),
%05=(FIXLEN=02)),
OVERLAY=(26:%04,UFF,M11,LENGTH=12,
C'.',
%05,TRAN=ALTSEQ)),
* There is no decimal dot, so just pad leading zeroes
IFTHEN=(WHEN=NONE,
OVERLAY=(26:26,15,UFF,M11,LENGTH=15))
* Write the final output
OUTREC BUILD=(C'ORDER ',01,10,
C' COUNT ',11,15,
C' AMOUNT ',26,15)
/*
The Output from above is
ORDER 0000005467 COUNT 000000000000002 AMOUNT 000000000567.82
ORDER 0000000243 COUNT 000000000000010 AMOUNT 000000000000856
ORDER 0000000001 COUNT 000000000000002 AMOUNT 000000000059.80
Upvotes: 0