Alternative to READ_TEXT Function Module (No more FM needed)

作者:郑德鼎 约 3 分钟阅读 更新日期:2024-02-22 2 年前更新 标签:ABAP, Basis, Data Engineering, SD, 开发, 数据工程, 系统管理, 销售分销

Former Member

February 25, 2014 3 minute read

Alternative to READ_TEXT Function Module (No more FM needed)

554289,736

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!

*&---------------------------------------------------------------------*

*& Report ZMA_READ_TEXT

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT ZMA_READ_TEXT.
TYPES: BEGIN OF TY_STXL,

TDNAME TYPE STXL-TDNAME,

CLUSTR TYPE STXL-CLUSTR,

CLUSTD TYPE STXL-CLUSTD,

END OF TY_STXL.
DATA: T_STXL TYPE STANDARD TABLE OF TY_STXL.

FIELD-SYMBOLS: <STXL> TYPE TY_STXL.

• compressed text data without text name

TYPES: BEGIN OF TY_STXL_RAW,

CLUSTR TYPE STXL-CLUSTR,

CLUSTD TYPE STXL-CLUSTD,

END OF TY_STXL_RAW.
DATA: T_STXL_RAW TYPE STANDARD TABLE OF TY_STXL_RAW.
DATA: W_STXL_RAW TYPE TY_STXL_RAW.

• decompressed text

DATA: T_TLINE TYPE STANDARD TABLE OF TLINE.

FIELD-SYMBOLS: <TLINE> TYPE TLINE.

DATA: T_STXH TYPE STANDARD TABLE OF STXH,

W_STXH TYPE STXH.

SELECT TDNAME TDOBJECT TDID

FROM STXH

INTO CORRESPONDING FIELDS OF TABLE T_STXH.

*AND THEN

• select compressed text lines in blocks of 3000 (adjustable)

SELECT TDNAME CLUSTR CLUSTD

INTO TABLE T_STXL

FROM STXL

PACKAGE SIZE 3000

FOR ALL ENTRIES IN T_STXH "WITH APPLICATION DATA AND TDNAME

WHERE RELID = 'TX' "standard text

AND TDOBJECT = T_STXH-TDOBJECT

AND TDNAME = T_STXH-TDNAME

AND TDID = T_STXH-TDID

AND TDSPRAS = SY-LANGU.

LOOP AT T_STXL ASSIGNING <STXL>.

• decompress text

CLEAR: T_STXL_RAW[], T_TLINE[].

W_STXL_RAW-CLUSTR = <STXL>-CLUSTR.

W_STXL_RAW-CLUSTD = <STXL>-CLUSTD.

APPEND W_STXL_RAW TO T_STXL_RAW.

IMPORT TLINE = T_TLINE FROM INTERNAL TABLE T_STXL_RAW.

• access text lines for further processing

LOOP AT T_TLINE ASSIGNING <TLINE>.
WRITE: / <TLINE>-TDLINE.
ENDLOOP.
ENDLOOP.

FREE T_STXL.

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!!

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!

Note: Sourcecode attached!

郑德鼎

关于作者:郑德鼎

企业信息化与 SAP 技术顾问,长期专注 SAP ABAP、FI/CO、MM、SD 等模块的技术分享与实战经验总结。查看更多介绍

来源说明:本文内容由「Alternative to READ_TEXT Function Module (No more FM needed).docx」整理生成,仅用于内部技术分享与学习交流。