ABAP程序做批处理一般用BDC来完成。本文主要讲解如何将BDC放在SM35的会话里。
步骤:
- 调用BDC_OPEN_GROUP,通过参数GROUP传入会话名称
- 编辑BDC录屏数据,调用函数BDC_INSERT,通过参数TCODE,CTUPARAMS,DYNPROTAB传入BDC相关数据
- 调用BDC_CLOSE_GROUP关闭会话
注意点:
- 第2步,可以循环放入多条数据
DATA:lv_bdcgroup TYPE char12. DATA: bdcdata LIKE STANDARD TABLE OF bdcdata WITH HEADER LINE, bdcmsg LIKE STANDARD TABLE OF bdcmsgcoll WITH HEADER LINE. MOVE 'JOB_GROUP' TO lv_bdcgroup. CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING client = sy-mandt group = lv_bdcgroup keep = 'X' user = sy-uname EXCEPTIONS client_invalid = 1 destination_invalid = 2 group_invalid = 3 group_is_locked = 4 holddate_invalid = 5 internal_error = 6 queue_error = 7 running = 8 system_lock_error = 9 user_invalid = 10 OTHERS = 11. LOOP AT itab INTO ls_itab. CLEAR: bdcdata. REFRESH bdcdata. PERFORM bdc_dynpro USING 'SAPLCHRG' '1000'. PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'. ... ... PERFORM bdc_dynpro USING 'SAPLCHRG' '1000'. PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE'. CALL FUNCTION 'BDC_INSERT' EXPORTING tcode = 'MM01' ctuparams = t_opt TABLES dynprotab = bdcdata EXCEPTIONS internal_error = 1 not_open = 2 queue_error = 3 tcode_invalid = 4 printing_invalid = 5 posting_invalid = 6 OTHERS = 7. ENDLOOP. CALL FUNCTION 'BDC_CLOSE_GROUP' EXCEPTIONS not_open = 1 queue_error = 2 OTHERS = 3.