Wednesday, April 16, 2008

Date manipulation in CL:

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.

2 comments:

JoJosho said...

Attention! See Please Here

Celulite said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Celulite, I hope you enjoy. The address is http://eliminando-a-celulite.blogspot.com. A hug.