Using the code below you'll be able to do date manipulation in a CL program, and retrieving the system date.
DCL VAR(&SYSDATE) TYPE(*CHAR) LEN(6)
DCL VAR(&YESTERDAY) TYPE(*DEC) LEN(8 0)
DCL VAR(&LILIAN) TYPE(*CHAR) LEN(4)
DCL VAR(&JUNK1) TYPE(*CHAR) LEN(8)
DCL VAR(&JUNK2) TYPE(*CHAR) LEN(23)
DCL VAR(&WDATE) TYPE(*CHAR) LEN(8)
RTVSYSVAL SYSVAL(QDATE) RTNVAL(&SYSDATE)
/* Get local time from system: When this call is +
complete, &LILIAN will contain the number of +
days between today and Oct 14, 1582. */
CALLPRC PRC(CEELOCT) PARM(&LILIAN &JUNK1 &JUNK2 *OMIT)
/* Subtracting 1 from &LILIAN will produce yesterday's date */
CHGVAR VAR(%BIN(&LILIAN)) VALUE(%BIN(&LILIAN) - 1)
/* Convert lillian to yyymmdd date */
CALLPRC PRC(CEEDATE) PARM(&LILIAN 'YYYYMMDD' &WDATE *OMIT)
CHGVAR VAR(&YESTERDAY) VALUE(&WDATE)
Note: CEELOCT and CEEDATE are APIs that exist on the system; you do not need to create them. In essence, what the CL that is supplied does is:
1) Use the CEELOCT API to convert the current date to lillian.
2) Then you add or subtract the number of days you need from the lillian date.
3) Then you use CEEDATE to convert the new lillian date back to the date format that you wish, in this case, we have used YYYYMMDD.
Wednesday, April 16, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment