|
View previous topic :: View next topic
|
| Author |
Message |
A_programmers
New User
Joined: 24 Mar 2010 Posts: 19 Location: USA
|
|
|
|
Dear Friend,
This specific query is related to converting Text representation of number to number using DFSORT.
I have a input file field of 40 bytes which contains data as below :
| Code: |
Amount 12K Required 20-June-2020
Amount 52.2M Available 15-June-2020
Amount 1252M Overspend 05-June-2020
|
I need to convert above data in such as way that 'K' is replaced by value before 'K' multiplied by 1000 and 'M' is replaced by value before 'M' multiplied by million as shown below :
| Code: |
Amount 12000 Required 20-June-2020
Amount 52200000 Available 15-June-2020
Amount 1252000000 Overspend 05-June-2020
|
Does anyone know how this can be achieved using DFSORT ? |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
There was once a sample in the forum like this one:
| Code: |
//FORMAT EXEC PGM=ICEMAN
//SORTIN DD *
1M 1M 128K
145M 145M 0K
1024M 1024M 0K
0K 0K 0K
256K 256K 64K
/*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(COPY)
OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(1:1,80,SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=INIT,
FINDREP=(INOUT=(C'K',C',1024,',
C'M',C',1048576,',
C'G',C',1073741824,'))),
IFTHEN=(WHEN=INIT,PARSE=(%1=(ENDBEFR=C',',FIXLEN=10,REPEAT=6)),
OVERLAY=(%1,UFF,MUL,%2,UFF,M10,LENGTH=16,
01:01,16,JFY=(SHIFT=LEFT),
%3,UFF,MUL,%4,UFF,M10,LENGTH=16,
17:17,16,JFY=(SHIFT=LEFT),
%5,UFF,MUL,%6,UFF,M10,LENGTH=16,
33:33,16,JFY=(SHIFT=LEFT)))
END
/* |
Works pretty well. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
That's this - ibmmainframes.com/viewtopic.php?t=65945&highlight=145m
You can try this as well -
1. INREC PARSE into 4 fields delimited by SPACE.
2. Pick the second one and do a SHIFT= RIGHT, look for 'K'/'M' at last position of the field and multiply the numeric part of the field by 1000/1000000. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
| Code: |
OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,
PARSE=(%10=(ENDBEFR=BLANKS,FIXLEN=10),
%21=(STARTAT=NUM,ENDBEFR=BLANKS,ENDBEFR=UC,FIXLEN=8),
%22=(SUBPOS=1,FIXLEN=1),
%30=(FIXLEN=61)),
OVERLAY=(81:%21,X,%22,CHANGE=(11,C' ',C'00000000001',
C'K',C'00000001000',
C'M',C'00001000000',
C'G',C'01000000000'))),
IFTHEN=(WHEN=INIT,
PARSE=(%23=(ABSPOS=81,STARTAT=NUM,ENDBEFR=C'.',FIXLEN=4),
%24=(ENDBEFR=BLANKS,FIXLEN=4)),
OVERLAY=(81:%23,UFF,M11,%24,JFY=(SHIFT=(LEFT),TRAIL=C'0000'))),
IFTHEN=(WHEN=INIT,
OVERLAY=(%10,X,
(81,8,ZD,MUL,90,11,ZD),DIV,+10000,LENGTH=16,X,
%30)),
IFTHEN=(WHEN=INIT,BUILD=(1,80,SQZ=(SHIFT=LEFT,MID=C' ',LENGTH=80)))
END |
Output:
| Code: |
Amount 12000 Required 20-June-2020
Amount 52200000 Available 15-June-2020
Amount 1252000000 Overspend 05-June-2020 |
|
|
| Back to top |
|
 |
A_programmers
New User
Joined: 24 Mar 2010 Posts: 19 Location: USA
|
|
|
|
Thanks Rohit and Joerg. It is working perfectly fine.
Initially it took me couple of parses of above logic to understand how it is working; at the end finally I understood the logic. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
Thank you for letting us know.  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|