FUNCTION z_read_table_text.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(P_LANGU) TYPE CHAR1 DEFAULT SPACE
*" TABLES
*" IT_STXL TYPE ZT_STXL
*"----------------------------------------------------------------------
*compressed text data with text name
TYPES: BEGIN OF ty_stxl,
tdname TYPE stxl-tdname,
clustr TYPE stxl-clustr,
clustd TYPE stxl-clustd,
tdobject TYPE tdobject,
tdid TYPE tdid,
txt TYPE string, "长文本描述
END OF ty_stxl.
DATA: t_stxl TYPE STANDARD TABLE OF ty_stxl.
FIELD-SYMBOLS: <stxl> TYPE ty_stxl,
<is_stxl> TYPE zystxl.
* 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: it_stxl2 TYPE zt_stxl,
is_stxl2 TYPE zystxl.
DATA: lv_langu TYPE spras.
DATA: wa_stxl LIKE LINE OF it_stxl.
CHECK it_stxl[] IS NOT INITIAL.
MODIFY it_stxl FROM wa_stxl TRANSPORTING txt WHERE txt IS NOT INITIAL.
* select compressed text lines in blocks of 3000 (adjustable)
IF p_langu IS NOT INITIAL.
lv_langu = p_langu.
ELSE.
lv_langu = sy-langu.
ENDIF.
SELECT tdname clustr clustd tdobject tdid
INTO TABLE t_stxl
FROM stxl
* PACKAGE SIZE 3000
FOR ALL ENTRIES IN it_stxl
WHERE relid = 'TX' "standard text
AND tdobject = it_stxl-tdobject
AND tdname = it_stxl-tdname
AND tdid = it_stxl-tdid
AND tdspras = lv_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>.
* <stxl>-txt = <tline>-tdline.
CONCATENATE <stxl>-txt <tline>-tdline INTO <stxl>-txt."20191224
ENDLOOP.
ENDLOOP.
SORT t_stxl BY tdobject tdname tdid.
LOOP AT it_stxl ASSIGNING <is_stxl>.
READ TABLE t_stxl ASSIGNING <stxl> WITH KEY tdobject = <is_stxl>-tdobject
tdname = <is_stxl>-tdname
tdid = <is_stxl>-tdid BINARY SEARCH.
IF sy-subrc = 0.
<is_stxl>-txt = <stxl>-txt.
ELSE.
is_stxl2 = <is_stxl>.
APPEND is_stxl2 TO it_stxl2.
ENDIF.
ENDLOOP.
CHECK p_langu IS INITIAL."要求语言为空时, 才到另一种语言寻找文本
CHECK it_stxl2 IS NOT INITIAL.
IF sy-langu = 'E'.
lv_langu = '1'.
ELSE.
lv_langu = 'E'.
ENDIF.
* select compressed text lines in blocks of 3000 (adjustable)
SELECT tdname clustr clustd tdobject tdid
INTO TABLE t_stxl
FROM stxl
* PACKAGE SIZE 3000
FOR ALL ENTRIES IN it_stxl2
WHERE relid = 'TX' "standard text
AND tdobject = it_stxl2-tdobject
AND tdname = it_stxl2-tdname
AND tdid = it_stxl2-tdid
AND tdspras = lv_langu.
CHECK sy-subrc = 0.
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>.
* <stxl>-txt = <tline>-tdline.
CONCATENATE <stxl>-txt <tline>-tdline INTO <stxl>-txt."20191224
ENDLOOP.
ENDLOOP.
SORT t_stxl BY tdobject tdname tdid.
LOOP AT it_stxl ASSIGNING <is_stxl> WHERE txt IS INITIAL.
READ TABLE t_stxl ASSIGNING <stxl> WITH KEY tdobject = <is_stxl>-tdobject
tdname = <is_stxl>-tdname
tdid = <is_stxl>-tdid BINARY SEARCH.
IF sy-subrc = 0.
<is_stxl>-txt = <stxl>-txt.
ENDIF.
ENDLOOP.
ENDFUNCTION.