Page 1 of 2

apend last record in input file with the sum of two fields

PostPosted: Wed Sep 28, 2016 10:39 am
by arya_starc
Hi All,

My requirement is that I need to append one record in the output file in which the first five characters is "total" word and in other fields the sum of two fields from the input file.

EG:-
THIS IS MY INPUT FILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
23/03/2016  10  34   /*FILE 1*/
24/04/2016  20  56   /*FILE 2*/
26/08/2016  30  85   /*FILE 3*/
.
.
.
.
.
 


AND I NEED OUTPUT FILE LIKE THIS

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
23/03/2016  10  34   /*FILE 1*/
24/04/2016  20  56   /*FILE 2*/
26/08/2016  30  85   /*FILE 3*/
.
.
.
.
.
TOTAL        60   175
 

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 11:52 am
by enrico-sorichetti
have You searched the forum ?
the issue has been discussed gazillions of times.

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 12:11 pm
by Aki88
Hello,

Look for OUTFIL --> TRAILER1 --> TOT

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 3:36 pm
by arya_starc
enrico-sorichetti wrote:have You searched the forum ?
the issue has been discussed gazillions of times.

hi enrico

I searched in forum..but not getting the correct post
dfsort-icetool-icegener/sum-fields-t120.html#p471
this I see but still not able to get.

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 3:52 pm
by arya_starc
Aki88 wrote:Hello,

Look for OUTFIL --> TRAILER1 --> TOT


while using trailer and outfil I an getting max cc 16
but I used with outrec and overlay

 SORT FIELDS=(1,2,ZD,A)                                          
 SUM FIELDS=(11,9,ZD,20,15,ZD)                                    
 OUTREC OVERLAY=(1:C'TOTAL',5X,                                  
                 (11,9,ZD),                                      
                 EDIT=(I,III,III),                                
                 (20,16,ZD),                                      
                 EDIT=(I,II,III,III,III))                        
*                                                                

 


but getting output as single record only

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 3:57 pm
by NicC
I do not see OUTFIL or TRAILER in that last post. Did you consult the manual or just copy an example and changed it with your own syntax?

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 4:13 pm
by Aki88
Hello,

arya_starc wrote:...but getting output as single record only


'SUM FIELDS' does precisely that (and more) - it sums the fields and produces unique records basis the SORT key specified in 'SORT FIELDS' statement.

A quote from the DFSORT programming guide; have highlighted the relevant portion:

The SUM control statement specifies that, whenever two records are found with
equal sort or merge control fields, the contents of their summary fields are to be
added, the sum is to be placed in one of the records, and the other record is to be
deleted
.


Since you have not shown what you had tried for OUTFIL/TRAILER1, it is difficult to recommend a correction for the RC- 16.

A hint:
a. Code a SORT FIELDS=COPY --> since you do not want records to be sorted, instead you just want a new summation record added
b. Use a simple OUTFIL REMOVECC, BUILD --> OUTFIL, to process output records prior getting written to outpit DS; REMOVECC, to remove carriage control character which will be inserted while using TRAILER1 reporting feature; BUILD to build the actual output
c. Couple this with TRAILER1 operator of OUTFIL, and TOTAL or TOT sub-operator of TRAILER1

Have a look at DFSORT Application Programming Guide for detailed description of these operators.
If you're looking for a quick code snippet, search the aforementioned operators, there are hundreds of working examples for this.

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 6:26 pm
by arya_starc
hi aki88,

I used below syntax

 SORT FIELDS=COPY                                              
  OUTFIL REMOVECC,BUILD=(1:1,35),                              
  TRAILER1(1:1C'TOTAL',                                        
          10:TOT=(11,9,ZD),                                    
          20:TOT(20,16,ZD))      
                             

but it reporting this error

                    20:TOT(20,16,ZD))                                          
                    $                                                          
ICE223A F REPORT FIELD ERROR                                                    
ICE751I 0 C5-I21470 C6-BASE   C7-K96411 C8-I25275 E7-I22412                    
 

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 6:28 pm
by arya_starc
NicC wrote:I do not see OUTFIL or TRAILER in that last post. Did you consult the manual or just copy an example and changed it with your own syntax?


000011 //STEP020  EXEC PGM=SORT,COND=(0,NE)                                    
000012 //SYSOUT   DD  SYSOUT=*                                                
000013 //SYSPRINT DD  SYSOUT=*                                                
000014 //SORTIN   DD  DSN=MVPS.AY.TESCO.CLUBPNT.S1.SE,DISP=SHR                
000015 //SORTOUT  DD  DSN=MVPS.AY.TESCO.CLUBPNT.SUMMARY.SE.OUT1,DISP=SHR      
000016 //SYSIN    DD  *                                                        
000017   SORT FIELDS=COPY                                                      
000018   OUTFIL REMOVECC,BUILD=(1:1,35),                                      
000019   TRAILER1(1:1C'TOTAL',                                                
000020           10:TOT=(11,9,ZD),                                            
000021           20:TOT(20,13,ZD))                                            
000022 //**********************************************************************


 


but getting max cc 16 for that

Re: apend last record in input file with the sum of two fiel

PostPosted: Wed Sep 28, 2016 6:32 pm
by NicC
perhaps because 20:TOT( overlaps 10:TOT=