How to run a command within a CLP only during a specific time frame

205 pts.
CL Commands
IF statement
I have a pgm that perfroms verious system checks and alerts me if there is a problem. 

I would like to add an If statement to exclude some of the checks that fall between a certain time period and have it jump to a specific lable in the script to continue. thus skipping over the commands that do not need to run during the time frame.

Can someone show me an example and explain the process?


Software/Hardware used:

Answer Wiki

Thanks. We'll let you know when a new response is added.

The first thing you need is the system time. You can retrieve that with the RTVSYSVAL command:<pre>
dcl &QTIME *char 6
rtvsysval QTIME rtnvar( &QTIME )</pre>
The system time will be stored in variable &QTIME.

From there, the basic idea is to compare the value of &QTIME to the starting and ending times of your time range<pre>
dcl &STRTIME *char 6 value( ‘103000’ ) /* 10:30 AM */
dcl &ENDTIME *char 6 value( ‘143000’ ) /* 2:30 PM */

If ( &QTIME *ge &STRTIME *and &QTIME *le &ENDTIME ) do
/* Time range process goes here… */
The system time will be returned as a value from ‘000000’ through ‘235959’. If the retrieved system time is greater than or equal to your starting time, and it’s less than or equal to your ending time, then it’s within the time range that you chose.

At least, that’s the basic idea. There is a twist that needs to be considered — what if your time range starts before midnight and ends after midnight, say, from 10:30 PM to 2:30 AM? Your &STRTIME value would be ‘223000’ and your &ENDTIME value would be ‘023000’.

When the time range crosses midnight, you can’t simply test for greater-than and less-than in the same way. The comparison doesn’t work because the system time goes back to ‘000000’ at midnight. Either the &STRTIME or the &ENDTIME comparison will be wrong. You can tell when the time range crosses midnight because &ENDTIME will be less than &STRTIME.

There are a number of ways to manipulate the values. One way is simply to reverse the logic. When you find &ENDTIME is less than &STRTIME, use negative logic:<pre>
if ( &ENDTIME *lt &STRTIME ) +
if (*not ( &QTIME *gt &ENDTIME *and &QTIME *le &STRTIME )) do
/* Time range process goes here… */
Ask for clarification in the discussion area below.


Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • lotofbad
    Thanks Tom, I will try and go through the process you suggested and see if I understand it as I walk through it all.
    205 pointsBadges:
  • lotofbad
    Tom, I had to wrk the second senerio you gave and it worked great. Question: command ENDTIME *lt &STRTIME ).....what does the *lt stand for.
    205 pointsBadges:
  • philpl1jb
    *lt is less then. So this would be true when the endtime value is less than the start time. As in &Strtime = 2300 and &EndTime = 0100 if (&ENDTIME *lt &STRTIME Phil
    54,090 pointsBadges:
  • TomLiotta
    Comparison operators can be entered as symbols such as "=" or "<", but it's better to use the mnemonics.
    • *LT is Less-Than
    • *GT is Greater-Than
    • *EQ is Equal
    • *LE is Less-Than-Or-Equal
    • *GE is Greater-Than-Or-Equal
    • *AND is And
    • *NOT is Not
    • *CAT is Concatenate
    • *TCAT is Concatenate-With-Truncation
    • *BCAT is Concatenate-With-Single-Blank
    The mnemonics are not case-sensitive. I prefer using lower-case for all language elements because it will emphasizes how the command analyzer interprets commands after I prompt them. When I change a command, I always copy it first, then change the copy. I can see dramatic differences due to the upper-casing by the prompter. Especially with a complex expression involving embedded quotes, I expect to see where all of the mnemonics have been recognized by the prompter. If the change looks correct, I copy/paste just the change back into the original and type over any bits to set letters to lower-case. Tom
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: