RPG Timed Wait or Delay Function

Posted on 2004-11-30
Last Modified: 2010-10-05
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).

Question by:bodger
    LVL 14

    Accepted Solution

    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)

    LVL 14

    Expert Comment

    what are you waiting for?
    LVL 1

    Expert Comment

    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;                                                      

    Author Comment


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

    Author Comment


    I'm using QCMDEXC.


    LVL 14

    Expert Comment

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

    LVL 1

    Expert Comment

    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.
    LVL 26

    Expert Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now