Alternative to READ_TEXT Function Module

Alternative to READ_TEXT Function Module

  1. Output+Long+Text

Hello everyone!

 

This one is for all of those and me too. Most of the posts I have seen on SDN where people asking for alternative READ_TEXT alternative fuvtion module for read_text | SCN or mass usage of READ_TEXT. Some good or better developers – I must say – are worried about performance issues. Few newbies are still looking for the usage of READ_TEXT. Lol. FM – READ_TEXT issue with data declaration | SCN

 

I was also looking for some alternate solution but all in vain. I found one good wiki about the usage of the FM:Function Example READ_TEXT ABAP wrapper function – Enterprise Information Management – SCN Wiki. This one is great but obviously I have two main concerns. 1. Performance, 2. Mass usage of reading long text of any object. There is another way to achieve mass read of long text by looping the READ_TEXT (lol, that’s funny), I don’t need this either because I need performance. I don’t want Basis guys cursing me! 

 

So, what I came with was to avoid READ_TEXT, now the question is HOW? You might think of a big NO! Not possible! But remember

 

Lots of time people say no when they don’t know.

 

Let me assure you one thing I have done this and it is ready working like a charm.

 

All you need to do is just fetch the data, first from STXH then from the line item table STXL. Only question left is how to decompress the long text? Well, that’s pretty easy and not a big deal all you need is the use of IMPORT statement.

 

Now let’s see what we have to and how to do it? Below is the code that’s is working 4 to 5 times faster than READ_TEXT performance and is as simple as anything!

 

  1. *&———————————————————————*
  2. *& Report  ZMA_READ_TEXT
  3. *&
  4. *&———————————————————————*
  5. *&
  6. *&
  7. *&———————————————————————*
  8. REPORT  ZMA_READ_TEXT.
  9. TYPES: BEGIN OF TY_STXL,
  10.           TDNAME TYPE STXL-TDNAME,
  11.           CLUSTR TYPE STXL-CLUSTR,
  12.           CLUSTD TYPE STXL-CLUSTD,
  13.         END OF TY_STXL.
  14. DATA:  T_STXL TYPE STANDARD TABLE OF TY_STXL.
  15. FIELD-SYMBOLS: <STXL> TYPE TY_STXL.
  16. * compressed text data without text name
  17. TYPES: BEGIN OF TY_STXL_RAW,
  18.           CLUSTR TYPE STXL-CLUSTR,
  19.           CLUSTD TYPE STXL-CLUSTD,
  20.         END OF TY_STXL_RAW.
  21. DATA:  T_STXL_RAW TYPE STANDARD TABLE OF TY_STXL_RAW.
  22. DATA:  W_STXL_RAW TYPE TY_STXL_RAW.
  23. * decompressed text
  24. DATA:  T_TLINE TYPE STANDARD TABLE OF TLINE.
  25. FIELD-SYMBOLS: <TLINE> TYPE TLINE.
  26. DATA: T_STXH TYPE STANDARD TABLE OF STXH,
  27.        W_STXH TYPE STXH.
  28. SELECT TDNAME TDOBJECT TDID
  29.    FROM STXH
  30.      INTO CORRESPONDING FIELDS OF TABLE T_STXH.
  31. *AND THEN
  32. * select compressed text lines in blocks of 3000 (adjustable)
  33. SELECT TDNAME CLUSTR CLUSTD
  34.         INTO TABLE T_STXL
  35.         FROM STXL
  36.         PACKAGE SIZE 3000
  37.         FOR ALL ENTRIES IN T_STXH “WITH APPLICATION DATA AND TDNAME
  38.         WHERE RELID    = ‘TX’          “standard text
  39.           AND TDOBJECT = T_STXH-TDOBJECT
  40.           AND TDNAME   = T_STXH-TDNAME
  41.           AND TDID     = T_STXH-TDID
  42.           AND TDSPRAS  = SY-LANGU.
  43.    LOOP AT T_STXL ASSIGNING <STXL>.
  44. *   decompress text
  45.      CLEAR: T_STXL_RAW
    [], T_TLINE[].
  46.      W_STXL_RAW-CLUSTR = <STXL>-CLUSTR.
  47.      W_STXL_RAW-CLUSTD = <STXL>-CLUSTD.
  48.      APPEND W_STXL_RAW TO T_STXL_RAW.
  49.      IMPORT TLINE = T_TLINE FROM INTERNAL TABLE T_STXL_RAW.
  50. *  access text lines for further processing
  51.      LOOP AT T_TLINE ASSIGNING <TLINE>.
  52.        WRITE: / <TLINE>-TDLINE.
  53.      ENDLOOP.
  54.    ENDLOOP.
  55.    FREE T_STXL.
  56. ENDSELECT.

Here is the output: I have not restricted it to any object (obviously you can do it for your need) and boy it pulls more then 1300 records within a nano second!

Boom!!

 

Output Long Text.png

 

There is another Function Module to fetch multiple texts: RETRIEVAL_MULTIPLE_TEXTS but I haven’t used it. 

 

Now the last thing, I want to thank Mr. Julian Phillips and Mr. Thomas Zloch. Thankful to Julian because he posted and Thomas gave the solution. Same solution I implemented with some additions. Here is the post I referred to: Mass reading standard texts (STXH, STXL)

 

I hope you will reuse this code to fetch multiple long text and your comments, suggestions and complaints are welcome! 

 

http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module

2017-08-15T07:30:28+00:00