Page 1 of 1

subtract 1 day to a date

PostPosted: Tue Jan 25, 2011 5:33 pm
by javivi
Hi
I can't use the last SUBDAYS function in dfsort because the PTF is not availabe in my installation.
I need to subtract 1 day to a date in a sortin file but I can't do it. I'm trying the next, but the result are wrong.

//SORTIN DD *
20100507
//SORTOUT DD DSN=THEOUT.FILE,DISP=(,CATLG,CATLG),
// DCB=(RECFM=FB,LRECL=25,BLKSIZE=0),
// UNIT=SYSDA,SPACE=(TRK,(1,1),RLSE)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION DYNALLOC=(,12)
SORT FIELDS=COPY
INREC OVERLAY=(40:01,08,Y4T,TOJUL=Y4T)
OUTREC OVERLAY=(50:40,07,ZD,SUB,+1)
OUTFIL BUILD=(01,08,C'*',40,07,C'*',50,7,Y4T,TOGREG=Y4T)
END

This is the result:

20100507*2010127*

Someone can help me?

Thanks.

Re: subtract 1 day to a date

PostPosted: Tue Jan 25, 2011 10:56 pm
by skolusu
Javivi,

You are performing arithmetic on the entire 7 bytes of Julian date which is not correct. You need to perform arithmetic just on DDD portion of the julian date. You also need to take care of January 1st. If the input date is January 1st , you need to subtract 1 from the year. Here is a DFSORT JCL which will give you the desired results

//STEP0100 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD *                                           
20100507                                                 
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                           
  SORT FIELDS=COPY                                       
  INREC IFOUTLEN=25,                                     
  IFTHEN=(WHEN=INIT,OVERLAY=(09:C'*',1,8,Y4T,TOJUL=Y4T,   
          26:10,4,14,3,ZD,SUB,+1,M11,LENGTH=3)),         
  IFTHEN=(WHEN=(30,3,ZD,EQ,0),                           
  OVERLAY=(17:C'*',26,4,ZD,SUB,+1,M11,LENGTH=4,C'1231')),
  IFTHEN=(WHEN=(30,3,ZD,GT,0),                           
  OVERLAY=(17:C'*',26,7,Y4T,TOGREG=Y4T))                 
/*


This will produce the following output

20100507*2010127*20100506