user3885073
user3885073

Reputation: 29

Adding amounts present in the character format

I have a PS with LRECL = 500 and RECFM=FB and in positions 70 through 82, I have the below amount fields in character format.

  -000000042.99
  -000000001.50
  -000000003.00
  -000000001.50
  -000000042.99
  +000000025.00
  +000000019.52
  +000000058.36

How can I convert this to Packed Decimal? My intention is I need to sum up the amounts field.Any ideas?

We have DFSORT. These amount fields are not in Packed decimal or numeric format. This file comes from an external system and I would like to sum all the amounts in this file through a JCL. I have to know the amount. For obvious reasons I do not wish to export this file to an excel and find the total there. I do not want to sum the totals based on a key. I just want to sum all the amounts in that file in that column.

Upvotes: 1

Views: 3418

Answers (2)

Bill Woodger
Bill Woodger

Reputation: 13076

It is a simple task using OUTFIL and its reporting functions:

//TOTALREP EXEC PGM=SORT 
//SYSOUT   DD SYSOUT=* 
//SORTOUT  DD SYSOUT=* 
//SYSIN    DD * 
  OPTION COPY 

  OUTFIL  REMOVECC, 
          TRAILER1=(TOTAL=(1,13,SFF, 
                            EDIT=(SIIIIIIIIT.TT), 
                            SIGNS=(+,-), 
                            LENGTH=13)) 
//SORTIN   DD * 
-000000042.99 
-000000001.50 
-000000003.00 
-000000001.50 
-000000042.99 
+000000025.00 
+000000019.52 
+000000058.36 

SORTOUT contains:

-000000042.99
-000000001.50
-000000003.00
-000000001.50
-000000042.99
+000000025.00
+000000019.52
+000000058.36
        +3.86

REMOVECC says don't include a printer Control Code, TRAILER1 is actioned at the end of the OUTFIL group, TOTAL (or TOT) says give a total of the position (here 1) length (13) and type (FS) (which you should look up in the DFSORT Application Programming Guide, which, for your version of DFSORT, can be found here: http://www-01.ibm.com/support/docview.wss?uid=isg3T7000080 . The EDIT, SIGNS and LENGTH dictate how the TOTAL value is going to appear.

UFF is Unsighed Free Format - This will strip out all non-numeric digits and process the result

SFF is Signed Free Format - This will strip out all non-numeric digits and process the result based on the presence, anywhere in the field, and that means anywhere, of one or more -If - is located, value will be negative otherwise positive.

FS CSF These two are synonymous and can handle leading signs, but not decimal points. In the original example, the presence of the decimal point caused the number to be treated as only the decimal part. Everything in front of the decimal point was ignored, including the sign.

Upvotes: 0

user3885073
user3885073

Reputation: 29

//SORTA    EXEC PGM=SORT                             
//SYSOUT   DD SYSOUT=*                               
//SORTOUT  DD SYSOUT=*                               
//SYSIN    DD  *                                     
  OPTION COPY                                        
   OUTFIL  REMOVECC,                                 
            TRAILER1=(TOTAL=(1,13,SFF,               
                              EDIT=(SIIIIIIIIT.TT),  
                              SIGNS=(+,-),           
                              LENGTH=13))            
//SORTIN   DD *                                      
-000000010.10                                        
-000000020.20                                        
+000000005.88                                        

Now I am getting the desired output
-000000010.10 
-000000020.20 
+000000005.88 
       -24.42 

Upvotes: 1

Related Questions