RPG Timed Wait or Delay Function

Can anyone suggest a better way than that shown below to implement a Timed Wait in RPG?

     C                     TIME           TIMEA   60
     C                     Z-ADDTIMEA     TIMEB   60
     C           TIMEA     DOWEQTIMEB              
     C                     TIME           TIMEB    
     C                     ENDDO

My concern with a delay as implemented above is that it is very processor intensive. Unless the job as a whole were assigned a very low priority it could all but freeze the system and were the delay to be larger than 1 second, say 1 minute, then the freeze could become a nuisance to other users.

In the particular assignment which needs this delay function, it cannot be achieved outside the RPG program, so a CL wait is of no use unless it is part of a separately threaded CLP which sends timed messages to the RPG program (in which case the question becomes one of how to wait for a message within an RPG program).

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

2 Solutions
A) Use QCMDEXC to issue the dlyjob cl statement
b) use the QC2LE sleep procedure
there is also Usleep that works down to a millisecond

D sleep           PR            10I 0 extproc('sleep')
D   seconds                     10U 0 value

D usleep          PR            10I 0 extproc('usleep')
D   Miliseconds                 10U 0 value

c                   callp     sleep(10)
c                   callp     usleep(1000)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
what are you waiting for?
You can also add error reporting to this api
H Option(*SrcStmt : *NoDebugIO)                                      
H Dftactgrp( *No )                                                  
H Actgrp( *Caller )                                                  
H Bnddir( 'QC2LE')                                                  
D sleep           PR             5u 0 EXTPROC(*cnowiden:'sleep')    
D  p_sec                         5u 0 Value                          
D Sec             s              5u 0                                
D Rtn             s              5u 0                                
  Rtn = sleep( 60 );                                                
  *inlr = *on;                                                      
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

bodgerAuthor Commented:

Regarding your question. I have an output-only status display, at a keyboardless terminal, which must be periodically updated.
bodgerAuthor Commented:

I'm using QCMDEXC.


why don't you use a dataq. The dataq can autiomaticaly update the display when an entry is received. No waiting.

I agree with dave on that one. That is how the displays work at airports that use a as400.  Flight information hits a dataq that then triggers a display which will update and wait for the next event.
AFAIK, the dtaq is attached to the display file and the program then waits for an entry to appear on the data queue. (See CRTDSPF DTAQ().)  When a user presses <Enter> or some other AID-generating key, that's when the data queue entry is created.

This way, the program logic is driven by the data queue rather than by the display file. Instead of the program delaying during an EXFMT statement, the program simply does a WRITE and the calls the data queue API. Essentially all other logic is the same.

When the API is called, a wait-time is specified. If no entry appears within the wait-time, the API returns an indication that there was no entry available; and the program then continues on to output the next refresh and wait again.

Note that one side effect is that entries can be written to the data queue by external programs in order to cause a refresh-on-demand. Also note that there is no user required -- if no keys are pressed for the display file, then the API stills returns once the time limit passes.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.