Академический Документы
Профессиональный Документы
Культура Документы
| SCN
ABAP Development
Share 1 0 Tw eet 4
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 post onepost
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
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 1/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
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!
01. *&---------------------------------------------------------------------*
02. *& Report ZMA_READ_TEXT
03. *&
04. *&---------------------------------------------------------------------*
05. *&
06. *&
07. *&---------------------------------------------------------------------*
08. REPORT ZMA_READ_TEXT.
09. 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
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 2/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
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!!
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 3/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
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!
ZMA_READ_TEXT.zip(795 bytes)
4115 View s
Topics: abap, database Tags: sap, beginner, sap_developer_netw ork, code_exchange, code, reusability, abap_unit
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 4/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
Average User Rating
(5 ratings)
Share 1 0 Tw eet 4
30 Comments
Hi Mansoor ,
Praveen .
Like (1)
Mansoor Ahmed Feb 25, 2014 2:57 PM (in response to Praveen Nenaw a)
Thanks for the appreciation. Do let me know when you use it. You can also add some filters
to the WHERE clause to restrict your query.
Like (0)
Hi Mansoor,
Nice investigation. Thanks for your kind share about read_text.
Like (1)
Mansoor Ahmed Feb 28, 2014 12:26 PM (in response to YUNUS KALDIRIM)
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 5/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
Hi Mansoor,
Thanks
Bikas
Like (0)
Mansoor Ahmed Feb 26, 2014 4:34 PM (in response to Bikas Tarw ay)
Thanks for the comment. Yes, it does give performance issues when you need to pull
millions of texts at once. Obviosuly, you won't loop READ_TEXT. Hope this makes sense!
Like (0)
Mansoor, very nice explanation. I had read the post you mention Mass reading standard texts
(STXH, STXL) and had success implementing this as well. Now I have another question that some
more skilled ABAP'ers may be able to help with.
With regard to the IMPORT statement, does this work directly on the fields provided to it and convert
this into the text
OR
Does this actually retrieve something else from the database based on the binary types that are
provided, like a mapping technique?
For example, if I have the values in CLUSTR and CLUSTD in any given ABAP system, can I get the
values or do I need to execute this in the source where the STXH/STXL table exists?
My requirement is related to SLT replication, whereas I am trying to convert the values that are
extracted from ECC into SLT with the IMPORT statement. My assumption is that the IMPORT is able
to convert the CLUSTR and CLUSTD values outside of the source system, but now I am not sure.
Maybe the IMPORT statement is just converting the binary location in CLUSTR/CLUSTD and
retrieving from some other location in the system?
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 6/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
Regards,
Justin
Like (0)
Mansoor Ahmed Feb 26, 2014 4:42 PM (in response to Justin Molenaur)
As far as I know, if import is specified in parameter_list from a data cluster, the data is
automatically converted to the current byte sequence (Endian) and character
representation. You can make use of conversion_options to make adaptations to the
current platform.
Justin Molenaur Feb 26, 2014 5:07 PM (in response to Mansoor Ahmed)
Not sure I understood you correctly there, you went over my head a bit with the first
comment.
If I have one single row of STXL, and extract that to another netweaver system, can
I perform the IMPORT there or is there some link that needs to be maintained?
Regards,
Justin
Like (0)
Mansoor Ahmed Feb 27, 2014 8:15 AM (in response to Justin Molenaur)
You can have an addition of Conversion type with import statement. That
should work.
Like (0)
Hi Mansoor,
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 7/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
Only one question, don't you think that use INNER-JOIN instead of FAE in the select would be better
for performance?
Cheers,
Adrián
Like (0)
Mansoor Ahmed Feb 26, 2014 5:16 PM (in response to Adrián Mejido)
Hi Adrian,
There has been a never ending debate to use or not to use FAE. But you can use it and
track it via Performance Analysis tool and check which one gives you better performance.
Thanks.
Like (1)
Gareth Ryan Feb 26, 2014 6:49 PM (in response to Mansoor Ahmed)
And I'm pretty sure in almost all cases, you'll find a join is better than FAE. Have
you tried to make your code even b etter by changing it to use a join?
Like (1)
Mansoor Ahmed Feb 28, 2014 12:25 PM (in response to Gareth Ryan)
Yeah absolutely! That's it! I was just telling Adrián Mejido to check it
and come back to me
Like (1)
Most of the code was taken from my original post, so please allow me to
explain.
In my approach the list of single values for the TDNAME selection does
not come from an STXH selection, but rather from a selection of
application data like BKPF/BSEG, to name an example. Long texts for FI
document items have TDNAME values concatenated from BUKRS,
BELNR, GJAHR and BUZEI. You need to build these TDNAMEs in an
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 8/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
intermediate step before accessing STXL, that's why a direct join is not
possible, and FAE is the next best option.
Thomas
Like (4)
Like (1)
Like (0)
Hello,
I think the code is not entirely correct. It may dump in case a standard text is very long. As you can
see, T_STXL_RAW is always one line before IMPORT ... FROM INTERNAL TABLE, but theorically
there should be more lines if the original text is very long. I found the standard text
ADRS_HEADER_LOGO_PRES provided by SAP, which is very long, and it should demonstrate the
bug.
The correction is not obvious as the loading is done by PACKAGE; consequently the last line of the
package may not be the last line of a text. So we need to wait for the next package to complete the
text and be able to use IMPORT. That requires both a sorted read (ORDER BY) and a buffer table.
The following code should always work. Please feel free to ask me any question if it's unclear.
REPORT.
TYPES: BEGIN OF ty_stxl,
relid TYPE stxl-relid,
tdobject TYPE stxl-tdobject,
tdname TYPE stxl-tdname,
tdid TYPE stxl-tdid,
tdspras TYPE stxl-tdspras,
srtf2 TYPE stxl-srtf2,
clustr TYPE stxl-clustr,
clustd TYPE stxl-clustd,
END OF ty_stxl.
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 9/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
DATA: t_stxl TYPE STANDARD TABLE OF ty_stxl,
t_stxl_buffer 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.
TABLES stxh.
SELECT-OPTIONS s_object FOR stxh-tdobject.
SELECT-OPTIONS s_name FOR stxh-tdname.
SELECT-OPTIONS s_id FOR stxh-tdid.
SELECT-OPTIONS s_langu FOR stxh-tdspras.
DO.
FETCH NEXT CURSOR cursor
APPENDING TABLE t_stxl
PACKAGE SIZE package_size.
subrc = sy-subrc.
IF subrc = 4.
IF lines( t_stxl ) > 0.
process = abap_true.
ELSE.
process = abap_false.
ENDIF.
ELSEIF subrc = 0.
IF lines( t_stxl ) < package_size.
process = abap_true.
ELSE.
" put lines of last key aside, as there may be other lines for the same key
DESCRIBE TABLE t_stxl LINES l_last_tabix.
READ TABLE t_stxl INDEX l_last_tabix INTO s_stxl.
READ TABLE t_stxl INDEX 1 ASSIGNING <stxl>.
IF <stxl>-relid = s_stxl-relid
AND <stxl>-tdobject = s_stxl-tdobject
AND <stxl>-tdname = s_stxl-tdname
AND <stxl>-tdid = s_stxl-tdid
AND <stxl>-tdspras = s_stxl-tdspras.
" The whole package has same key -> load next lines
process = abap_false.
ELSE.
process = abap_true.
l_first_tabix = l_last_tabix.
l_first_tabix = l_last_tabix.
DO.
SUBTRACT 1 FROM l_first_tabix.
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 11/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
READ TABLE t_stxl INDEX l_first_tabix ASSIGNING <stxl>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF NOT ( <stxl>-relid = s_stxl-relid
AND <stxl>-tdobject = s_stxl-tdobject
AND <stxl>-tdname = s_stxl-tdname
AND <stxl>-tdid = s_stxl-tdid
AND <stxl>-tdspras = s_stxl-tdspras ).
EXIT.
ENDIF.
ENDDO.
ADD 1 TO l_first_tabix.
APPEND LINES OF t_stxl FROM l_first_tabix TO l_last_tabix TO t_stxl_buffer.
DELETE t_stxl FROM l_first_tabix TO l_last_tabix.
ENDIF.
ENDIF.
ELSE.
" can't happen
ASSERT 0 = 1.
ENDIF.
IF process = abap_true.
LOOP AT t_stxl ASSIGNING <stxl>.
AT NEW tdspras.
REFRESH t_stxl_raw.
ENDAT.
AT END OF tdspras.
IMPORT tline = t_tline FROM INTERNAL TABLE t_stxl_raw.
DESCRIBE TABLE t_stxl_raw.
FORMAT COLOR 5.
WRITE: / 'AA', sy-tfill LEFT-JUSTIFIED, <stxl>-tdobject, <stxl>-tdname, <stxl>-tdid, <stxl>-tdspras.
FORMAT RESET.
LOOP AT t_tline ASSIGNING <tline>.
WRITE: / <tline>-tdline.
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 12/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
ENDLOOP.
REFRESH t_stxl_raw.
ENDAT.
ENDLOOP.
ENDIF.
t_stxl = t_stxl_buffer.
IF subrc <> 0.
EXIT.
ENDIF.
ENDDO.
Thomas Zloch May 19, 2014 1:27 PM (in response to Sandra Rossi)
Nice catch, and thanks for enhancing the logic. It seems that the threshold of STXL-
CLUSTR is 7902 (bytes?), then a new line is started.
My use cases so far were far below this threshold, so it never occurred to me.
Cheers
Thomas
Like (0)
Like (0)
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 13/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
Like (1)
Hi Mansor,
Thanks for your effort. In Lot of cases many Abapers are using READ_TEXT fm. Now onwards we
will follow above code what you have mentioned.
Thanks,
Gurunath D
Like (0)
Thomas Zloch May 19, 2014 5:20 PM (in response to Gurunath Kumar Dadamu)
It's fine to use READ_TEXT. The approach described here is meant for performance-critical
mass processing.
Thomas
Like (1)
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 14/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
You might also want to add IF t_stxh[] IS NOT INITIAL check before 'FOR ALL ENTRIES'. Or a
program could display some kind of 'No data found' message and just exit in such case, I guess...
Like (0)
Hi Mansoor,
the STXL storage mechanism that you proudly found out and exposed here (congratulations), is only
a small part of the function module READ_TEXT. There is
Regards,
Rüdiger
Like (2)
Hi Mansoor,
Good post, I have tried RETRIEVAL_MULTIPLE_TEXTS that you mentioned to read batch short text
and It is working fine !
Thanks,
Darshak
Like (0)
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 15/16
27/8/2014 Alternative to READ_TEXT Function Module (No mo... | SCN
Like (0)
Like (0)
Nice Alternative to Read_Text & Excellent use of field symbol and Import statement
Like (0)
http://scn.sap.com/community/abap/blog/2014/02/25/alternative-to-readtext-function-module 16/16