ABAP读取文本函数效率优化,read_text --->zread_text

FUNCTION zread_text.
*“----------------------------------------------------------------------
"“本地接口:
*” IMPORTING
*” VALUE(CLIENT) LIKE SY-MANDT DEFAULT SY-MANDT
*" VALUE(ID) LIKE THEAD-TDID
*" VALUE(LANGUAGE) LIKE THEAD-TDSPRAS DEFAULT ‘1’
*" VALUE(OBJECT) LIKE THEAD-TDOBJECT
*" VALUE(ARCHIVE_HANDLE) LIKE SY-TABIX DEFAULT 0
*" VALUE(LOCAL_CAT) DEFAULT SPACE
*" TABLES
*" IT_NAME STRUCTURE ZTDNAME_RANGE
*" ET_TEXT STRUCTURE ZSTDTEXT
*"----------------------------------------------------------------------
TYPES:BEGIN OF ty_stxl,
tdname TYPE stxl-tdname,
clustr TYPE stxl-clustr,
clustd TYPE stxl-clustd,
END OF ty_stxl.
TYPES:BEGIN OF ty_stxk_raw,
clustr TYPE stxl-clustr,
clustd TYPE stxl-clustd,
END OF ty_stxk_raw.
DATA:lt_stxl TYPE STANDARD TABLE OF ty_stxl WITH HEADER LINE.
DATA:lt_tdname TYPE STANDARD TABLE OF ty_stxl WITH HEADER LINE.
DATA:lt_lines_temp TYPE TABLE OF tline WITH HEADER LINE.
DATA:lt_lines TYPE TABLE OF tline.
DATA:lt_stxl_raw TYPE STANDARD TABLE OF ty_stxk_raw.
DATA:ls_stxl_raw TYPE ty_stxk_raw.

SELECT tdname clustr clustd
INTO CORRESPONDING FIELDS OF TABLE lt_stxl
FROM stxl
WHERE tdobject = object
AND tdid = id
AND tdname IN it_name
AND tdspras = language
.
lt_tdname[] = lt_stxl[].

SORT lt_stxl BY tdname.
SORT lt_tdname BY tdname.
DELETE ADJACENT DUPLICATES FROM lt_tdname COMPARING tdname.

LOOP AT lt_tdname.
READ TABLE lt_stxl WITH KEY tdname = lt_tdname-tdname BINARY SEARCH.
IF sy-subrc = 0.

  CLEAR:ls_stxl_raw,lt_stxl_raw.
  REFRESH:lt_lines_temp.
  LOOP AT lt_stxl FROM sy-tabix.
    IF lt_stxl-tdname <> lt_tdname-tdname.
      EXIT.
    ENDIF.
    MOVE-CORRESPONDING lt_stxl TO ls_stxl_raw.
    APPEND ls_stxl_raw TO lt_stxl_raw.
  ENDLOOP.
  IF lt_stxl_raw[] IS NOT INITIAL.
    IMPORT tline = lt_lines_temp[]  FROM INTERNAL TABLE lt_stxl_raw[].

    CLEAR:et_text.
    et_text-tdname = lt_tdname-tdname.
    LOOP AT lt_lines_temp.
      et_text-ztext = et_text-ztext && lt_lines_temp-tdline.
    ENDLOOP.
    APPEND et_text.

  ENDIF.


ENDIF.

ENDLOOP.

ENDFUNCTION.

你可能感兴趣的:(ABAP,SAP,abap,SAP)