|
View previous topic :: View next topic
|
| Author |
Message |
shea24
New User
Joined: 01 Nov 2023 Posts: 5 Location: czechia
|
|
|
|
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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
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 |
|
 |
shea24
New User
Joined: 01 Nov 2023 Posts: 5 Location: czechia
|
|
|
|
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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
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 |
|
 |
shea24
New User
Joined: 01 Nov 2023 Posts: 5 Location: czechia
|
|
|
|
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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
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 |
|
 |
shea24
New User
Joined: 01 Nov 2023 Posts: 5 Location: czechia
|
|
|
|
| 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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
| 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 |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1436 Location: Bamberg, Germany
|
|
|
|
| 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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
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 |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1436 Location: Bamberg, Germany
|
|
|
|
| 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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
| 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 |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10902 Location: italy
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|