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

Sum accounts at every group break


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

New User


Joined: 06 Nov 2008
Posts: 46
Location: Manila, Philippines

PostPosted: Wed Sep 08, 2010 9:05 am
Reply with quote

Hi All,
I have a file that contains group and account totals:
Code:
AAB       ;          1,950.00;              0.00;          1,950.00;
05612112  ;              0.00;              0.00;              0.00;
05645002  ;              0.00;              0.00;              0.00;
11100008  ;              0.00;              0.00;              0.00;
11100035  ;              0.00;              0.00;              0.00;
11109112  ;          1,000.00;              0.00;          1,000.00;
11109113  ;            500.00;              0.00;            500.00;
11109147  ;            294.00;              0.00;            294.00;
11109150  ;            156.00;              0.00;            156.00;
AAC       ;          3,900.00;              0.00;          3,900.00;
05611159  ;          1,900.00;              0.00;          1,900.00;
05611887  ;          2,000.00;              0.00;          2,000.00;
AAD       ;              0.00;              0.00;              0.00;
05645002  ;              0.00;              0.00;              0.00;


I want to sum the accounts under the group and compare it with the group total. Groups are alphanumeric and accounts are all numeric. I am thinking of putting the group id at the end of the record so that I can sum the account totals using sum fields. I'm thinking my intermediary record to be something like:
Code:
GRP1  ; VALUE; VALUE; VALUE;
ACCT1 ; VALUE; VALUE; VALUE;GRP1X
ACCT2 ; VALUE; VALUE; VALUE;GRP1X
GRP2  ; VALUE; VALUE; VALUE;
ACCT3 ; VALUE; VALUE; VALUE;GRP2X
ACCT4 ; VALUE; VALUE; VALUE;GRP2X

where X is just an indicator to distinguish it from the group id.

But I am confused on how to use when=group in this case. I want my output to be something like:

Code:
AAB       ;          1,950.00;              0.00;          1,950.00;
AABX      ;          1,950.00;              0.00;          1,950.00;
AAC       ;          3,900.00;              0.00;          3,900.00;
AACX      ;          3,900.00;              0.00;          3,900.00;
AAD       ;              0.00;              0.00;              0.00;
AADX      ;              0.00;              0.00;              0.00;


Any ideas?

Input file is 163 BYTES, FB (there are 5 more amounts to be summed aside from shown)
Output file is also 163 bytes, FB.
Thanks
Back to top
View user's profile Send private message
darkstar13

New User


Joined: 06 Nov 2008
Posts: 46
Location: Manila, Philippines

PostPosted: Wed Sep 08, 2010 11:13 am
Reply with quote

Hi all,
I settled for now using 3 steps to accomplish my goal:

1. separate group from acct lines; use WHEN=GROUP to add group id
on acct lines
2. using acct file from #1, sum fields based on group id
3. Merge group file from #1 with acct totals from #2

Would anyone know how I can merge these two sort statements?
Thanks
Back to top
View user's profile Send private message
smijoss

Active User


Joined: 30 Aug 2007
Posts: 114
Location: pune

PostPosted: Wed Sep 08, 2010 12:02 pm
Reply with quote

how dou you identify a group start , anything that starts with A or it can be any non numeric character

instead of using 3 steps,
for the when=group, at the start of group, push the entire header,
then sun the records.
then you can split them up into 2 line using the / in outrec
Back to top
View user's profile Send private message
smijoss

Active User


Joined: 30 Aug 2007
Posts: 114
Location: pune

PostPosted: Wed Sep 08, 2010 4:02 pm
Reply with quote

Code:
//S020        EXEC PGM=ICETOOL                                         
//FILE1   DD  *                                                       
AAB       ;          1,950.00;              0.00;          1,950.00;   
05612112  ;              0.00;              0.00;              0.00;   
05645002  ;              0.00;              0.00;              0.00;   
11100008  ;              0.00;              0.00;              0.00;   
11100035  ;              0.00;              0.00;              0.00;   
11109112  ;          1,000.00;              0.00;          1,000.00;   
11109113  ;            500.00;              0.00;            500.00;   
11109147  ;            294.00;              0.00;            294.00;   
11109150  ;            156.00;              0.00;            156.00;   
AAC       ;          3,900.00;              0.00;          3,900.00;   
05611159  ;          1,900.00;              0.00;          1,900.00;   
05611887  ;          2,000.00;              0.00;          2,000.00;   
AAD       ;              0.00;              0.00;              0.00;   
05645002  ;              0.00;              0.00;              0.00;   
/*                                                                     
//TEMP     DD DSN=TEMP.TEST.DEL1,                                 
//             DISP=(NEW,CATLG),UNIT=DISK,                             
//             SPACE=(27998,(400,100),RLSE)                           
//FILEOUT  DD DSN=TEMP.TEST.DEL2,                                 
//             DISP=(NEW,CATLG),UNIT=DISK,                             
//             SPACE=(27998,(400,100),RLSE)                       
//TOOLIN   DD  *                                                   
   COPY FROM(FILE1) TO(TEMP) USING(CTL1)                           
   COPY FROM(TEMP) TO(FILEOUT) USING(CTL2)                         
//TOOLMSG  DD  SYSOUT=*                                           
//DFSMSG  DD  SYSOUT=*                                             
//CTL1CNTL DD  *                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,ZD,NE,NUM),PUSH=(164:1,163))
  OUTREC BUILD=(1,11,                                             
            12,18,UFF,TO=ZD,C';',                                 
            31,18,UFF,TO=ZD,C';',                                 
            50,18,UFF,TO=ZD,                                       
            68,259)                                               
  OUTFIL FNAMES=TEMP,INCLUDE(1,8,ZD,EQ,NUM)                       
//CTL2CNTL DD  *                                                   
  SORT FIELDS=(164,3,CH,A)                                         
  SUM FIELDS=(12,18,ZD,                                           
            31,18,ZD,                                             
            50,18,ZD)                                             
  OUTFIL OUTREC=(164,163,/,164,3,C'X',11:C';',                     
               12,18,ZD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-),C';',
               31,18,ZD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-),C';', 
               50,18,ZD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-),68,96)
Back to top
View user's profile Send private message
darkstar13

New User


Joined: 06 Nov 2008
Posts: 46
Location: Manila, Philippines

PostPosted: Wed Sep 15, 2010 8:28 am
Reply with quote

smijoss wrote:
how dou you identify a group start , anything that starts with A or it can be any non numeric character

instead of using 3 steps,
for the when=group, at the start of group, push the entire header,
then sun the records.
then you can split them up into 2 line using the / in outrec


group is any non-numeric character icon_biggrin.gif
thanks for the code.
i think my code will work too in one step if i use icetool, icon_biggrin.gif
but yours is much simpler, so thanks!
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Sep 15, 2010 9:52 pm
Reply with quote

darkstar13,

Here is an alternative way of getting the desired results in one pass.

You mentioned having 8 amount fields that needs to be summed, I just put ??? for the position. Replace them with the correct positions of the amount fields.

Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*   
//SORTIN   DD DSN=Your input FB 163 byte file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                                 
//SYSIN    DD *                                                       
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(167:8X'00000000000000000C')),       
  IFTHEN=(WHEN=GROUP,BEGIN=(1,3,ZD,NE,NUM),PUSH=(164:1,3)),           
  IFTHEN=(WHEN=(1,3,ZD,EQ,NUM),                                       
  OVERLAY=(167:012,18,UFF,PD,LENGTH=9,     $ AMT -1                   
               031,18,UFF,PD,LENGTH=9,     $ AMT -2                   
               050,18,UFF,PD,LENGTH=9,     $ AMT -3                   
               ???,18,UFF,PD,LENGTH=9,     $ AMT -4                   
               ???,18,UFF,PD,LENGTH=9,     $ AMT -5                   
               ???,18,UFF,PD,LENGTH=9,     $ AMT -6                   
               ???,18,UFF,PD,LENGTH=9,     $ AMT -7                   
               ???,18,UFF,PD,LENGTH=9))    $ AMT -8                   
                                                                       
  SORT FIELDS=(164,3,CH,A),EQUALS                                     
                                                                       
  OUTFIL REMOVECC,NODETAIL,BUILD=(1,163),                             
  SECTIONS=(164,3,                                                     
  HEADER3=(1,163),                                                     
  TRAILER3=(164,3,C'X',11:C';',                                       
            TOT=(167,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(176,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(185,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(194,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(203,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(212,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(221,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';',   
            TOT=(230,9,PD,EDIT=(SII,III,III,IIT.TT),SIGNS=(,-)),';')) 
//*
Back to top
View user's profile Send private message
darkstar13

New User


Joined: 06 Nov 2008
Posts: 46
Location: Manila, Philippines

PostPosted: Fri Sep 17, 2010 4:47 am
Reply with quote

thanks Kolusu! =) works great!
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 Compare latest 2 rows of a table usin... DB2 1
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Splitting group records based on deta... DFSORT/ICETOOL 8
No new posts SORT HELP - SORT A COLUMN and GROUP B... DFSORT/ICETOOL 9
No new posts INCLUDE COND with WHEN=GROUP SYNCSORT 12
Search our Forums:

Back to Top