Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
bharatbajaj
Active Participant
Hello Guys,

Hope you are doing well.

Recently I came across a requirement, when I had to execute a Z program in foreground, which is supposed to run for 3-4 Hours.

Now, you might wonder why would the user run a program for so long in foreground and gaze his eyes on the screen, and not schedule a batch job instead.

Well, this was one of such case, where I had to upload an huge MS access file (which contains multiple tables) using the OLE function in SAP, and apparently the OLE functions works only in the foreground.

Although, as and alternative, I could have uploaded the data files in app server and read the data from there in background, but then I felt the urge to find something for the forground as well.

After some research, I came across this very common yet a Magical FM : SAPGUI_PROGRESS_INDICATOR, which did the whole trick.

Yes, we all frequently use this FM to show the progress bar during a program execution, but probably didn't know that this FM resets the runtime value to Zero.

Below is the piece of code that I had implemented in my program, which you can utilize as well.
**This is just a sample code for illustration purpose.

REPORT ZTEST_NO_TIMEOUT.

START-OF-SELECTION.
PERFORM process_main.

FORM process_main.

DATA : l_tab_data TYPE STANDARD TABLE OF g_typ_data,
l_wa_data LIKE LINE OF l_tab_data,
l_var_total TYPE i,
l_var_count TYPE i,
l_var_limit TYPE i VALUE '500'. " Interval for timer reset

**Get the Total number of records
DESCRIBE TABLE l_tab_data LINES l_var_total.

LOOP AT l_tab_data into l_wa_data.
**Increment the counter
l_var_count = l_var_count + 1.
*{
*Do somthing
*}

**Reset the timer at the inerval
PERFORM check_and_reset_timer USING l_var_total
l_var_count
l_var_limit.
ENDLOOP.

ENDFORM.

FORM check_and_reset_timer USING i_var_total TYPE i
i_var_count TYPE i
i_var_limit TYPE i.
DATA : l_var_mod TYPE i,
l_var_perc TYPE i,
l_var_msg TYPE bapi_msg.

l_var_mod = i_var_count MOD i_var_limit.

IF l_var_mod = 0.
l_var_perc = ( i_var_count * 100 ) / i_var_total.

** &1 of &2 Records Processed....
MESSAGE i002 WITH i_var_count i_var_total INTO l_var_msg.
CONDENSE l_var_msg.

PERFORM progress_indicator USING l_var_perc l_var_msg.
ENDIF.

ENDFORM.


FORM progress_indicator USING i_var_percent
i_var_text.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = i_var_percent
text = i_var_text
EXCEPTIONS
OTHERS = 1.

ENDFORM.

Hope this code will help you in simiar development for your project.

 

PS :  If you already knew about this, that's wonderful. But If you didn't, you can thank me 😉

 

Regards,

Bharat Bajaj
11 Comments