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; |