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: 
anisha_bafna
Product and Topic Expert
Product and Topic Expert
1,147

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:

 

 

TYPES: BEGIN OF TY_READ_TEXT,
         NAME   TYPE THEAD-TDNAME,
         STRING TYPE STRING,
       END OF TY_READ_TEXT.
DATA: IT_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.
  CLEAR: WA_READ_TEXT.
  LV_NAME = LS_VBRKP-VBELN.
  READ TABLE IT_READ_TEXT INTO WA_READ_TEXT WITH KEY NAME = LV_NAME.
  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.

7 Comments
neerajandrew
Associate
Associate
0 Kudos

 

Great job on your blog post! 

JimSpath
Active Contributor

The code samples are hard to read. Here is what it looks like on my browser:

JimSpath_0-1723235832199.png

Can you review this post and see if it helps?

https://community.sap.com/t5/questions-about-sap-websites/how-to-post-code-in-sap-community-gt-2024/...

ABAP style:

# COMMENT

LOOP AT GT_VBRKP INTO LS_VBRKP.  
CLEAR: WA_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 ...
anisha_bafna
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

 

I have updated this now. Thank You.

 

Best Regards,

Anisha

matt
Active Contributor

You've defined 

DATA: IT_READ_TEXT TYPE SORTED TABLE OF TY_READ_TEXT WITH UNIQUE KEY ID NAME

so you don't need to use BINARY SEARCH when reading.

In fact a further optimisation would be to defined it as a HASHED table, since it's got a unique key.

Also, you've posted this in discussions - it should be in blog posts.

anisha_bafna
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Matt,

 

Thank You for letting me know this. Any idea how do I delete this post now?

BR,

Anisha

Sandra_Rossi
Active Contributor

It's in the blog posts.

Sandra_Rossi_0-1723462235111.png

NB: I don't understand the goal of this post, why is there a need to talk about STXH or READ_TEXT specifically.

In all situations, if a program repeats one exact same task which is slow, this task should be executed once and its result stored for reuse (more memory used but higher performance).

NTeunckens
Active Contributor

You could also consider Using FM "READ_TEXT_MULTIPLE" instead of "READ_TEXT" for greater performance (if it matches your requirements). See SAP-KBA "2261311 - Function module for reading multiple SAPscript texts - SAP for Me".

If that would fail, you might want to check some older Posts as alternatives : Solved: Mass reading standard texts (STXH, STXL) - SAP Community / Alternative to READ_TEXT Function Module (No more ... - SAP Community

Kind regards

Nic T.

 

Labels in this area