Optimizing Performance of SELECT SINGLE STXH in READ_STXH_INTERNAL

Hi All,

If you’ve noticed that the statement SELECT SINGLE STXH within the method READ_STXH_INTERNAL is causing high execution times, especially with identical executions, this blog is for you.

In this post, I’ll share recommendations on how to enhance the performance of the SELECT SINGLE STXL statement.

When analyzing the execution sequence, you might find that the SELECT SINGLE STXH is executed inside the method CL_RSTX_TABLE_VIEW=>READ_STXH_INTERNAL, which in turn is called by the method CL_RSTX_TABLE_VIEW=>READ_STXH. This method is further invoked within the READ_TEXT function, which often runs inside a loop.

To optimize this process, the key is to reduce the number of calls to the READ_TEXT function. Instead of calling this function repeatedly with the same input parameters, consider executing it only for unique combinations of the exporting fields. The results can then be stored in an internal table, IT_READ_TEXT. If the output for a given set of exporting fields has already been retrieved, it can be fetched directly from this internal table, thereby avoiding redundant calls and significantly improving performance.

Below is an example:

Original Code:

LOOP AT GT_VBRKP INTO LS_VBRKP.

  LV_NAME LS_VBRKP-VBELN.

  CALL FUNCTION 'READ_TEXT'

    EXPORTING

      ID                      '0002'

      LANGUAGE                SY-LANGU

      NAME                    LV_NAME

      OBJECT                  'VBBK'

    TABLES

      LINES                   LT_LINES

    EXCEPTIONS

      ID                      1

      LANGUAGE                2

      NAME                    3

      NOT_FOUND               4

      OBJECT                  5

      REFERENCE_CHECK         6

      WRONG_ACCESS_TO_ARCHIVE 7

      OTHERS                  8.

  LOOP AT LT_LINES INTO LS_LINES.

    CONCATENATE LS_OUTTAB-NOTCAB LS_LINES-TDLINE INTO LS_OUTTAB-NOTCAB.

  ENDLOOP.

ENDLOOP.

Optimized Code:

Declaration:

TYPESBEGIN OF TY_READ_TEXT,

         NAME   TYPE THEAD-TDNAME,

         STRING TYPE STRING,

       END OF TY_READ_TEXT.

DATAIT_READ_TEXT TYPE SORTED TABLE OF TY_READ_TEXT WITH UNIQUE KEY ID NAME,

      WA_READ_TEXT TYPE TY_READ_TEXT.

Replace the original code as follows:

LOOP AT GT_VBRKP INTO LS_VBRKP.

  CLEARWA_READ_TEXT.

  LV_NAME LS_VBRKP-VBELN.

  READ TABLE IT_READ_TEXT INTO WA_READ_TEXT WITH KEY NAME LV_NAME BINARY SEARCH.

  IF SY-SUBRC 0.

    IF NOT WA_READ_TEXT-STRING IS INITIAL.

      LS_OUTTAB-NOTCAB WA_READ_TEXT-STRING.

    ENDIF.

  ELSE.

    CALL FUNCTION 'READ_TEXT'

      EXPORTING

        ID                      '0002'

        LANGUAGE                SY-LANGU

        NAME                    LV_NAME

        OBJECT                  'VBBK'

      TABLES

        LINES                   LT_LINES

      EXCEPTIONS

        ID                      1

        LANGUAGE                2

        NAME                    3

        NOT_FOUND               4

        OBJECT                  5

        REFERENCE_CHECK         6

        WRONG_ACCESS_TO_ARCHIVE 7

        OTHERS                  8.

    IF LT_LINES IS NOT INITIAL.

      LOOP AT LT_LINES INTO LS_LINES.

        CONCATENATE LS_OUTTAB-NOTCAB LS_LINES-TDLINE INTO LS_OUTTAB-NOTCAB.

      ENDLOOP.

      WA_READ_TEXT-STRING LS_OUTTAB-NOTCAB.

      WA_READ_TEXT-NAME LV_NAME.

      INSERT WA_READ_TEXT INTO IT_READ_TEXT.

    ENDIF.

  ENDIF.

ENDLOOP.

For a deeper understanding of the READ_TEXT Function Module, you can refer to the SAP Documentation – READ_TEXT.

Thank you for taking the time to read my blog. As this is my first post, I genuinely appreciate any feedback you may have.

Scroll to Top