Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Caculate date in CLP

Status
Not open for further replies.

jadec

MIS
Jan 22, 2004
87
0
0
US
Hi Guys,

First Happy Holiday !

I need to run a weekly report. date range is today's date - 7 to today's date - 1. Because I need build query first. So I need to caculate date in cl program. Is any way I can caculate date in cl program?

Thanks !

 
Hi,

Happy Xmas !

To calculate a date range in CL I think that your best bet is to call a RPG IV program %-) from within the CL. In the RPG procedure, use ADDDUR/SUBDUR opcodes or %day() free fonction to return the relevant dates to the CL.
 
An easy way is to call a RPG-IV pgm, canclutate date range, and put date(s) into *LDA. Then CL can use *LDA string as select options. Simple coding and generic.
 
If you must do this within CL, the CL Programming Manual has a sample program calculating dates inside CL.
 
Hi Guys, I found the code in cl. Thanks.

 
The code in CL :

Code:
YESTERDAY:PGM 
  /* DO NOT EXECUTE ON JANUARY, 1  */               

       DCL  VAR(&DATE)      TYPE(*CHAR) LEN(6)              
       DCL  VAR(&YYYYDDD)   TYPE(*CHAR) LEN(7)              
       DCL  VAR(&JULIAN)    TYPE(*DEC) LEN(7)               
                                                                        
  /*  RETRIEVE CURRENT DATE */                              
       RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DATE)                     
 /* CONVERT TO JULIAN DATE FORMAT  */                       
    CVTDAT DATE(&DATE) TOVAR(&YYYYDDD) FROMFMT(*SYSVAL) +  
           TOFMT(*LONGJUL) TOSEP(*NONE)                  
    CHGVAR VAR(&JULIAN) VALUE(&YYYYDDD)                    
 /*  SUBTRACT 1  DAY   */                                   
    CHGVAR VAR(&JULIAN) VALUE(&JULIAN - 1)                 
    CHGVAR VAR(&YYYYDDD) VALUE(&JULIAN)                    
    CVTDAT DATE(&YYYYDDD) TOVAR(&DATE) +                   
         FROMFMT(*LONGJUL) TOFMT(*SYSVAL) TOSEP(*NONE) 
    SNDPGMMSG  MSG('Yesterday = ' *CAT &DATE)          
END: ENDPGM

Thanks!
 
Here's a sample from the IBM CL manual.

/* Calculate new date from current system date. Pass negative */
/* number to subtract, positive number to add */
/* */
/* The first parameter is a character 8 date in YYYYMMDD format */
/* or the special value *CURRENT */
/* */
/* The second parameter is a decimal value for the number of days */
/* to adjust the first parameter by */
/* */
/* Test cases: CALL CALCDATE (*CURRENT -5) */
/* CALL CALCDATE (*CURRENT 5) */
/* CALL CALCDATE (’20030225’ -90) */
/* CALL CALCDATE (’30020228’ 90) */
/* */
/* There is no error handling in this sample, so make sure the */
/* input dates are valid (that is, no 20031325). The valid date */
/* date range is Oct 14 1582 to Dec 31 9999 */
/* */
PGM PARM(&CURDATE &DAYSTOCHG)
DCL VAR(&CURDATE) TYPE(*CHAR) LEN(8)
DCL VAR(&DAYSTOCHG) TYPE(*DEC) LEN(15 5)
DCL VAR(&DATETIME) TYPE(*CHAR) LEN(17)
DCL VAR(&DATE) TYPE(*CHAR) LEN(8)
DCL VAR(&LILDATEINT) TYPE(*CHAR) LEN(4)
DCL VAR(&LILDATEDEC) TYPE(*DEC) LEN(10 0)
DCL VAR(&ERRCOD) TYPE(*CHAR) LEN(4) VALUE(X’00000000’)
DCL VAR(&MSG) TYPE(*CHAR) LEN(50)
IF COND(&CURDATE = ’*CURRENT’) THEN(DO)
CALL PGM(QWCCVTDT) PARM(’*CURRENT’ ’ ’ ’*YYMD’ &DATETIME &ERRCOD) /* Get current +
system date and time in YYYYMMDD */
CHGVAR VAR(&DATE) VALUE(%SST(&DATETIME 1 8)) /* Get just the date portion */
ENDDO
ELSE CMD(CHGVAR VAR(&DATE) VALUE(&CURDATE)) /* Use the date provided */
CALLPRC PRC(CEEDAYS) PARM(&DATE ’YYYYMMDD’ &LILDATEINT *OMIT) /* Get Lilian date for +
current date */
CHGVAR VAR(&LILDATEDEC) VALUE(%BIN(&LILDATEINT)) /* Get Lilian date in decimal format +
*/
CHGVAR VAR(&LILDATEDEC) VALUE(&LILDATEDEC + &DAYSTOCHG) /* Adjust specified number of +
days */
CHGVAR VAR(%BIN(&LILDATEINT)) VALUE(&LILDATEDEC) /* Get Lilian date in integer format +
*/
CALLPRC PRC(CEEDATE) PARM(&LILDATEINT ’YYYYMMDD’ &DATE *OMIT) /* Return calculated +
date in YYYYMMDD format */
CHGVAR VAR(&MSG) VALUE(’THE NEW DATE IS ’ *CAT &DATE)
SNDPGMMSG MSG(&MSG) TOPGMQ(*EXT)
ENDPGM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top