Page 1 of 1

sumfields on two fields

PostPosted: Sun Sep 03, 2017 10:54 am
by Sunindia
Hi,

I have a below JCL. My input file has 5 fields,
Field1: Position 1 to 3(Primary Key)
Field2: Position 3 to 6
Field3: Position 7 to 9
Field4: Position 10 to 17
Field5: Position 18 to 20
I am trying to Sum two fields on the input file based on the Primary Key.
//SORTIN   DD  *                          
CDE00010020170831                        
CDE100000             ABC                      
CDE00010020170831                        
CDE100000             ABC                      
/*                                        
//SORTOUT  DD  SYSOUT=*                  
//SYSIN    DD  *                          
  SORT FIELDS=(1,3,CH,A)        
  SUM FIELDS=(4,3,ZD,7,3,ZD)              
/*        
 

Actual Result:
CDE20020020170831    

Expeced Result:
CDE20020020170831ABC


My expectation is when Value for a particular field is empty, take the value from next record. Can this be achieved using SORT?

Thank You.

Re: sumfields on two fields

PostPosted: Wed Sep 06, 2017 7:39 pm
by Aki88
Hello,

You're getting the output as below, because *SORT retains the first record as the base, and sums the remaining records into this record on the keys specified in the 'SORT FIELDS' keyword:


CDE20020020170831
 


Before we move to the solution, can you please let us know the expected output in case the input looks as below.
Note that I've shuffled the order of records slightly; but it still remains in-line with your original requirement.


//SORTIN   DD  *                          
CDE00010020170831                        
CDE100000             CDE                    
CDE00010020170831                        
CDE100000             ABC                      
CDE00010020170831                        
CDE100000             ABC                    
CDE00010020170831                        
CDE100000             CDE                      
/*          
 

Re: sumfields on two fields

PostPosted: Wed Sep 06, 2017 8:13 pm
by Sunindia
@Aki88, Thanks for the response.
Expected result:
CDE20020020170831ABC
CDE20020020170831CDE

Re: sumfields on two fields

PostPosted: Wed Sep 06, 2017 8:21 pm
by Aki88
Hello,

Umm, the expected output in this case might be incorrect if we go by the original post's expectation.
Can you please explain the logic on how this output was deduced; once you do the maths, you'll see the rationale behind my first statement.

Once we have this part figured out, then in solution, ICETOOL's extended operators such as FIRST, LAST etc. can be employed; or a logic can be built in DFSORT to achieve what you want.