Search code examples
openedgeprogress-4gl

Is it possible to provide estimate hrs or minutes for progress completion? - PROGRESS 4GL


I am using below query for progress completion which shows how much percentage is completed in record updating process. My question or doubt here is Is it possible to provide estimated hrs/minutes for this progress completion?

For example, consider a table has 1000 records and each record gets into some validations before updating and approx time is less than a second(milliseconds). So if a single record takes less than a millisecond to update after gets to validations then what will be estimated for 1000 records? How to calculate and convert into hh:mm:ss? Please help to write a sample query.

DEFINE VARIABLE I AS INTEGER NO-UNDO.
DEFINE VARIABLE iPercentage AS INTEGER NO-UNDO.
DEFINE VARIABLE iComp       AS INTEGER NO-UNDO.
DEFINE VARIABLE iRec        AS INTEGER NO-UNDO.

ASSIGN
I     = 0
iComp = 0
iRec  = 0
iPercentage = 0.


/* Calculating Total records*/
FOR EACH <table> NO-LOCK:
  iRec = iRec + 1.
END.
/* Taking each records from the same table to update*/
FOR EACH <table> NO-LOCK:
  I = I + 1.
  
  IF I = 1 THEN DO:
  /*do some more validations*/
    iComp =  iComp  + I.
    iPercentage  = 100 * (iComp / iRec).

    IF iPercentage = 100 THEN DO:
        MESSAGE "Record Updation Is completed".
    END.
    ELSE DO:
        I = 0
        NEXT.
    END.  
 END.

 END.

Solution

  • This variant here relies on NUM-RESULTS as suggested by nwahmaet and uses a DATETIME-TZ Variable and the INTERVAL function to determine the runtime. Output is done only every 1000's iteration so that the display of the Progress does not cause more load than the processing.

    &scoped Table Customer
    
    SESSION:APPL-ALERT-BOXES = FALSE .  
    
    DEFINE VARIABLE I           AS INTEGER NO-UNDO.
    DEFINE VARIABLE iPercentage AS INTEGER NO-UNDO.
    DEFINE VARIABLE iComp       AS INTEGER NO-UNDO.
    DEFINE VARIABLE iRec        AS INTEGER NO-UNDO.
    
    DEFINE VARIABLE dtStart AS DATETIME-TZ NO-UNDO.
    DEFINE VARIABLE iMsecs   AS INTEGER NO-UNDO.
    
    ASSIGN
        I     = 0
        iComp = 0
        iRec  = 0
        iPercentage = 0.
    
    
    DEFINE QUERY qT FOR {&table} .
    OPEN QUERY qT PRESELECT EACH {&Table}.
    iRec = QUERY qT:NUM-RESULTS.   // if you use a FOR you get 0
    
    dtStart = NOW .
    
    /* Taking each records from the same table to update*/
    FOR EACH {&table} NO-LOCK:
        I = I + 1.
    
        IF I MODULO 1000 = 0 THEN DO:
    PAUSE .05 . // simulate some load
    
            /*do some more validations*/
            iComp =  iComp  + I.
            iPercentage  = 100 * (iComp / iRec).
    
            iMsecs = INTERVAL (NOW, dtStart, "milliseconds") .
    
            MESSAGE i "of" iRec "/" iMsecs "/"
    
                    STRING (INTEGER ((iMsecs / (i / iRec)    // iMsecs / % processed = estimated total time
                                    - iMsecs)                // minus time already spent
                                     / 1000),                // msecs to seocnds
    
                            "hh:mm:ss")                      // format output
                   "remaining".
        END.
    END.
    
    MESSAGE "Record Updation Is completed".