MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SUM Fields with PUSH

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Wed May 06, 2015 12:20 pm    Post subject: SUM Fields with PUSH Reply with quote

Hi,

Please advise, Is it possible to sum the records from 1 to 5998(SEQNO) i.e a group of records will start from 1 to 5998 and a summary record will be in 5999th record

Once i use SUM FIELDS i will have 1 to 5998 records in one line, After that i need bring the 5999th records to the SUM'ed line.

I tried with Joinkeys have same input file, is it possible to do without joinkeys with one Pass


Code:

//SORTJNF1 DD DSN=FB1,DISP=SHR             
//SORTJNF2 DD DSN=FB1,DISP=SHR             
//SORTOUT DD DSN=FB.SORTOU15,DISP=(,CATLG,DELETE),   
//          SPACE=(CYL,(10,10),RLSE)                     
//SYSIN    DD *                                           
  JOINKEYS FILE=F1,FIELDS=(7,7,A)                               
  JOINKEYS FILE=F2,FIELDS=(7,7,A)                               
  JOIN UNPAIRED,F2                                             
  REFORMAT FIELDS=(F2:1,23,F1:18,6,?)                           
  OPTION COPY                                                   
  OUTFIL IFTHEN=(WHEN=(30,1,CH,EQ,C'B'),                       
         BUILD=(7,5,C',',12,2,C',',18,6,PD,EDIT=(IIIIIIIIT.TT), Matching record will have values in F1
          C',',24,6,PD,EDIT=(IIIIIIIIT.TT))),                   
         IFTHEN=(WHEN=NONE,                                     
         BUILD=(7,5,C',',12,2,C',',18,6,PD,EDIT=(IIIIIIIIT.TT), unpaired record will not have any values in F1 so moving zeros.
          C',        0.00'))                                 
/*                                                       
//JNF1CNTL DD *                                           
  INCLUDE COND=(15,4,CH,LT,C'5999',AND,                          PIC the record till 5998
               (13,2,CH,EQ,C'31',OR,13,2,CH,EQ,C'67',OR,         
                13,2,CH,EQ,C'01',OR,13,2,CH,EQ,C'61'))   
  INREC BUILD=(2,17,229,6)                               
  SUM FIELDS=(18,6,PD)                                           Sum the records
/*                                                       
//JNF2CNTL DD *                                           
  INCLUDE COND=(15,4,CH,EQ,C'5999',AND,                          GET the 5999th records
               (13,2,CH,EQ,C'31',OR,13,2,CH,EQ,C'67',OR,
                13,2,CH,EQ,C'01',OR,13,2,CH,EQ,C'61'))   
  INREC BUILD=(2,17,223,6)                                     
/*


Input File layout

FIELD2   FIELD3   FIELD4   FIELD5   FIELD6   FIELD7        FIELD8       
3/AN     3/AN     5/AN     2/AN     4/AN     6/PS          6/PS         
(2-4)    (5-7)    (8-12)   (13-14)  (15-18)  (223-228)     (229-234)   
2------- 3------- 4------- 5------- 6------- 8------------ 9------------



Thanks
Magesh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12369
Topics: 75
Location: San Jose

PostPosted: Wed May 06, 2015 12:28 pm    Post subject: Reply with quote

Magesh_J,

If I understand correctly you just need 2 records with summed values? The first record will have summed values for 1 thru 5998 records and the second record will the summed values for 5999 thru end of file?

If that is indeed the requirement then you have complicated a simple request.

A few more clarifications.

You are sorting FIELD-4 and Field-5 as a key.

Field-5 can have the following values

Code:

01
31
61
67


So that would yield you a minimum of 4 summed records. Where do you want the summary record data? on all the records? or just on the last one or on the key

Assume you have the following input
Code:

       FIELD-4    FIELD-5   FIELD-6      FIELD-8             
       AAAAA      01        2000         +100                 
       AAAAA      01        2001         +200                 
                                                             
       AAAAA      31        3000         +300                 
       AAAAA      31        3001         +400                 
       AAAAA      31        3002         +500                 
                                                             
       AAAAA      61        4000         +250                 
                                                             
       AAAAA      67        5000         +600                 
       AAAAA      67        5001         -700                 
       AAAAA      67        5002         +800                 
                                                             
       ?????      ??        5999         +10000               


After the summation on the key (7,7,CH,A) you would end up with the following for the records up to 5998

Code:

                                                     
       FIELD-4    FIELD-5   FIELD-6      FIELD-8     
       AAAAA      01        2000         +300         
                                                     
       AAAAA      31        3000         +1200       
                                                     
       AAAAA      61        4000         +250         
                                                     
       AAAAA      67        5000         +700         


Now where do you want the final 5999 record value?

If 5999 record has the key AAAA 01 then do you want on the summed record for that key like below?
Code:

      FIELD-4    FIELD-5   FIELD-6      FIELD-8   SUMMARY-FIELD
      AAAAA      01        2000         +300      +10000       
                                                               
      AAAAA      31        3000         +1200     +0           
                                                               
      AAAAA      61        4000         +250      +0           
                                                               
      AAAAA      67        5000         +700      +0           

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Wed May 06, 2015 9:28 pm    Post subject: Reply with quote

Thanks Kolusu, for looking into this.

Input
Code:

      FIELD-4  IELD-5     FIELD-6       FIELD-7 FIELD-8             
       Store1      01        2000             0    +100                 
       Store1      01        2001             0    +200
       Store1      01        5999         10000      +0
       Store1      31        3001             0    +220
       Store1      31        3000             0    +330
       Store1      31        5999         32000      +0
       Store1      61        5999         40000      +0
       Store1      67        5000             0    +600                 
       Store1      67        5001             0    +700                 
       Store1      67        5999         40000      +0
       STORE2      01        2000             0    +300                 
       STORE2      01        2001             0    +200
       STORE2      01        5999         30000      +0
       STORE2      31        5999         52000      +0
       STORE2      61        5999         40000      +0
       STORE2      67        5000             0    +500                 
       STORE2      67        5001             0    +400                 
       STORE2      67        5999         30000      +0


Note: Store1 has Four types of records 01,31,61,67.
For each type of record we have a summary record i.e 5999 in field 6.

In the above example Let us take Store1 01st record.

It has two sequence records and one summary record
I need to sum up the two sequence record and bring the total to the summary record. This is wat we did it with Joinkeys.
Otherway is also fine. Bring the summary record to the summed record.

As per our joinkeys output would be(for clarity reason i am displaying Field6 in the acutal output of the joinkey field6 will not be there)
Code:

       Store1      01        5999         10000    +300                     


Otherway
Code:

       Store1      01        2000         10000    +300                 


why both way is fine is because, we need not required Field6 in the output.

Also note Every store with a type will have summary records, but sequence may or may not be

example
Code:

       Store1      61        5999         40000      +0
       STORE2      31        5999         52000      +0
       STORE2      61        5999         40000      +0

In this situation we are just moving C', 0.00' to the output in joinkeys.


Output
Code:

      FIELD-4  IELD-5     FIELD-6       FIELD-7 FIELD-8             
       Store1      01        5999         10000     300
       Store1      31        5999         32000     550
       Store1      61        5999         40000       0
       Store1      67        5999         40000    1300
       Store2      01        5999         30000     500
       STORE2      31        5999         52000       0
       STORE2      61        5999         40000       0
       STORE2      67        5999         30000     900


Field6 is not required in the output hence the output should be like below.

Output with Comma seperated
Code:

       Store1,      01,     10000,     300
       Store1,      31,     32000,     550
       Store1,      61,     40000,       0
       Store1,      67,     40000,    1300
       Store2,      01,     30000,     500
       STORE2,      31,     52000,       0
       STORE2,      61,     40000,       0
       STORE2,      67,     30000,     900


Thanks
Magesh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12369
Topics: 75
Location: San Jose

PostPosted: Wed May 06, 2015 10:18 pm    Post subject: Reply with quote

Magesh_J,

Here is an untested version which will give you the desired results.

Code:

//SYSIN    DD *                                                     
  INCLUDE COND=((13,2,SS,EQ,C'01,31,61,67'),AND,                   
                15,4,CH,LE,C'5999')                                 
                                                                   
  INREC IFOUTLEN=19,IFTHEN=(WHEN=INIT,                             
  BUILD=(008,5,                                $ FIELD-4           
         013,2,                                $ FIELD-5           
         223,6,                                $ FIELD-7           
         229,6,                                $ FIELD-8           
         015,4)),                              $ FIELD-6           
                                                                   
  IFTHEN=(WHEN=(20,4,CH,EQ,C'5999'),           $ IF 5999           
  OVERLAY=(14:5Z,X'0C')),                      $ ZERO OUT FIELD8   
                                                                   
  IFTHEN=(WHEN=NONE,                           $ ELSE               
  OVERLAY=(08:5Z,X'0C'))                       $ ZERO OUT FIELD7   
                                                                   
  SORT FIELDS=(1,7,CH,A)                       $ FIELD-4 + FIELD-5 
                                                                   
  SUM FIELDS=(08,6,PD,                         $ SUM FOR =5999     
              14,6,PD)                         $ SUM FOR OTHER     
                                                                   
  OUTREC BUILD=(01,5,                          $ FIELD-4           
                C',',                          $ COMMA             
                06,2,                          $ FIELD-5           
                C',',                          $ COMMA             
                08,6,PD,EDIT=(IIIIIIIIT.TT),   FIELD-7             
                C',',                          $ COMMA             
                14,6,PD,EDIT=(IIIIIIIIT.TT),   FIELD-8             
                C',')                          $ COMMA             
//*

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Wed May 06, 2015 10:28 pm    Post subject: Reply with quote

Now i got an idea, I made it little complex.

Rough draft not yet tested.
Code:

SYSIN DD *
  INCLUDE COND=(15,4,CH,LE,C'5999',AND,                         
               (13,2,CH,EQ,C'31',OR,13,2,CH,EQ,C'67',OR,
                13,2,CH,EQ,C'01',OR,13,2,CH,EQ,C'61'))   
  INREC IFTHEN=(WHEN=(15,4,CH,LT,C'5999'),
                      OVERLAY=(223:+0,TO=PD,LENGTH=6)),
        IFTHEN=(WHEN=NONE,
                      OVERLAY=(229:+0,TO=PD,LENGTH=6))
  SORT FIELDS=(8,7,CH,A)
  SUM FIELDS=(223,6,PD,229,6,PD)
  OUTFIL BUILD=(08,5,C',',
                13,2,C',',
                223,6,PD,EDIT=(IIIIIIIIT.TT),C',',
                229,6,PD,EDIT=(IIIIIIIIT.TT))


Please advise on this code.

Regards,
Magesh
Back to top
View user's profile Send private message
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Wed May 06, 2015 10:31 pm    Post subject: Reply with quote

Kolusu,

Sorry, i missed to see your response, great I tried similar way, but yours is optimum solution.

Thank you very much.

Regards.
Magesh
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group