IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Covert k to 1000 / m to 1000000 using DFSORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
A_programmers

New User


Joined: 24 Mar 2010
Posts: 19
Location: USA

PostPosted: Tue Jun 23, 2020 6:52 pm
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1231
Location: Bamberg, Germany

PostPosted: Tue Jun 23, 2020 7:30 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3049
Location: NYC,USA

PostPosted: Tue Jun 23, 2020 9:08 pm
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1231
Location: Bamberg, Germany

PostPosted: Tue Jun 23, 2020 11:14 pm
Reply with quote

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
View user's profile Send private message
A_programmers

New User


Joined: 24 Mar 2010
Posts: 19
Location: USA

PostPosted: Sun Jul 05, 2020 11:51 am
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1231
Location: Bamberg, Germany

PostPosted: Sun Jul 05, 2020 12:06 pm
Reply with quote

Thank you for letting us know. icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts DFsort help with SUM() DFSORT/ICETOOL 12
No new posts DFSORT - VB file RDW getting overridden DFSORT/ICETOOL 3
Search our Forums:

Back to Top