日常读取生产订单、采购订单、销售订单等长文本时
最经常使用的就是系统标准函数READ_TEXT
这个函数确实很方便,但是因为是LOOP里面,频繁的访问数据库
会造成程序运行很慢,但是又找不到很好的办法
各位可以试下使用以下方法,能大幅度的提高运行效率,适用于各种长文本
以下为代码原文。
* 批量读取长文本,以物料批次特性为例子
TYPES: BEGIN OF ty_stxl, "项目
tdobject TYPE stxl-tdobject,
tdid TYPE stxl-tdid,
tdname TYPE stxl-tdname,
clustr TYPE stxl-clustr,
clustd TYPE stxl-clustd,
END OF ty_stxl.
TYPES: BEGIN OF ty_stxl_raw, "压缩的文本
clustr TYPE stxl-clustr,
clustd TYPE stxl-clustd,
END OF ty_stxl_raw.
TYPES:BEGIN OF ty_text, "解压的文本
tdobject TYPE stxl-tdobject,
tdid TYPE stxl-tdid,
tdname TYPE stxl-tdname,
tdline TYPE string,
matnr TYPE matnr,
charg TYPE charg_d,
END OF ty_text.
DATA:
gt_stxh TYPE TABLE OF stxh WITH HEADER LINE, "抬头
gt_stxl TYPE TABLE OF ty_stxl WITH HEADER LINE, "项目
gt_stxl_raw TYPE TABLE OF ty_stxl_raw WITH HEADER LINE,
gt_tline TYPE STANDARD TABLE OF tline WITH HEADER LINE,
gt_text TYPE TABLE OF ty_text WITH HEADER LINE.
”主要就是取出表中加密的文本
LOOP AT lt_out INTO DATA(ls_out) .
gt_stxh-tdname = ls_out-matnr.
gt_stxh-tdname+44(10) = ls_out-charg.
APPEND gt_stxh.
CLEAR gt_stxh.
ENDLOOP.
FREE gt_stxl.
IF gt_stxh[] IS NOT INITIAL .
SELECT tdobject tdid tdname clustr clustd
INTO CORRESPONDING FIELDS OF TABLE gt_stxl
FROM stxl
FOR ALL ENTRIES IN gt_stxh "WITH APPLICATION DATA AND TDNAME
WHERE relid = 'TX' "standard text
AND tdobject = 'CHARGE'
AND tdname = gt_stxh-tdname
AND tdid = 'VERM'
AND tdspras = sy-langu.
ENDIF.
LOOP AT gt_stxl.
CLEAR:gt_stxl_raw,gt_stxl_raw[], gt_tline,gt_tline[],gt_text.
gt_stxl_raw-clustr = gt_stxl-clustr.
gt_stxl_raw-clustd = gt_stxl-clustd.
APPEND gt_stxl_raw.
"使用系统标准函数READ_TEXT中的代码,将文本解析出来
IMPORT tline = gt_tline FROM INTERNAL TABLE gt_stxl_raw.
LOOP AT gt_tline.
gt_text-tdline = gt_text-tdline && gt_tline-tdline.
ENDLOOP.
gt_text-tdobject = gt_stxl-tdobject.
gt_text-tdid = gt_stxl-tdid.
gt_text-tdname = gt_stxl-tdname.
gt_text-matnr = gt_stxl-tdname.
gt_text-charg = gt_stxl-tdname+44(10).
APPEND gt_text.
ENDLOOP.
SORT gt_text BY tdname.