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

How to change 'K' or 'M' use Sort


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

New User


Joined: 26 Feb 2006
Posts: 19
Location: usa

PostPosted: Thu May 18, 2017 7:11 am
Reply with quote

Hello everyone,

I want to change below data
Code:
1M      1M      128K                     
145M    145M    0K                       
1024M   1024M   0K                       
0K      0K      0K                       
0K      0K      0K                       
256K    256K    64K                     
256K    256K    64K                     
1M      1M      64K                     
512K    512K    64K                     
22M     22M     128K                     
60M     60M     256K                     
1M      1M      128K                     
1M      1M      128K                     
198M    198M    0K                       
1024M   1024M   0K                       
0K      0K      0K                       
0K      0K      0K                       
256K    256K    64K                                             
256K    256K    64K                                             
1M      1M      64K                                             
256K    256K    64K


change to
Code:
                                                                 
1048576         1048576         131072                           
152043520       152043520       0                               
1073741824      1073741824      0                               
0               0               0                               
0               0               0                               
262144          262144          65536                           
262144          262144          65536                           
1048576         1048576         65536                           
524288          524288          65536                           
23068672        23068672        131072                           
62914560        62914560        262144                           
1048576         1048576         131072                           
1048576         1048576         131072                           
207618048       207618048       0                               
1073741824      1073741824      0                             
0               0               0                             
0               0               0                             
262144          262144          65536                           
262144          262144          65536                         
1048576         1048576         65536                           
262144          262144          65536                         


thanks in advance
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Thu May 18, 2017 1:12 pm
Reply with quote

I don't know if this is the most efficient way of doing it, but here is a sample rexx. You can expand it to process the complete dataset.

Code:
/******************rexx*******************/
string = '0M      60M     128K'
parse var string col1 col2 col3 .
do i = 1 to 3
  interpret "temp = col"i
  select
    when pos('K',temp) \= 0 then do
      interpret "col"i "=" (substr(temp,1,(pos('K',temp)-1))) * 1024
      end
    when pos('M',temp) \= 0 then do
      interpret "col"i "=" (substr(temp,1,(pos('M',temp)-1))) * 1048576
      end
    otherwise
  end
end
string = left(col1,10) || left(col2,10) || left(col3,10)
say string

Output:
Code:
0         62914560  131072

Hope this helps.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu May 18, 2017 1:31 pm
Reply with quote

not what the TS asked for, but
writing small rexx snippets is like doing crosswords for me icon_wink.gif

try with

the script
Code:

#! /usr/bin/env rexx
Trace "O"
numeric digits 15

in = "356 0M 60M 128K 2G 346Z"

mult.B = 1
mult.K = 1024
mult.M = 1024*1024
mult.G = 1024*1024*1024

ou = ""
sz = 16
do while ( in \= "" )
    parse var in tk in
    tk = translate(tk)
    mf = right(tk,1)
    if datatype(mf,"M") then ,
        tk = strip(tk,,mf)
    else ,
        mf = "B"
    if ( symbol("mult."mf) = "VAR" ) then ,
        ou = ou || left(tk * mult.mf,sz," ")
    else ,
        ou = ou || copies("*",sz-1)" "
end
say ">>"ou"<<"



(*) it is one of my pet peeves to decouple the real coding from the control data
adding a new multiplier factor will not make the coding to change

the result
Code:

>>356             0               62914560        131072          2147483648      *************** <<


doing it with sort could be pretty boring ...
shifting right to find the multiplier factor, and a bunch of ifthen to do the calculations

but probably not impossible

edited the code to deal with BYTES with or without the B suffix
the code assumes that the suffix is VALID
pretty easy to add the check ( done )
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Thu May 18, 2017 2:15 pm
Reply with quote

Quote:
I don't know if this is the most efficient way of doing it

Now I know that was not icon_redface.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu May 18, 2017 2:52 pm
Reply with quote

probably You have not written as many lines of Rexx code as I have done icon_wink.gif
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu May 18, 2017 7:39 pm
Reply with quote

Quote:
doing it with sort could be pretty boring ...
I thought of taking up some of that, before I get to my much boring work icon_smile.gif. There could be better ways, but here is one of them that I can think of now.
Code:
//SYSIN     DD *                                       
  OPTION 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)))           

For the OP's input data provided in SORTIN, SORTOUT had
Code:
1048576         1048576         131072
152043520       152043520       0     
1073741824      1073741824      0     
0               0               0     
0               0               0     
262144          262144          65536
262144          262144          65536
1048576         1048576         65536
524288          524288          65536
23068672        23068672        131072
62914560        62914560        262144
1048576         1048576         131072
1048576         1048576         131072
207618048       207618048       0     
1073741824      1073741824      0     
0               0               0     
0               0               0     
262144          262144          65536
262144          262144          65536
1048576         1048576         65536
262144          262144          65536
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 Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top