Hi Tim,

> I want to select all records from file VINLOG where IJDATE is 6 months ago
> or later and IJTYPE is 1D, then insert them into QTEMP/CSDS. IJDATE format
> is ccyymmdd (ex. 20041028)

I usually prefer to do my date calcs based on a number of days instead of
a number of months. That way, the time period is consistent!  If I say
"182 days" it's always the same length of time.  Whereas "6 months" will
be different depending on which months they happen to be.

That being the case, I prefer to use the ILE CEE APIs to do date math in
CL.  What these APIs do is convert a date to a number of days since a
given date, long ago.  (Oct 14, 1582)

That way, you can add or subtract from that date number, and convert it
back.

Here's a sample:

PGM

    DCL VAR(&LILIAN) TYPE(*CHAR) LEN(4)
    DCL VAR(&JUNK1)  TYPE(*CHAR) LEN(8)
    DCL VAR(&JUNK2)  TYPE(*CHAR) LEN(23)
    DCL VAR(&DATE)   TYPE(*CHAR) LEN(8)


    /* get current date (CEELOCT) and subtract 183 days from it +
       (183 days is APPROX 6-months) then convert to YYYYMMDD */

    CALLPRC PRC(CEELOCT) PARM(&LILIAN &JUNK1 &JUNK2 *OMIT)
    CHGVAR VAR(%BIN(&LILIAN)) VALUE(%BIN(&LILIAN) - 180)
    CALLPRC PRC(CEEDATE) PARM(&LILIAN 'YYYYMMDD' &DATE *OMIT)


    /* grab records */

    OPNQRYF FILE((VINLOG)) +
            QRYSLT('IJDATE *GE' *BCAT &DATE *BCAT +
                   '*AND IJTYPE *EQ "1D"')

    CPYFRMQRYF FROMOPNID(VINLOG)  +
               TOFILE(QTEMP/CSDS) +
               MBROPT(*ADD)       +
               CRTFILE(*YES)

    CLOF OPNID(VINLOG)

ENDPGM

In order to use those CEE APIs, you should be using ILE CL.  The only
difference between that and the original CL is that in ILE the source
member type is 'CLLE' (instead of CLP) and you compile it with the
CRTBNDCL command instead of the CRTCLPGM command.  (PDM will do that for
you if you change the member type to CLLE)

IF you really do want to do months instead of days, then you could do it
as follows:

PGM

    DCL VAR(&CLOCK)  TYPE(*CHAR) LEN(6)
    DCL VAR(&DATE)   TYPE(*CHAR) LEN(8)
    DCL VAR(&YEAR)   TYPE(*CHAR) LEN(4)
    DCL VAR(&MONTH)  TYPE(*CHAR) LEN(2)
    DCL VAR(&DAY)    TYPE(*CHAR) LEN(2)
    DCL VAR(&YYYY)   TYPE(*DEC)  LEN(4 0)
    DCL VAR(&MM)     TYPE(*DEC)  LEN(2 0)

    /* Routine to retrieve current date and subtract 6 months +
       from it. */

    RTVSYSVAL SYSVAL(QDATE) RTNVAR(&CLOCK)
    CVTDAT DATE(&CLOCK) TOVAR(&DATE) FROMFMT(*SYSVAL) +
             TOFMT(*YYMD) TOSEP(*NONE)

    CHGVAR VAR(&YEAR)  VALUE(%SST(&DATE 1 4))
    CHGVAR VAR(&MONTH) VALUE(%SST(&DATE 5 2))
    CHGVAR VAR(&DAY)   VALUE(%SST(&DATE 7 2))

    CHGVAR VAR(&MM) VALUE(&MONTH)
    CHGVAR VAR(&MM) VALUE(&MM - 6)

    IF (&MM *LT 1) DO
       CHGVAR VAR(&YYYY) VALUE(&YEAR)
       CHGVAR VAR(&YYYY) VALUE(&YYYY - 1)
       CHGVAR VAR(&YEAR) VALUE(&YYYY)
       CHGVAR VAR(&MM)   VALUE(&MM + 12)
    ENDDO

    CHGVAR VAR(&MONTH) VALUE(&MM)
    CHGVAR VAR(&DATE) VALUE(&YEAR *CAT &MONTH *CAT &DAY)

    /* DO OPNQRYF HERE -- SAME AS OTHER EXAMPLE */

ENDPGM


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.