5 1 1 1 1 1 Rating 100% (12 Votes)
I know that many times showing any progress information isn't something that developer likes to have in his program, especially when it's so fast that progress indicator only slows it down horribly, but often we're putting it into code, when program runtime is quite long ( more than 1 minute) and we want to show the users that program is running and we're currently at step m of n.  Since I remember I was always using SAPGUI_PROGRESS_INDICATOR FM to display such messages on the screen. When used inside loops I often was manually dividing current tabix by selected variable (for example 1000) and if there was no rest from such division then I was running this FM, just to avoid calling this FM to often. The problem of this FM is that when used in background it hasn't show any info in job log. So if you wanted to have also entries in job log, then additional lines with checks if this is foreground or background mode were needed, and if we were in bg mode then messages instead of progress indicator had to be used. 
Now with CL_PROGRESS_INDICATOR class and its method PROGRESS_INDICATE you can forget about all this stuff. Importing parameter I_OUTPUT_IMMEDIATELY determines if message will be putted to screen directly or only once per 10 seconds, which seems to be fair enough. Additionally there is a check inside this method if this is background or foreground mode, and on a base of that messages or SAP_GUI_PROGRESS_INDICATOR is called. 
 
When you'll open this method and look on the import parameters, then you'll notice that you can pass simply any text to it , or you can pass message variables (MSGNO, MSGID, MSGV1, .. etc) so you can also easily use it together with BAPIs and return tables. 
 
I'd say with this method your code can look cleaner than before and for sure it will be shorter.
 
Bellow you can find sample program which shows immediate and delayed output using CL_PROGRESS_INDICATOR

report zab_prog_indicator.

parametersp_times1 type default  15"Immediately
            p_times2 type default  42"Once per 10 seconds


do p_times1 times.

cl_progress_indicator=>progress_indicate(
  exporting
     i_text               Output immediately { sy-index } / { p_times1 } |
*    i_msgid              = i_msgid    " Message Class (If I_TEXT is not transferred)
*    i_msgno              = i_msgno    " Message Number (If I_TEXT is not transferred)
*    i_msgv1              = i_msgv1    " Message Variable (Maximum of 50 Characters)
*    i_msgv2              = i_msgv2    " Message Variable (Maximum of 50 Characters)
*    i_msgv3              = i_msgv3    " Message Variable (Maximum of 50 Characters)
*    i_msgv4              = i_msgv4    " Message Variable (Maximum of 50 Characters)
    i_processed          sy-index    " Number of Objects Already Processed
    i_total              p_times1    " Total Number of Objects to Be Processed
    i_output_immediately abap_true    " X = Display Progress Immediately
*  importing
*    e_progress_sent      = e_progress_sent    " X = Progress Information Was Displayed
).
    wait up to seconds.

enddo.

do p_times2 times.

cl_progress_indicator=>progress_indicate(
  exporting
     i_text               Output once per 10 seconds { sy-index } / { p_times2 } |
*    i_msgid              = i_msgid    " Message Class (If I_TEXT is not transferred)
*    i_msgno              = i_msgno    " Message Number (If I_TEXT is not transferred)
*    i_msgv1              = i_msgv1    " Message Variable (Maximum of 50 Characters)
*    i_msgv2              = i_msgv2    " Message Variable (Maximum of 50 Characters)
*    i_msgv3              = i_msgv3    " Message Variable (Maximum of 50 Characters)
*    i_msgv4              = i_msgv4    " Message Variable (Maximum of 50 Characters)
    i_processed          sy-index    " Number of Objects Already Processed
    i_total              p_times2    " Total Number of Objects to Be Processed
    i_output_immediately abap_false    " X = Display Progress Immediately
*  importing
*    e_progress_sent      = e_progress_sent    " X = Progress Information Was Displayed
).

   wait up to seconds.
enddo.

Have fun!

ABAP Favorites Eclipse plugin

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client