How To Get System Date In Cl Program

I need to get the last day of the previous month. So this CL can run on a 3rd day of the new month.Can I do a Select statement in the CL (we are in 7.1)

  1. How To Get System Date In Python

Re: CL command for timestamp U CAN USE DCL VAR(&VAR) TYPE(*CHAR) LEN(20) RTVSYSVAL SYSVAL(QDATETIME) RTNVAR(&VAR) Here there no need to get Date and time separately and concatenating. QDATETIME -----System date and time. This is the date and time for the local system time as a single value. Hi I wrote this program to retain system date, I am sending it to this forum because someone may need it during the year end. Schedule a job using ADDJOBSCDE command with schedule time 00:00:01 calling this CL program. You would have to use the convert date to convert your date to Julian, add 1 to it, check for leap year and make adjustments and then convert it back.

Or if not what are some steps needed to code and save this date as well in a small table.

user3167167user3167167

3 Answers

Here is a simple example of calculating the last day of the previous month using CL.

jamesallmanjamesallman
How To Get System Date In Cl Program

CL doesn't actually support date data types. So it doesn't support date arithmetic like SQL or RPGLE does.

If all you need to to ensure a job is run on the 3rd of the month, why not use the job scheduler? The basic job scheduler is included with the OS or perhaps you have the Advance Job Scheduler (AJS).

For the basic job scheduler:

FRQ(*MONTHLY) SCDDATE(110315) are the keys to having the job repeat on the 3rd of every month.

If you chose to continue down the path of having the CL determine if it should run or not; I'd suggest an RPGLE procedure that simply returns the day of the month. That way the return value is a simple integer and your CL doesn't have to try to parse the day out of a character or numeric representation of a date.

How To Get System Date In Python

If you need help with that program, post a new question and tag it RPGLE.

CharlesCharles

Technically, it's possible to do a SELECT in CL; but it requires coding to the SQL CLI APIs to do it. Not for the inexperienced and not worth the effort. CL could run an INSERT or UPDATE statement, though, and then use RCVF to retrieve the inserted value. It's far easier to call a module written in RPG, COBOL or C to do SQL. If those languages seem out of reach, then REXX could easily do the SQL and pass the value out to CL.

Without SQL, date math seems best. If you want 'last day' of the current month via CL, it's possibly easiest to set to the 1st day of next-month and subtract '1 day'. The following shows an example using a couple CEE* Date and TIME APIs:

It first sets a date for the 28th of the current month, then adds 4 days. Using those values makes sure that the first calculated date is always inside of 'next month'. It then takes that date and sets the day number to '01'. And from that, it subtracts '1 day'.

The two APIs work with a representation known as 'Lilian day'. That's simply an integer value for the number of days since 14 October 1582. Dates can be converted to a Lilian day number, then simple integer math can add or subtract however many days are wanted. The resulting integer can be converted back to a Date value.

You can specify a 'picture string' to describe the date formats for both the input and output date. I used a 6-char format for the initial input, but a 8-char format for output. You can modify the format however you want. At the end, it simply runs DMPCLPGM to show results. You can set up a PARM() variable to return the result to whatever calls it.

Program

The result in the example code is for LastDay of current month. With a little changing, it can easily be simplified to return 3rd day of next month instead.

I thought about creating a VIEW over SYSIBM.SYSDUMMY1 that expresses LAST_DAY(); but while the VIEW works well in a SELECT statement, it crashed RUNQRY in i 6.1. It didn't seem worthwhile to try to make it work with RCVF for CL.

I also tested adding a dummy job scheduler entry that runs at month-end. Then I used the appropriate API to retrieve NextSubmissionDate from the entry. That worked well enough, but was too obscure to be a good solution. Of course, if the whole purpose is to schedule a job, then simply adding a scheduler entry for it is probably what should be done. Retrieving NextSubmissionDate would simply be a way to get LastDayOfMonth into any CL program.

But if that's the purpose, simply having a CL module that calculates the last day is the most direct way.

How to get system date in sql server
user2338816user2338816

Not the answer you're looking for? Browse other questions tagged ibm-midrangedb2-400rpgle or ask your own question.