Alternative to READ_TEXT Function Module (to fetch multiple long text at one go )

Multi READ_TEXT Code in SAP

   *&---------------------------------------------------------------------*
*& Report  ZMULTI_READ_TEXT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZMULTI_READ_TEXT.

*---------------------------------------------------------------------*
* data declaration
*---------------------------------------------------------------------*

TABLES vbap.
DATA curs TYPE cursor.
TYPESBEGIN OF ty_stxl,
          tdname TYPE stxl-tdname,
          tdid   TYPE stxl-tdid,
          clustr TYPE stxl-clustr,
          clustd TYPE stxl-clustd,
        END OF ty_stxl.
TYPESBEGIN OF ty_stxh,
          tdobject TYPE stxh-tdobject,
          tdname   TYPE stxh-tdname,
          tdid TYPE stxh-tdid,
        END OF ty_stxh.

TYPESBEGIN OF ty_tdid,
      sign  TYPE ddsign,
      option  TYPE ddoption,
      low  TYPE stxl-tdid,
      high  TYPE stxl-tdid ,
  END OF ty_tdid.
DATA lt_tdid TYPE STANDARD TABLE OF ty_tdid.
DATA ls_tdid TYPE ty_tdid.
DATA lv_text  TYPE string.
DATA:  t_stxl TYPE STANDARD TABLE OF ty_stxl.
DATA:  t_stxh TYPE STANDARD TABLE OF ty_stxh.
FIELD-SYMBOLS<stxl> TYPE ty_stxl.
* compressed text data without text name
TYPESBEGIN 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.
*---------------------------------------------------------------------*
* selection screen
*---------------------------------------------------------------------*
SELECT-OPTIONS s_vbeln FOR vbap-vbeln.
SELECT-OPTIONS s_tdid FOR  stxh-tdid .
*---------------------------------------------------------------------*
* select on header
*---------------------------------------------------------------------*
SELECT tdobject tdname tdid
   FROM stxh
     INTO TABLE t_stxh
    WHERE tdobject 'VBBK' AND tdname IN s_vbeln AND tdid IN  s_tdid  AND tdspras 'E'.

*---------------------------------------------------------------------*
* select compressed text lines into cursor
*---------------------------------------------------------------------*
OPEN CURSOR curs FOR SELECT tdname tdid clustr clustd
        FROM stxl
        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.

*---------------------------------------------------------------------*
* select compressed text lines in blocks of 1000 (adjustable) from cursor
*---------------------------------------------------------------------*
DO.
  FETCH NEXT CURSOR curs INTO TABLE t_stxl PACKAGE SIZE 1000.
  IF sy-subrc <> 0.
    EXIT.
  ELSE.
    LOOP AT t_stxl ASSIGNING <stxl>.

*---------------------------------------------------------------------*
*   decompress text
*---------------------------------------------------------------------*
      CLEARt_stxl_raw[]t_tline[].
      w_stxl_raw-clustr <stxl>-clustr.
      w_stxl_raw-clustd <stxl>-clustd.
      APPEND w_stxl_raw TO t_stxl_raw.

*---------------------------------------------------------------------*
*  access text lines for further processing
*---------------------------------------------------------------------*
      IMPORT tline t_tline FROM INTERNAL TABLE t_stxl_raw.


*---------------------------------------------------------------------*
*  aadd text in one row by seprater
*---------------------------------------------------------------------*

      LOOP AT t_tline ASSIGNING <tline>.
        IF lv_text IS INITIAL.
          lv_text <tline>-tdline .
        ELSE.
          CONCATENATE lv_text <tline>-tdline INTO lv_text SEPARATED BY cl_abap_char_utilities=>newline.
        ENDIF.
      ENDLOOP.
*---------------------------------------------------------------------*
*  write text to screen with name id and text
*---------------------------------------------------------------------*
      WRITE/  <stxl>-tdname  , <stxl>-tdid , lv_text .
      CLEAR lv_text.
  ENDLOOP.
  FREE t_stxl.
ENDIF.
ENDDO.

Comments

Popular posts from this blog