http://scn.sap.com/thread/18844
第一步:初始化server group ,server group 可以用RZ12进行维护,参数支直复制即可,不要修改。
CONSTANTS: serv_group LIKE rzllitab-classname VALUE 'JOBRUN'.
CALL FUNCTION 'SPBT_INITIALIZE'
EXPORTING
group_name = serv_group
* IMPORTING
* MAX_PBT_WPS =
* FREE_PBT_WPS =
EXCEPTIONS
.
第二步:分别写多个FM的调用,注意:如果多个FM都共用的参数,数据写在主程序中,然后用参数传到FM里。
CALL FUNCTION 'Z_BAPI_FM1'
STARTING NEW TASK 'FM1TASK' DESTINATION IN GROUP serv_group
PERFORMING sub_fm1_back ON END OF TASK
TABLES
date_ra = date_ra.
CALL FUNCTION 'Z_BAPI_FM2'
STARTING NEW TASK 'FM2TASK' DESTINATION IN GROUP serv_group
PERFORMING sub_FM2_back ON END OF TASK
TABLES
date_ra = date_ra.
第三步.FM执行完之后数据反回,数据返回的参数是全局的,在Z_BAPI_FM*中对全局参数进行赋值。
FORM sub_fm1_back USING name.
RECEIVE RESULTS FROM FUNCTION 'Z_BAPI_FM1'
TABLES
ret_par = gdt_ret_pars "返回的参数
return = gdt_gr_return.
APPEND LINES OF gdt_gr_return TO gdt_return.
gr_flag = 'X'. "这个很重要,根据这个参数判断FM是否执行完毕
ENDFORM. "sub_fm1_back
FORM sub_fm2_back USING name.
RECEIVE RESULTS FROM FUNCTION 'Z_BAPI_FM2'
TABLES
returnpo = gdt_ret_pos
return = gdt_returnpo_return.
APPEND LINES OF gdt_returnpo_return TO gdt_return.
returnpo_flag = 'X'.
ENDFORM. "sub_fm2_back
第四步:收尾工作,判断各个FM是否执行完毕
WAIT UNTIL gr_flag = 'X' AND returnpo_flag = 'X' .
ret_pars[] = gdt_ret_pars. "返回的结果
returnpo[] = gdt_ret_pos. "返回的结果
APPEND LINES OF gdt_return TO return. "最终返回的return ,一般FM都有返回值,返回错误,警告等信息。
From <http://www.cnblogs.com/byfhd/archive/2008/02/26/1082661.html>