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).



bodgerAsked:
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.

daveslaterCommented:
Hi
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
H DFTACTGRP(*NO)

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)


Dave
0

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
daveslaterCommented:
ps
what are you waiting for?
0
odumbruceCommented:
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                                
 /free                                                              
                                                                     
  Rtn = sleep( 60 );                                                
                                                                     
  *inlr = *on;                                                      
 /end-free                                                          
0
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:
Dave

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

I'm using QCMDEXC.

Thanks

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

Dave
0
odumbruceCommented:
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.
0
tliottaCommented:
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.

Tom
0
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.