参考 http://blog.csdn.net/wanglei880526/article/details/8949754
********************************************************************* * 程序名: YXB_TEST1 * 程序名称:多线程读取长文本DEMO *------------------------------------------------- * 创建日期 程序员 SAP版本 程序类型 * 2024-04-28 徐邦 REPORT * 功能说明书: *------------------------------------------------- * 描述: * *================================================= * 修改日期 版本 修改人 修改描述 ********************************************************************* *&---------------------------------------------------------------------* REPORT YXB_TEST1. TABLES:VBAK. *----------------------------------------------------------------------* * TYPE-POOLS *----------------------------------------------------------------------* TYPE-POOLS: SLIS. *----------------------------------------------------------------------* * data *----------------------------------------------------------------------* TYPES: * 销售订单 BEGIN OF TY_VBAK, VBELN TYPE VBAK-VBELN, "销售订单 ERDAT TYPE VBAK-ERDAT, "记录建立日期 ERZET TYPE VBAK-ERZET, "输入时间 ERNAM TYPE VBAK-ERNAM, "对象创建人姓名 TEXT TYPE CHAR255, "长文本 END OF TY_VBAK, * 销售订单进程 BEGIN OF TY_TASK, VBELN TYPE VBAK-VBELN, "物料号 TEXT TYPE CHAR255, "长文本 TASKNAME TYPE CHAR10, "任务名 END OF TY_TASK, BEGIN OF TY_ZCKMLKEPH. INCLUDE STRUCTURE ZCKMLKEPH. TYPES: MATNR TYPE MARA-MATNR, "物料号 WERKS LIKE T001W-WERKS, END OF TY_ZCKMLKEPH. DATA: GT_VBAK TYPE TABLE OF TY_VBAK, GT_TASK TYPE TABLE OF TY_TASK. DATA: GV_JOBS TYPE I. *&---------------------------------------------------------------------* *& Parameters Screen: *&---------------------------------------------------------------------* SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN, S_ERNAM FOR VBAK-ERNAM, S_ERDAT FOR VBAK-ERDAT. START-OF-SELECTION. * 获取销售订单数据 PERFORM FRM_GET_DATA. * 异步调用DEMO PERFORM FMR_DEMO. * ALV展示 PERFORM FRM_ALV_DISPLAY. *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* FORM FRM_GET_DATA. * 获取销售订单数据 SELECT VBELN ERDAT ERZET ERNAM FROM VBAK INTO CORRESPONDING FIELDS OF TABLE GT_VBAK WHERE VBELN IN S_VBELN AND ERDAT IN S_ERDAT AND ERNAM IN S_ERNAM. IF SY-SUBRC <> 0. MESSAGE '无查询数据!' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. SORT GT_VBAK BY VBELN ASCENDING. ENDFORM. *&---------------------------------------------------------------------* *& Form FMR_DEMO *&---------------------------------------------------------------------* FORM FMR_DEMO . * 异步调用DEMO DATA: LV_CLASSNAME TYPE RZLLI_APCL, "Server Group Name LV_APPLSERVER TYPE RZLLITAB-APPLSERVER, "RFC Serve Group LV_TASKNAME TYPE CHAR10, LV_SENDJOB TYPE I, LV_TASK_NUM TYPE I, LV_NAME TYPE THEAD-TDNAME. DATA: LS_TASK TYPE TY_TASK. * 一般系统直接指定<RFC Serve Group> =' parallel_generators ',“ * 为了保持一般性通过如下逻辑段获取服务器组”对应的内容 CALL 'C_SAPGPARAM' "#EC CI_CCALL ID 'NAME' FIELD 'rdisp/myname' ID 'VALUE' FIELD LV_APPLSERVER. SELECT SINGLE CLASSNAME FROM RZLLITAB INTO LV_CLASSNAME "Server Group Name WHERE APPLSERVER = LV_APPLSERVER AND GROUPTYPE = 'S'. "S:服务器组,空:登陆组 LOOP AT GT_VBAK INTO DATA(LS_VBAK). * 生成任务名称 = sy-tabix WRITE SY-TABIX TO LV_TASKNAME NO-GROUPING. CONDENSE LV_TASKNAME. * 生成任务名称 = 'Task' + sy-tabix End--* * CLEAR LS_TASK. * LS_TASK-TASKNAME = LV_TASKNAME. * LS_TASK-VBELN = <LFS_VBAK>-VBELN. * APPEND LS_MARC TO GT_MARC. GT_TASK = VALUE #( BASE GT_TASK ( TASKNAME = LV_TASKNAME VBELN = LS_VBAK-VBELN ) ) . LV_NAME = LS_VBAK-VBELN. * 异步调用函数 CALL FUNCTION 'ZREAD_TEXT' STARTING NEW TASK LV_TASKNAME DESTINATION IN GROUP LV_CLASSNAME PERFORMING FRM_GET_TEXT ON END OF TASK * 只要将函数的EXPORTING参数放在此处,其他参数放到子程序中 EXPORTING ID = '0001' LANGUAGE = '1' NAME = LV_NAME OBJECT = 'VBBK'. IF SY-SUBRC = 0. LV_SENDJOB = LV_SENDJOB + 1. ENDIF. LV_TASK_NUM = LV_TASK_NUM + 1. "记录启动的进程数量 IF LV_TASK_NUM = 5. "可以通过RZ12,查看队列中的最大请求数 * 获取并发进程返回的结果 WAIT UNTIL GV_JOBS >= LV_SENDJOB. CLEAR:LV_TASK_NUM,GV_JOBS,LV_SENDJOB. FREE:GT_TASK. ENDIF. ENDLOOP. * 如果还有剩余的 IF LV_SENDJOB IS NOT INITIAL. * 获取并发进程返回的结果 WAIT UNTIL GV_JOBS >= LV_SENDJOB. ENDIF. ENDFORM. " FMR_GET_DATA *&---------------------------------------------------------------------* *& Form FRM_GET_TEXT *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* FORM FRM_GET_TEXT USING I_TASKNAME. DATA: LT_ZCKMLKEPH TYPE STANDARD TABLE OF TY_ZCKMLKEPH, LS_ZCKMLKEPH TYPE TY_ZCKMLKEPH. DATA: LT_LINES TYPE TABLE OF TLINE. GV_JOBS = GV_JOBS + 1. ""Receiving data CLEAR:LT_LINES[]. CLEAR:LT_ZCKMLKEPH. * 调用函数的tables参数 RECEIVE RESULTS FROM FUNCTION 'ZREAD_TEXT' TABLES LINES = LT_LINES. CHECK LT_LINES IS NOT INITIAL. * 读取对于线程的数据,进行一些后续处理 READ TABLE GT_TASK INTO DATA(LS_TASK) WITH KEY TASKNAME = I_TASKNAME BINARY SEARCH. IF SY-SUBRC = 0. READ TABLE GT_VBAK ASSIGNING FIELD-SYMBOL(<LFS_VBAK>) BINARY SEARCH WITH KEY VBELN = LS_TASK-VBELN. IF SY-SUBRC = 0. LOOP AT LT_LINES INTO DATA(LS_LINES). CONCATENATE <LFS_VBAK>-TEXT LS_LINES-TDLINE INTO <LFS_VBAK>-TEXT. ENDLOOP. ENDIF. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_ALV_DISPLAY *&---------------------------------------------------------------------* *& 展示ALV *&---------------------------------------------------------------------* FORM FRM_ALV_DISPLAY . DATA: LS_LAYOUT TYPE LVC_S_LAYO, LT_FIELDCAT TYPE LVC_T_FCAT, LS_FIELDCAT TYPE LVC_S_FCAT. DEFINE M_FIELDCAT. CLEAR LS_FIELDCAT. LS_FIELDCAT-FIELDNAME = &2. "字段ID LS_FIELDCAT-COLTEXT = &3. "列标题 LS_FIELDCAT-REF_TABLE = &4. "参考表名称 LS_FIELDCAT-REF_FIELD = &5. "参考字段名称 APPEND LS_FIELDCAT TO &1. END-OF-DEFINITION. * 布局设置 CLEAR LS_LAYOUT. LS_LAYOUT-ZEBRA = 'X'. "斑马线 LS_LAYOUT-CWIDTH_OPT = 'X'. "最优宽 * LS_LAYOUT-BOX_FNAME = 'SEL'. M_FIELDCAT LT_FIELDCAT 'VBELN' '' 'VBAK' 'VBELN'. M_FIELDCAT LT_FIELDCAT 'ERDAT' '' 'VBAK' 'ERDAT'. M_FIELDCAT LT_FIELDCAT 'ERZET' '' 'VBAK' 'ERZET'. M_FIELDCAT LT_FIELDCAT 'ERNAM' '' 'VBAK' 'ERNAM'. M_FIELDCAT LT_FIELDCAT 'TEXT' '文本信息' '' ''. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING I_CALLBACK_PROGRAM = SY-REPID * I_CALLBACK_PF_STATUS_SET = 'FRM_SET_PF_STATUS' IS_LAYOUT_LVC = LS_LAYOUT IT_FIELDCAT_LVC = LT_FIELDCAT[] I_SAVE = 'A' TABLES T_OUTTAB = GT_VBAK EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. ENDFORM.
READ_TEXT 封装在ZREAD_TEXT里