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

DFsort help with SUM()


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

New User


Joined: 01 Nov 2023
Posts: 5
Location: czechia

PostPosted: Wed Nov 01, 2023 4:42 pm
Reply with quote

Hello ,

I have an input file with filename , volume and size in bytes.
My requirement is to sort the file and have only the volume and sum of size of all the files in the volume as output.
The size in bytes should be converted to KB/GB/MB based on the sum.
Could you please help me in this.

Size below are just for sample.
I/P file.

ABC 524986 VOL1
DEF 22502 VOL1
GHI 1919919199 VOL2
JJJ 9797 vOL3
o/p file

VOL1 0.7878MB
VOL2 1.5GB
VOL3 9KB

Thanks,
Shea
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 01, 2023 4:59 pm
Reply with quote

1. Please, re-post it as follows.

I/P file.
Code:
ABC                            524986 VOL1
DEF                              22502 VOL1
GHI                    1919919199  VOL2
JJJ                                9797 vOL3


o/p file
Code:
VOL1    0.7878MB
VOL2    1.5GB
VOL3    9KB


2. Please, provide any sample: what did you try so far?
If you did not try at all, then: why do you think SORT is good for you?

3. Some initial hints:
- resort your data by volume name - SORT FIELDS=
- provide detection of record groups with the same volume name - WHEN=GROUP or SECTIONS=(...)
- calculate total amount of bytes per each volume - TOT=(...)
- if needed, convert bytes amount to KB/MB/GB - IFTHEN=(WHEN=(...))
Back to top
View user's profile Send private message
shea24

New User


Joined: 01 Nov 2023
Posts: 5
Location: czechia

PostPosted: Wed Nov 01, 2023 5:09 pm
Reply with quote

My sorted output file is
V00129 181825.146
V00896 4194303.999
V01027 4230964.261
V01156 15589922.165
V01318 6.202

The size is in KB. I converted them by multiplying the sum of the size with 1024. I want them in KB/GB/MB based on the size.

I used the sort card.
SUM FIELDS=(46,11,ZD)
OUTFIL FNAMES=OUTPUT,
OUTREC=(1:58,6,1X,((46,11,ZD,MUL,+1000),DIV,+1024),
EDIT=(IIIIIIIT.TTT),C'K',

Here 46,11 is the size in bytes
58,6 is the volume,[/code]
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 01, 2023 5:11 pm
Reply with quote

Please, re-post it as follows

My sorted output file is
Code:
V00129    181825.146
V00896  4194303.999
V01027  4230964.261
V01156 15589922.165
V01318              6.202


The size is in KB. I converted them by multiplying the sum of the size with 1024. I want them in KB/GB/MB based on the size.

I used the sort card.
Code:
SUM FIELDS=(46,11,ZD)                             
OUTFIL FNAMES=OUTPUT,                             
OUTREC=(1:58,6,1X,((46,11,ZD,MUL,+1000),DIV,+1024),
EDIT=(IIIIIIIT.TTT),C'K',   


Here 46,11 is the size in bytes
58,6 is the volume,

P.S.
Adding the dot '.' in the middle of the result of multiplication - is the best way to create unbelievable mess in the next steps.
In your first post you planned to use all of them: KB/MB/GB?
Back to top
View user's profile Send private message
shea24

New User


Joined: 01 Nov 2023
Posts: 5
Location: czechia

PostPosted: Wed Nov 01, 2023 5:27 pm
Reply with quote

Apologies for not reposting. My requirement is to convert the bytes to KB/MB/GB based on the sum.
[P.S.
Adding the dot '.' in the middle of the result of multiplication - is the best way to create unbelievable mess in the next steps. In your first post you planned to use all of them: KB/MB/GB]

Is it about the dot (.) in the edit ?[/quote]
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 01, 2023 5:42 pm
Reply with quote

Let's resolve the issues from the beginning, not from the end.


1. Are you really using "free text format"?
Code:
ABC                            524986 VOL1
DEF                              22502 VOL1
GHI                    1919919199  VOL2
JJJ                                9797 vOL3

If yes, how do you plan to calculate the SUM?

2. Did you try using the suggested SECTIONS=(...) or WHEN=GROUP to calculate partial amounts per volume?
If not, there is no sense to start thinking about KB/MB/GB at this point.
Back to top
View user's profile Send private message
shea24

New User


Joined: 01 Nov 2023
Posts: 5
Location: czechia

PostPosted: Wed Nov 01, 2023 6:01 pm
Reply with quote

Code:
DATA_SET_NAME                                TOTAL_BYTES VOLUME   
____________________________________________ ___________ __________
ABC                                           4294967295 VOL071   
DEF                                            106609708 VOL071   
BBB                                                 8503 VOL072   
CCCC                                               11044 VOL073   
HHHHH                                               6672 VOL073   
JJJJJ                                               6672 VOL073   
LKKKKKK                                            62286 VOL073   



This is the input file. It's not of free form.

I used this sort card based on your input and it worked. Let me know if it's ok.

Code:
SORT FIELDS=(58,6,ZD,A)                                 
    SUM FIELDS=(46,11,ZD)                               
    OUTREC IFTHEN=(WHEN=(46,11,ZD,LE,1048576),         
    BUILD=(1:58,6,1X,((46,11,ZD,MUL,+1000),DIV,+1024), 
    EDIT=(IIIIIIIT.TTT),C'K')),                         
    IFTHEN=(WHEN=(46,11,ZD,LE,1073741824),             
    BUILD=(1:58,6,1X,                                   
    ((46,11,ZD,MUL,+1000),DIV,+1048576),               
    EDIT=(IIIIIIIT.TTT),C'M')),                         
    IFTHEN=(WHEN=(46,11,ZD,GT,1073741824),             
    BUILD=(1:58,6,1X,                                   
    ((46,11,ZD,MUL,+1000),DIV,+1073741824),             
    EDIT=(IIIIIIIT.TTT),C'G'))                         
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 01, 2023 6:10 pm
Reply with quote

shea24 wrote:


I used this sort card based on your input and it worked. Let me know if it's ok.

Code:
SORT FIELDS=(58,6,ZD,A)                                 
    SUM FIELDS=(46,11,ZD)                               
    OUTREC IFTHEN=(WHEN=(46,11,ZD,LE,1048576),         
    BUILD=(1:58,6,1X,((46,11,ZD,MUL,+1000),DIV,+1024), 
    EDIT=(IIIIIIIT.TTT),C'K')),                         
    IFTHEN=(WHEN=(46,11,ZD,LE,1073741824),             
    BUILD=(1:58,6,1X,                                   
    ((46,11,ZD,MUL,+1000),DIV,+1048576),               
    EDIT=(IIIIIIIT.TTT),C'M')),                         
    IFTHEN=(WHEN=(46,11,ZD,GT,1073741824),             
    BUILD=(1:58,6,1X,                                   
    ((46,11,ZD,MUL,+1000),DIV,+1073741824),             
    EDIT=(IIIIIIIT.TTT),C'G'))                         


I repeat: you need to fix the issues starting from the beginning, not from the end.

The first issue with free text format is resolved, as soon as you followed the advice to use the Code button.

The second issue is: calculation the total amounts grouped by volumes.

Unless you are able to resolve #2, it makes no sense to consider conversion to KB/MB/GB.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Wed Nov 01, 2023 8:38 pm
Reply with quote

If your input is from DCOLLECT Data, you SHOULD check if the fields are in 31 bit, or 63 bit in length. Before summing, also make sure the target field is large enough to hold the result.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 01, 2023 8:50 pm
Reply with quote

There is only one non-obvious trick in this task: after the total amounts by volumes has been calculated, SORT cannot provide re-calculation of bytes to KB/MB/GB in the same SORT pass.
Either two SORT JCL steps may be needed, or two SORT passes can be combined into one step for ICETOOL/SYNCTOOL.

Also need to take care of the required number of digits during re-calculation involved multiplication and division. If not enough, hi-order digits may just disappear without any trace...

Code:
//*====================================================================
//SORTGRP  EXEC PGM=SYNCTOOL   or ICETOOL                                       
//*                                                                   
//SSMSG    DD  SYSOUT=*         use //DFMSG for ICETOOL                                               
//TOOLMSG  DD  SYSOUT=*                                               
//SORTIN   DD  *                                                       
DATA_SET_NAME                                TOTAL_BYTES VOLUME       
____________________________________________ ___________ __________   
ABC                                           4294967295 VOL071       
DEF                                            106609708 VOL071       
BBB                                                 8503 VOL072       
BBB                                             10000000 VOL072       
CCCC                                               11044 VOL073       
HHHHH                                               6672 VOL073       
JJJJJ                                               6672 VOL073       
LKKKKKK                                            62286 VOL073       
XXXXXXXXX                                           1024 VOL01K       
YYYYYYYYY                                        1048576 VOL01M       
ZZZZZZZZZ                                     1073741824 VOL01G       
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*                                                                   
//SUMS@    DD  SYSOUT=*                                               
//SUMS     DD  SPACE=(TRK,(10,10))                                     
//*                                                                   
//SORTOUT  DD  SYSOUT=*                                               
//*....................................................................
//TOOLIN   DD  *                                                       
 SORT FROM(SORTIN) TO(SUMS)    USING(GRPS)                             
 COPY FROM(SUMS)   TO(SORTOUT) USING(CONV)                             
//*....................................................................
//GRPSCNTL DD  *                                                       
 INCLUDE COND=(55,2,ZD,EQ,NUM)                                         
 SORT FIELDS=(58,6,CH,A)                                               
 OUTFIL FNAMES=(SUMS,SUMS@),                                           
        REMOVECC,NODETAIL,                                             
        SECTIONS=(58,6,                                               
                  TRAILER3=(1:58,6,                                   
                           46:TOT=(46,11,ZD,EDIT=(TTTTTTTTTTT))))     
//*....................................................................
//CONVCNTL DD  *                                                       
 INREC OVERLAY=(30:46,11,ZD,MUL,+1000,                                 
                   EDIT=(TTTTTTTTTTTTTTT))                             
                                                                       
 OUTREC IFTHEN=(WHEN=(46,11,ZD,LT,+1048576),                           
                BUILD=(1:1,6,                                         
                      10:30,15,ZD,DIV,+1024,                           
                         EDIT=(IIIIIT.TTT),C'K')),                     
        IFTHEN=(WHEN=(46,11,ZD,LT,+1073741824),                       
                BUILD=(1:1,6,                                         
                      10:30,15,ZD,DIV,+1024,                           
                                  DIV,+1024,                           
                         EDIT=(IIIIIT.TTT),C'M')),                     
        IFTHEN=(WHEN=NONE,                                             
                BUILD=(1:1,6,                                         
                      10:30,15,ZD,DIV,+1024,                           
                                  DIV,+1024,                           
                                  DIV,+1024,                           
                         EDIT=(IIIIIT.TTT),C'G'))                     
//*....................................................................


SUMS@: intermediate results, for verification only.
Code:
********************************* TOP OF DATA ************
VOL01G                                       01073741824 
VOL01K                                       00000001024 
VOL01M                                       00001048576 
VOL071                                       04401577003 
VOL072                                       00010008503 
VOL073                                       00000086674 
******************************** BOTTOM OF DATA **********


SORTOUT:
Code:
********************************* TOP OF DATA *******
VOL01G        1.000G                                 
VOL01K        1.000K                                 
VOL01M        1.000M                                 
VOL071        4.099G                                 
VOL072        9.544M                                 
VOL073       84.642K                                 
******************************** BOTTOM OF DATA *****
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Wed Nov 01, 2023 8:59 pm
Reply with quote

I would not go this way, you may face deviations. It's better to multiply first, then divide. I am not that quick providing solutions, it's a day off for me today.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 01, 2023 9:58 pm
Reply with quote

Joerg.Findeisen wrote:
I would not go this way, you may face deviations. It's better to multiply first, then divide. I am not that quick providing solutions, it's a day off for me today.


It is multiplied FIRST: in INREC statement.
It is divided NEXT: in OUTREC statement.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Nov 01, 2023 10:30 pm
Reply with quote

here a link to the IBM smart dfsort tricks page

www.ibm.com/support/pages/smart-dfsort-tricks
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 - VB file RDW getting overridden DFSORT/ICETOOL 3
No new posts Volume chain using DFSORT DFSORT/ICETOOL 17
Search our Forums:

Back to Top