大多情况使用BDC批量修改 这次使用 CSAP_MAT_BOM_MAINTAIN 函数 进行批量修改
TABLES:MAST,STKO,STZU.
" 获取数据至内表
FORM FRM_GET_DATA .
SELECT
MATNR
WERKS
STLAN
S~STLNR
S~STLAL
S~STLST
S~BMEIN
S~BMENG
S~STKTX
S~LABOR
S~CADKZ
FROM MAST AS M INNER JOIN STKO AS S
ON S~STLNR = M~STLNR AND S~STLAL = M~STLAL
INTO CORRESPONDING FIELDS OF TABLE GT_LIST
WHERE MATNR IN S_MATNR
AND WERKS = P_WERKS
AND S~STLTY = 'M' AND S~STLST = '02'." AND S~STLNR IN S_STLNR.
SELECT * FROM STZU INTO TABLE GT_STZU FOR ALL ENTRIES IN GT_LIST
WHERE STLTY = 'M' AND STLNR = GT_LIST-STLNR.
ENDFORM.
" 更改BOM状态 注意传入的日期使用函数中的类型
FORM FRM_CHANGE_DATA .
DATA: L_STKO TYPE STKO_API01.
DATA: L_WARNING TYPE TABLE OF CAPIFLAG-FLWARNING WITH HEADER LINE,
LT_STKO2 TYPE TABLE OF STKO_API02 WITH HEADER LINE,
L_DATE TYPE CSAP_MBOM-DATUV.
DATA: L_RETURN(50) TYPE C.
LOOP AT GT_LIST INTO GS_LIST WHERE SEL = 'X'.
CLEAR L_DATE.
READ TABLE GT_STZU INTO GS_STZU WITH KEY STLNR = GS_LIST-STLNR.
IF SY-SUBRC = 0.
CLEAR:L_STKO.
L_STKO-BASE_QUAN = GS_LIST-BMENG.
* L_STKO-BASE_UNIT = GS_LIST-BMEIN. "此为错误行 不能修改单位 传入则报错
L_STKO-BOM_STATUS = '01'.
L_STKO-ALT_TEXT = GS_LIST-STKTX.
L_STKO-LABORATORY = GS_LIST-LABOR.
L_STKO-BOM_TEXT = GS_STZU-ZTEXT.
L_STKO-BOM_GROUP = GS_STZU-EXSTL.
L_STKO-AUTH_GROUP = GS_STZU-STLBE.
L_STKO-CAD_IND = GS_LIST-CADKZ.
ENDIF.
L_DATE = SY-DATUM.
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
MATERIAL = GS_LIST-MATNR
PLANT = GS_LIST-WERKS
BOM_USAGE = GS_LIST-STLAN
ALTERNATIVE = GS_LIST-STLAL
VALID_FROM = L_DATE
I_STKO = L_STKO
FL_COMMIT_AND_WAIT = 'X'
FL_DEFAULT_VALUES = 'X'
IMPORTING
FL_WARNING = L_WARNING
O_STKO = LT_STKO2.
CLEAR L_RETURN.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = sy-msgid
msgnr = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv2
msgv3 = sy-msgv3
msgv4 = sy-msgv4
IMPORTING
message_text_output = L_return.
IF SY-SUBRC <> 0.
CONCATENATE 状态更改失败!' L_return INTO GS_LIST-MESSAGE .
ELSE.
GS_LIST-STLST = '01'.
GS_LIST-MESSAGE = '激活成功'.
ENDIF.
MODIFY GT_LIST FROM GS_LIST .
ENDLOOP.
ENDFORM.