Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  ZPROGIND.
TYPES: BEGIN OF T_MARA,
         MATNR LIKE MARA-MATNR,
       END OF T_MARA.
DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA INITIAL SIZE 0,
      WA_MARA TYPE T_MARA.
DATA: MARA_LINES TYPE I,
      GD_PERCENT TYPE I.
************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
  SELECT MATNR
    INTO TABLE IT_MARA
    FROM MARA.
  CHECK SY-SUBRC EQ 0.
  MARA_LINES = SY-DBCNT.
  CLEAR: GD_PERCENT.
  LOOP AT IT_MARA INTO WA_MARA.
    PERFORM PROGRESS_BAR USING 'Retrieving data...'(001)
                               SY-TABIX
                               MARA_LINES.
*    WAIT UP TO 2 SECONDS.
  ENDLOOP.
  WRITE: /20 'Report is "Complete" OK'.
*&---------------------------------------------------------------------*
*&      Form  PROGRESS_BAR
*&---------------------------------------------------------------------*
FORM PROGRESS_BAR USING    P_VALUE
                           P_TABIX
                           P_NLINES.
  DATA: W_TEXT(40),
        W_PERCENTAGE TYPE P,
        W_PERCENT_CHAR(3).
  W_PERCENTAGE = ( P_TABIX / P_NLINES ) * 100.
  W_PERCENT_CHAR = W_PERCENTAGE.
  SHIFT W_PERCENT_CHAR LEFT DELETING LEADING ' '.
  CONCATENATE P_VALUE W_PERCENT_CHAR '% Complete'(002) INTO W_TEXT.
* This check needs to be in otherwise when looping around big tables
* SAP will re-display indicator too many times causing report to run
* very slow. (No need to re-display same percentage anyway)
  IF W_PERCENTAGE GT GD_PERCENT OR P_TABIX EQ 1.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        PERCENTAGE = W_PERCENTAGE
        TEXT       = W_TEXT.
    GD_PERCENT = W_PERCENTAGE.
  ENDIF.
ENDFORM.                    " PROGRESS_BAR

*&---------------------------------------------------------------------*
*& Report  Z_14_PROGRESS
*&
*&---------------------------------------------------------------------*
*&
*& ALTERNATIVE SAMPLE FOR TAW-10 STUDENTS AT SAP ACADEMY
*&
*&---------------------------------------------------------------------*
REPORT  Z_14_PROGRESS.
DATA: IT_SPFLI TYPE STANDARD TABLE OF SPFLI INITIAL SIZE 0,
      WA_SPFLI LIKE LINE OF IT_SPFLI.
DATA: SPFLI_LINES TYPE I,
      GD_PERCENT TYPE I.
************************************************************************
START-OF-SELECTION.
  SELECT *
    INTO TABLE IT_SPFLI
    FROM SPFLI.
  CHECK SY-SUBRC EQ 0.
  SPFLI_LINES = SY-DBCNT.
  CLEAR: GD_PERCENT.
  LOOP AT IT_SPFLI INTO WA_SPFLI.
    PERFORM PROGRESS_BAR USING 'Retrieving data...'(001)
                               SY-TABIX
                               SPFLI_LINES.
*    DELAY FOR EFFECT (DO NOT USE ON PRODUCTION SERVERS IN THIS FORM).
    DO 1000000 TIMES.
      WA_SPFLI-DISTANCE = WA_SPFLI-DISTANCE + 0.
    ENDDO.
  ENDLOOP.
  WRITE: /20 'Report is "Complete" OK'.
*&---------------------------------------------------------------------*
*&      Form  PROGRESS_BAR
*&---------------------------------------------------------------------*
FORM PROGRESS_BAR USING    P_VALUE
                           P_TABIX
                           P_NLINES.
  DATA: W_TEXT(40),
        W_PERCENTAGE TYPE P,
        W_PERCENT_CHAR(3).
  W_PERCENTAGE = ( P_TABIX / P_NLINES ) * 100.
  W_PERCENT_CHAR = W_PERCENTAGE.
  SHIFT W_PERCENT_CHAR LEFT DELETING LEADING ' '.
  CONCATENATE P_VALUE W_PERCENT_CHAR '% Complete'(002) INTO W_TEXT.
* This check needs to be in otherwise when looping around big tables
* SAP will re-display indicator too many times causing report to run
* very slow. (No need to re-display same percentage anyway)
  IF W_PERCENTAGE GT GD_PERCENT OR P_TABIX EQ 1.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        PERCENTAGE = W_PERCENTAGE
        TEXT       = W_TEXT.
    GD_PERCENT = W_PERCENTAGE.
  ENDIF.
ENDFORM.                    " PROGRESS_BAR

2 Comments

  1. Former Member

    Good Job.

    Implemented this in my program.

  2. I used in my program. However I moved the definition of GD_PERCENT into the FORM PROGRESS_BAR.

    FORM progress_bar USING    p_value
                               p_tabix
                               p_nlines.
      STATICSgd_percent TYPE i.
      DATAw_text(40),

    ...


    I just prefer to declare variables within the same processing block. If you stick to a global variable you should change the interface of the form like this. (ABAP is like early BASIC. The global visibility of variables isboth a blessing and a curse

    FORM progress_bar USING    p_value
                               p_tabix
                               p_nlines

                                CHANGING gd_percent.
      DATAw_text(40),