Page 1 of 1

SORT SUM

Posted: Wed Aug 12, 2009 12:37 pm
by SRI123
I want to sum the amounts that are at position 10,12,ZD. I want to sum all the amounts. And out should contain only the total amount. I tried with the below statement, but I'm not getting the sum, it is only displaying all the records in the output. Please help me.

OPTION COPY
SUM FIELDS=(10,12,ZD)

Posted: Wed Aug 12, 2009 1:30 pm
by arcvns
SRI123,

Welcome to the forums. Try this one.

Code: Select all

//STEP1  EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD DSN = Input  file                          
//SORTOUT  DD DSN = Output file                          
//SYSIN DD *                                             
  OPTION COPY                                            
  OUTFIL REMOVECC,NODETAIL,                              
         TRAILER1=('TOTAL=',TOT=(10,12,ZD,M11,LENGTH=12))

Posted: Wed Aug 12, 2009 3:44 pm
by SRI123
Thank you arcvns for qucik reply. This is working fine. My field declaration is S9(9)V99. So the out put is displaying without decimal. Can I get with decimal out put with sign like +123.45 or -123.45. And does this sysntax is valid for packed data also? for packed I'm not getting correct output. Field declaration is S9(9).

Posted: Wed Aug 12, 2009 4:25 pm
by arcvns
Change your OUTFIL statement like this to display the sign as well. AFAIK s9(9)v99 would occupy only 11 bytes.

Code: Select all

 OPTION COPY                                                        
 OUTFIL REMOVECC,NODETAIL,                                          
 TRAILER1=('TOTAL=',TOT=(10,11,ZD,EDIT=(STTTTTTTTT.TT),SIGNS=(+,-)))

Posted: Wed Aug 12, 2009 4:36 pm
by SRI123
Thank you.
And does this sysntax is valid for packed data also? for packed I'm not getting correct output. Field declaration is S9(9).

Posted: Wed Aug 12, 2009 5:12 pm
by arcvns
SRI123,
And does this sysntax is valid for packed data also?
No, it's NOT. As per your original problem, your input file has ZD data. The solution can vary based on the field format.
for packed I'm not getting correct output
The solution provided was for ZD input. Now what exactly is your field format? Is it ZD? Or PD? What is its length? How does it look like? If possible provide some sample data.

Posted: Wed Aug 12, 2009 5:21 pm
by SRI123
FIELD format is ==> SV99 PD 15 2
data is like this
05
1C

06
5C

Posted: Wed Aug 12, 2009 8:35 pm
by Frank Yaeger
I believe that data is equivalent to a 2-byte PD field starting at position 15 interpreted as a sd.dd value.

A total for that value could overflow sd.dd so you would probably want to display it as a larger values, something like sdddd.dd depending on what you want the output value to look like. As an example, you could use these DFSORT statements:

Code: Select all

  OPTION COPY                                                       
  OUTFIL REMOVECC,NODETAIL,                                         
    TRAILER1=('TOTAL=',TOT=(15,2,PD,EDIT=(SIIIT.TT),SIGNS=(+,-)))   

Posted: Thu Aug 13, 2009 10:09 am
by SRI123
Thank you Frank

Topic deleted by Admin

Posted: Mon Jan 25, 2016 10:27 pm
by academyindia4
<< Content deleted By Admin >>