ABAP 快捷取长文本方法

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.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值