注意在修改之前要先用'CSAI_BOM_READ读取该BOM的数据 。
可实现对BOM行项目做增删改的操作,而且可以带上更改号。
REPORT ZTEST5.
data wa_csin type CSIN.
data tab_stpob type table of STPOB.
data tab_STKOB type table of STKOB.
data tab_DEP_DATA type table of CSDEP_DAT.
data tab_DEP_DESCR type table of CSDEP_DESC.
data tab_DEP_ORDER type table of CSDEP_ORD.
data tab_DEP_SOURCE type table of CSDEP_SORC.
data tab_DEP_DOC type table of CSDEP_DOC.
data g_warn_stlnr type STZUB-STLNR.
data g_flwarning type CAPIFLAG-FLWARNING.
cLEAR wa_csin.
wa_csin-MATNR = '000000000000001040'.
wa_csin-EMENG = 2.
wa_csin-datuv = sy-datum.
wa_csin-PSPNR = '00065061'.
wa_csin-werks = '2000' .
wa_csin-stlan = '1'. " 4
wa_CSIN-STLNR = '00001548'.
wa_csin-stlty = 'P'.
data: l_text type string.
CALL FUNCTION 'CSAI_BOM_READ'
EXPORTING
ECSIN = wa_csin
IMPORTING
fl_warning = g_flwarning
TABLES
t_stpob = tab_stpob
T_STKOB = tab_stkob
T_DEP_DATA = tab_dep_data
T_DEP_DESCR = tab_dep_descr
T_DEP_ORDER = tab_dep_order
T_DEP_SOURCE = tab_dep_source
T_DEP_DOC = tab_dep_doc
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO into l_text
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
write l_text.
else.
data wa_stpob like STPOB.
data wa_stzub like STZUB.
data wa_STKOB like STKOB.
* wa_csin-aennr = '009900159470'.
read table tab_stkob into wa_stkob index 1.
wa_stkob-stlST = '1'.
WA_STKOB-BMENG = 3.
WA_STKOB-AENNR = 'A-4008057012'.
CLEAR wa_stzub.
wa_stzub-stlty = 'P'.
loop at tab_stpob into wa_stpob.
IF WA_STPOB-IDNRK ='000000000000001090'.
* WA_stpob-vbkz = 'D'. "与删除相关
* wa_stpob-aennr = 'A-4008057012'.
* MODIFY TAB_STPOB FROM WA_STPOB.
elseIF WA_STPOB-IDNRK = '000000000000001080'.
wa_stpob-menge = 150.
wa_stpob-aennr = 'A-4008057012'.
modify tab_stpob from wa_stpob.
ENDIF.
CLEAR wa_stpob.
endloop.
" 新增行项目
*CLEAR wa_stpob.
*wa_stpob-stlty = 'P'.
*wa_stpob-idnrk = '000000000000001201'.
*wa_stpob-postp = 'L'.
*wa_stpob-posnr = '0418' .
*wa_stpob-menge = 6.
*WA_STPOB-AENNR = 'A-4008057012'.
*wa_stpob-potx1 = 'liu'.
*wa_stpob-potx2 = 'jin'.
*wa_stpob-datuv = sy-datum.
*APPEND wa_stpob TO tab_stpob.
*CLEAR wa_stpob.
*wa_stpob-stlty = 'P'.
*wa_stpob-idnrk = '000000000000001060'.
*wa_stpob-postp = 'L'.
*wa_stpob-posnr = '0016' .
*wa_stpob-menge = 3.
*wa_stpob-potx1 = 'liu2'.
*wa_stpob-potx2 = 'jin3'.
*wa_stpob-datuv = sy-datum.
*APPEND wa_stpob TO tab_stpob.
*CLEAR wa_stpob.
data tab2 like tab_stpob.
WA_CSIN-AENNR = 'A-4008057012'.
CALL FUNCTION 'CSAI_BOM_MAINTAIN'
EXPORTING
* FL_BOM_CREATE = ' '
* FL_NEW_ITEM = ''
* FL_COMPLETE = ' '
ECSIN = wa_csin
ESTKOB = wa_stkob
ESTZUB = wa_stzub
* FL_NO_CHANGE_DOC = ' '
FL_COMMIT_AND_WAIT = 'X'
* FL_NO_COMMIT_WORK = ' '
* FL_ALE = ' '
* FL_DEFAULT_VALUES = 'X'
* FL_NEW_ROMEN = 'X'
* FL_RECURSIVE = ' '
FL_IMPLICIT_SUBITEM_DELETION = 'X'
* IMPORTING
* fl_warning = g_flwarning
* ASTKOB =
* ASTZUB =
TABLES
T_STPOB = tab_stpob
* ET_STPOB = tab2
* T_STPUB =
* T_LTX_ITM =
* T_LTX_BOM =
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
IF sy-subrc NE 0. " here Sy-subrc is 1
MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO into l_text
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
write l_text.
else.
write 'OK'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
ENDIF.
ENDIF.
标签:CSAI,SY,wa,MAINTAIN,BOM,tab,stpob,data,csin
From: https://blog.51cto.com/u_8215601/7508970