Robert Munday wrote:
Is there a date testing method which I can use to compare today's
date and the member creation date in CL and find the difference in
months? If so, I could remove the RPG program from the process.
The ILE environment has date capabilities built into it. (via the CEE
APIs). So if you don't mind using ILE CL, this will be relatively easy
to do.
The ILE date & time APIs work based on the notion of "Lilian days". The
Gregorian calendar (which is what's used in most of the world, including
the USA) started on October 14, 1582. A Lilian Day is a count of the
number of days that have elapsed since that date. Since it's just a
count of the number of days since a given point in time, adding and
subtracting from the number equates to adding and subtracting days.
More info about these APIs can be found here:
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/apis/ile4a1TOC.htm
Here's an example, based on my understanding of what you're trying to
do. (It should work on V3R1 and later machines)
PGM
DCL VAR(&FILE) TYPE(*CHAR) LEN(10) VALUE('MYFILE')
DCL VAR(&LASTMBR) TYPE(*CHAR) LEN(10)
DCL VAR(&TODAY) TYPE(*CHAR) LEN(4)
DCL VAR(&NOTUSED1) TYPE(*CHAR) LEN(8)
DCL VAR(&NOTUSED2) TYPE(*CHAR) LEN(23)
DCL VAR(&DATE13) TYPE(*CHAR) LEN(13)
DCL VAR(&DATE8) TYPE(*CHAR) LEN(8)
DCL VAR(&CRTDATE) TYPE(*CHAR) LEN(4)
DCL VAR(&TOOOLD) TYPE(*CHAR) LEN(4)
DCL VAR(&DONE) TYPE(*LGL) VALUE('0')
/********************************************************+
* Calculate what the date was 182 days (1/2 year) ago +
*********************************************************/
CALLPRC PRC(CEELOCT) PARM(&TODAY &NOTUSED1 &NOTUSED2 *OMIT)
CHGVAR VAR(%BIN(&TOOOLD)) VALUE(%BIN(&TODAY) - 182)
/*******************************************************+
* The following code gets the member create date: +
* -- RTVMBRD retrieves the member date. +
* -- CVTDAT converts it to a 4-digit year +
* -- CEEDAYS converts it to lilian days +
*******************************************************/
RTVMBRD FILE(&FILE) CRTDATE(&DATE13) RTNMBR(&LASTMBR)
LOOP: CVTDAT DATE(%SST(&DATE13 1 7)) FROMFMT(*CYMD) +
TOVAR(&DATE8) TOFMT(*YYMD) TOSEP(*NONE)
CALLPRC PRC(CEEDAYS) PARM(&DATE8 'YYYYMMDD' &CRTDATE *OMIT)
/* Check if member date is too old */
IF (&CRTDATE <= &TOOOLD) DO
... RMVM FILE(&FILE) MBR(&LASTMBR), etc ...
ENDDO
RTVMBRD FILE(&FILE) MBR(&LASTMBR *NEXT) +
RTNMBR(&LASTMBR) CRTDATE(&DATE13)
MONMSG MSGID(CPF3049) EXEC(CHGVAR &DONE '1')
IF (*NOT &DONE) DO
GOTO LOOP
ENDDO
ENDPGM
In the preceding code, the CEELOCT API retrieves the current local time
in Lilian format. I subtract 182 days from it (which is approx 6
months) to get the lilian date from 182 days ago.
Then I retrieve the member description of each member in the file and
convert the create date to lilian format (The CEE APIs don't understand
the '0'=1900, '1'=2000 date format, so I use CVTDAT to make it a normal
4-digit year first). Then I can simply compare it to the date from 182
days ago, and if it's older, I can run RMVM, etc.
Remember, the above source is ILE CL. That means the source member type
must be CLLE (not CLP). And if you compile it from the command line,
you have to use the CRTBNDCL command (not CRTCLPGM). (PDM opt 14 will
automatically use CRTBNDCL based on the CLLE member type.)
If the compiler chokes on the CALLPRC commands, that means you tried to
compile it as the original (OPM) CL instead of ILE CL.
As an Amazon Associate we earn from qualifying purchases.