Page 1 of 1

Need help about overlay of DFSORT

PostPosted: Thu Jul 18, 2013 12:48 pm
by richiewu
I have a problem about using OVERLAY:

suppose one sequential flat file:
0001 1 +100.70
0002 1 +120.13
0001 2 +600.80
0001 1 +100.20
0002 2 +500.10

I need sort with unique result, if the 6th byte is 1, then change the amount sign as "+", else if 6th byte is 2, then change as "-"

here is my JCL
//SYSIN    DD *                                     
 INREC IFTHEN=(WHEN=INIT,                           
     OVERLAY=(8:8,7,SFF,TO=ZD)),                     
       IFTHEN=(WHEN=(6,1,CH,EQ,C'1'),               
     OVERLAY=(8:7,2,ZD,MUL,-1)),                     
       IFTHEN=(WHEN=(6,1,CH,EQ,C'2'),               
     OVERLAY=(8:7,2,ZD,MUL,1))                       
 SORT FIELDS=(1,6,CH,A)                             
 SUM FIELDS=(8,7,ZD)                                 
 OUTREC OVERLAY=(8:8,7,ZD,EDIT=(SIIT.TT),SIGNS=(+,-))
/*                                                   


But got abend, how to use OVERLAY to override amount sign?

Thanks,
Ricky

Re: Need help about overlay of DFSORT

PostPosted: Thu Jul 18, 2013 4:48 pm
by NicC
What abend?

Re: Need help about overlay of DFSORT

PostPosted: Thu Jul 18, 2013 11:00 pm
by skolusu
richiewu wrote:I need sort with unique result, if the 6th byte is 1, then change the amount sign as "+", else if 6th byte is 2, then change as "-"


You seem to do the opposite of what you described. As for the abend you need to realize that your INIT statement has already modified the numeric edited item and now the sign on the last byte. Your Next statement is trying to multiply just 2 bytes from position 8 and since you did not have a format/length, DFSORT will create a 16 byte FS(leading spaces and sign at the end) output value from the arithmetic operation. So you need to provide the format and length.

Use the following DFSORT JCL which will give you the desired results. Also you need to remember that you might have an overflow

//STEP0100 EXEC PGM=SORT                                               
//SYSOUT   DD SYSOUT=*                                                 
//SORTIN   DD *                                                       
----+----1----+----2----+----3----+----4----+----5----+----6----+----7-
0001 1 +100.70                                                         
0002 1 +120.13                                                         
0001 2 +600.80                                                         
0001 1 +100.20                                                         
0002 2 +500.10                                                         
//SORTOUT  DD SYSOUT=*                                                 
//SYSIN    DD *                                                       
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(8:8,7,SFF,TO=ZD)),                 
  IFTHEN=(WHEN=(6,1,CH,EQ,C'2'),OVERLAY=(8:8,7,ZD,MUL,-1,ZD,LENGTH=7))
  SORT FIELDS=(1,6,CH,A)                                               
  SUM FIELDS=(8,7,ZD)                                                 
  OUTREC OVERLAY=(8:8,7,ZD,EDIT=(SIIT.TT),SIGNS=(+,-))                 
//*


The output from this job is
0001 1 +200.90
0001 2 -600.80
0002 1 +120.13
0002 2 -500.10


If that is not what you want you need to explain the rules with a sample of input and desired output.

Re: Need help about overlay of DFSORT

PostPosted: Fri Jul 19, 2013 3:10 pm
by richiewu
skolusu wrote:
richiewu wrote:I need sort with unique result, if the 6th byte is 1, then change the amount sign as "+", else if 6th byte is 2, then change as "-"


You seem to do the opposite of what you described. As for the abend you need to realize that your INIT statement has already modified the numeric edited item and now the sign on the last byte. Your Next statement is trying to multiply just 2 bytes from position 8 and since you did not have a format/length, DFSORT will create a 16 byte FS(leading spaces and sign at the end) output value from the arithmetic operation. So you need to provide the format and length.

Use the following DFSORT JCL which will give you the desired results. Also you need to remember that you might have an overflow



Thanks,

I found the way yesterday:
//SYSIN    DD *                                     
 INREC IFTHEN=(WHEN=INIT,                           
     OVERLAY=(8:8,7,SFF,TO=PD,LENGTH=7)),           
       IFTHEN=(WHEN=(6,1,CH,EQ,C'2'),               
     OVERLAY=(8:8,7,PD,MUL,-1,TO=PD,LENGTH=7))       
 SORT FIELDS=(1,6,CH,A)                             
 SUM FIELDS=(8,7,PD)                                 
 OUTREC OVERLAY=(8:8,7,PD,EDIT=(SIIT.TT),SIGNS=(+,-))
/*                                                   


How can I avoid overflow if the actual data is S9(15)V99 COMP-3?

Re: Need help about overlay of DFSORT

PostPosted: Fri Jul 19, 2013 6:42 pm
by BillyBoyo
If you have 17 decimal digits, your LENGTH= should be 9. If you want to avoid overflow in the SUM, what is the maximum value you expect to have as a total per key? If you want more than five digits on your OUTREC, you need to make the EDIT long enough so that there is an I or a T to represent every digit you want in the output.