选择界面:
SELECTION-SCREEN BEGIN OF BLOCK b0 WITH FRAME TITLE text-t00.
PARAMETERS: group(12) DEFAULT 'ZSCMLT', "group name of session
user(12) DEFAULT sy-uname, "user for session in batch
once TYPE i DEFAULT 5000, "每个Session处理的数据条数
keep AS CHECKBOX DEFAULT 'X',
*"' ' = delete session if finished
*"'X' = keep session if finished
smalllog AS CHECKBOX DEFAULT 'X',
*"' ' = log all transactions
*"'X' = no transaction logging
autorun AS CHECKBOX."是否自动运行生成的Session
SELECTION-SCREEN END OF BLOCK b0.
主要的FORM:
*&---------------------------------------------------------------------*
*& Form bdc
*&---------------------------------------------------------------------*
FORM bdc .
DATA: linenum LIKE sy-tabix,
fromnum LIKE sy-index,
tonum LIKE sy-index.
DATA: n TYPE i ,
m LIKE sy-tabix.
DATA: listobject LIKE abaplist OCCURS 0.
SORT itab BY infnr.
DESCRIBE TABLE itab LINES linenum.
n = linenum DIV once.
n = n + 1.
DO n TIMES.
itab_once[] = itab[].
fromnum = sy-index * once + 1 .
DELETE itab_once FROM fromnum TO linenum.
IF sy-index > 1 .
tonum = fromnum - once - 1 .
DELETE itab_once FROM 1 TO tonum.
ENDIF.
PERFORM bdc_once USING sy-index.
ENDDO.
IF autorun = 'X'.
CONCATENATE group '*' INTO group_all .
SUBMIT rsbdcsub
WITH mappe EQ group_all
WITH z_verarb EQ 'X'
WITH fehler EQ ' '
WITH von = sy-datum
WITH bis = sy-datum
AND RETURN
EXPORTING LIST TO MEMORY.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
SKIP 2.
WRITE '后台Job设置情况:'.
ULINE.
CALL FUNCTION 'WRITE_LIST'
TABLES
listobject = listobject
EXCEPTIONS
empty_list = 1
OTHERS = 2.
ENDIF.
LEAVE TO SCREEN 300.
ENDFORM .
*---------------------------------------------------------------------*
* FORM bdc_once *
*---------------------------------------------------------------------*
FORM bdc_once USING index.
DATA: c(3) ,
group_tmp(12).
c = index.
CONDENSE c .
CONCATENATE group c INTO group_tmp.
* PERFORM open_group.
SKIP.
WRITE: /(20) 'Create group'(i01), group_tmp.
SKIP.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = group_tmp
user = user
keep = keep.
WRITE: /(30) 'BDC_OPEN_GROUP'(i02),
(12) 'returncode:'(i05),
sy-subrc.
LOOP AT itab_once .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = itab_once-matnr
IMPORTING
output = itab_once-matnr.
REFRESH bdcdata .
CLEAR bdcdata .
PERFORM bdc_dynpro USING 'SAPMM06I' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_field USING 'EINA-INFNR' itab_once-infnr.
PERFORM bdc_field USING 'EINA-LIFNR' itab_once-lifnr.
PERFORM bdc_field USING 'EINA-MATNR' itab_once-matnr.
PERFORM bdc_field USING 'EINE-EKORG' itab_once-ekorg.
PERFORM bdc_field USING 'EINE-WERKS' itab_once-werks.
CASE itab_once-esokz .
WHEN '0'.
PERFORM bdc_field USING 'RM06I-NORMB' 'X'.
WHEN '3'.
PERFORM bdc_field USING 'RM06I-LOHNB' 'X'.
WHEN '2'.
PERFORM bdc_field USING 'RM06I-KONSI' 'X'.
WHEN 'P'.
PERFORM bdc_field USING 'RM06I-PIPEL' 'X'.
ENDCASE.
PERFORM bdc_dynpro USING 'SAPMM06I' '0101'.
PERFORM bdc_field USING 'BDC_OKCODE' '=EINE'.
PERFORM bdc_dynpro USING 'SAPMM06I' '0102'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
PERFORM bdc_field USING 'EINE-APLFZ' itab_once-apsum.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'ME12'
TABLES
dynprotab = bdcdata.
IF smalllog <> 'X'.
WRITE: / 'BDC_INSERT'(i03),
'ME12',
'returncode:'(i05),
sy-subrc,
'RECORD:',
sy-index.
ENDIF.
ENDLOOP.
* PERFORM close_group.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(i04),
(12) 'returncode:'(i05),
sy-subrc.
ENDFORM. " bdc
*---------------------------------------------------------------------*
* FORM bdc_field *
*---------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
CONDENSE bdcdata-fval.
APPEND bdcdata.
ENDFORM.
*---------------------------------------------------------------------*
* FORM BDC_DYNPRO *
*---------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module STATUS_0300 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0300 OUTPUT.
DATA: n TYPE i VALUE 3.
DATA: len TYPE i .
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SET PF-STATUS space.
SUPPRESS DIALOG.
ENDMODULE. " STATUS_0300 OUTPUT
Text Symbols:
E00 打开数据集错误,返回代码:
I01 会话视窗名称
I02 开启会话视窗
I03 加入事务
I04 关闭会话视窗
I05 返回代码=
I06 错误会话视窗被创建
S01 会话视窗名称
S02 用户
S03 保留会话视窗
S04 冻结日期
S05 BDC Processing mode
S06 更新对话
S07 生成会话视窗
S08 调用事务
S09 错误会话
阅读(6491) | 评论(0) | 转发(0) |