Logo2
Progress Bar
[Home] [Code Samples] [Progress Bar]

The RPG to generate a Progress Bar for source files
      //***************************************************************
      //   ___             _    _     __ __             _    _        *
      //  | . > ___  ___ _| |_ | |_  |  \  \ ___  _ _ _| |_ <_>._ _   *
      //  | . \/ . \/ . \ | |  | . | |     |<_> || '_> | |  | || ' |  *
      //  |___/\___/\___/ |_|  |_|_| |_|_|_|<___||_|   |_|  |_||_|_|  *
      //                                                              *
      //  A program to demo a Progress Bar.                           *
      //                                                              *
      //  11/2012                                 booth@martinvt.com  *
      //***************************************************************
      // COMMENTS                                                     *
      //              TotalRecs and CurrentRec are the two fields     *
      //              to be changed and populated for your actual     *
      //              operation.                                      *
      //--------------------------------------------------------------*
     FPRGBAR20D cf   e             WorkStn
      //---------------------------------------------------------------
     D TimeStart       s               t   inz(*sys)
     D TimeNow         s               t
     D TimeHMS         s               t   TimFmt(*HMS)
     D TotSecsJob      s              9s 0
     D TotSecsSoFar    s                   like(TotSecsJob)
     D TotSecsLeft     s                   like(TotSecsJob)

     D CurrentRec      s              7s 0
     D TotalRecs       s              7s 0 inz(20000)
     D Pct             s              3s 0

      /FREE
           write FMT01;  // Display the progress bar
       dow CurrentRec < TotalRecs;
         CurrentRec = CurrentRec + 1;
         Pct = CurrentRec * 100 / TotalRecs;  // Get %-done figure.
           if Pct > 3;
           PRGBAR = '  ' +
               %triml(%editc(CurrentRec:'3')) +
               ' records of ' +
               %triml(%editc(TotalRecs:'3')) + ' read. ' +
               %editw(Pct:'   %');
             TotSecsSoFar = %diff(%time(): TimeStart: *S);
             TotSecsJob = TotSecsSoFar / Pct * 100;
             TotSecsLeft = TotSecsJob - TotSecsSoFar;
             TimeHMS = T'00.00.00' + %seconds(TotSecsLeft);
             PRGBAR = %trimr(PRGBAR) + ' ' +
                 %char(TimeHMS) + ' remaining.';
             Pct = Pct * .01 * %size(PRGBAR);   // Set the RI placement
               if Pct = 0;
                 Pct = 1;
               endif;
             %subst(PRGBAR:Pct:1) = x'33'; // 33 = Yellow
             write FMT01;
           endif;
       enddo;
       exfmt FMT01; //Optional: This leaves Progress Bar on screen.
       *inlr = *on; 







The DDS for the screen format

      ****************************************************************
      *   ___             _    _     __ __             _    _        *
      *  | . > ___  ___ _| |_ | |_  |  \  \ ___  _ _ _| |_ <_>._ _   *
      *  | . \/ . \/ . \ | |  | . | |     |<_> || '_> | |  | || ' |  *
      *  |___/\___/\___/ |_|  |_|_| |_|_|_|<___||_|   |_|  |_||_|_|  *
      *                                                              *
      *  A display screen for a Progress Bar program.                *
      *                                                              *
      *  11/2012                                 booth@martinvt.com  *
      ****************************************************************
                R FMT01
                                            TEXT('A displayable Progress bar')
                                            FRCDTA
                                            OVERLAY
                                            WINDOW(22 2 1 61 *NOMSGLIN)
                  PRGBAR        58   O  1  1DSPATR(RI)
                                            COLOR(GRN)
                  FLASH          1   I   + 1DSPATR(ND)
      *   - Move the distracting flash from the first column of the progress bar.
      *****************************************************************
                R DUMMY
                                            TEXT('Prevents Previous +
                                            screen from being cleared')
                                            ASSUME
                                        5  9' ' 

[Home] [Code Samples] [SQL (simple)] [Subfiles] [Web & .json] [Contact Us] [Other]