Display remaining time during long-running conversions
When performing pre-validations on data and comparing it against existing data the job tends to run a long time. LSMW by default will indicate the progress of the conversion step after every 500 records, but it doesn't indicate how much longer the task will run. While unnecessary, it is a fun way to plan for coffee breaks.
SAPGUI 7.10 and earlier
SAPGUI 7.20 and after
In addition to the remaining time, this function calls the SAPGUI_PROGRESS_INDICATOR
function and shows a clock with the percentage complete. The code also blocks LSMW from calling the function with its own default progress indication with things like the number of records processed.
In the Global Definitions in the LSMW Maintain Field Mapping and Conversion Rules add this snippet of code. The GetTotalRecords
opens the the source file on the SAP server, reads in all the records in order to count them and then closes it and puts the number in the nTotalRecords
variable. Note: This code will cause an error if added after the Global Definitions section.
data: nTotalRecords type i, nIndex type i. perform GetTotalRecords changing nTotalRecords.
In the BEGIN_OF_TRANSACTION section add this snippet of code. This code increments the nIndex
variable and then calls ZPROGRESSTIME
to update the SAPGui client with the enhanced progress. An index is also a great way to enhance reports created in LSMW during the conversion step.
add 1 to nIndex. perform ZPROGRESSTIME using nIndex nTotalRecords.
Finally, add these two forms to a User Defined Routine or to the FORM_ROUTINES
section of the LSMW Change Field Mapping and Conversion Rules. This is where most of the work is done.
These snippets of code are included in Jimbo's LSMW Toolbox. They are a small part of the free downloadable content from SAPLSMW.com.
form GetTotalRecords changing lvTotalRecords. CALL FUNCTION '/SAPDMC/LSM_FILE_INFO_GET' EXPORTING project = g_project subproj = g_subproj object = g_object IMPORTING file_read = g_dsn_in file_conv = g_dsn_out EXCEPTIONS no_such_object = 1 OTHERS = 2. open dataset g_dsn_in for input in binary mode. while sy-subrc eq 0. READ DATASET g_dsn_in INTO g_hex_record_length. IF sy-subrc eq 0. g_record_length = g_hex_record_length. ASSIGN g_max_buffer(g_record_length) TO <g_buffer>. READ DATASET g_dsn_in INTO <g_buffer>. IF sy-subrc eq 0. gs_buffer = <g_buffer>. g_record = gs_buffer-record. ADD 1 TO lvTotalRecords. ENDIF. ENDIF. endwhile. close dataset g_dsn_in. endform. form ZPROGRESSTIME using lvCurrent lvCount. statics: lvtimlo like sy-timlo, lvstarted like sy-timlo, cRemaining(80) type c, cPercentage(50) type c. data: lvPercentage type f, lvPercent type i, lvcTransferred(50) type c. if cRemaining eq ''. cRemaining = 'X'. lvStarted = sy-timlo. endif. get time. if sy-timlo ne lvtimlo and lvCurrent gt 5 and lvCount gt 0. cRemaining = ( ( sy-timlo - lvstarted ) / lvcurrent ) * ( lvcount - lvcurrent ). cRemaining = cRemaining div 1. condense cRemaining no-gaps. lvPercentage = 100 * lvCurrent / lvCount. lvPercent = lvPercentage. cPercentage = 100 * ( lvCurrent / lvCount ). cPercentage = cPercentage div 1. condense cPercentage no-gaps. concatenate cPercentage '%' into cPercentage. lvcTransferred = g_cnt_records_transferred. lvcTransferred = lvcTransferred div 1. condense lvcTransferred no-gaps. concatenate '[' cPercentage 'complete][ Seconds remaining:' cRemaining '][ Transferred:' lvcTransferred ']' into cRemaining separated by space. call function 'SAPGUI_PROGRESS_INDICATOR' exporting PERCENTAGE = lvPercentage TEXT = cRemaining exceptions others = 1. lvtimlo = sy-timlo. endif. " The following line prevents LSMW from calling the " SAPGUI_PROGRESS_INDICATOR function by setting the " counter to 0; it calls at 500 and sets to 0 again. g_cnt_records_read_progress = 0. endform.