SAP PP CSAP_MAT_BOM_MAINTAIN ECN 替换组件
注意:替换后 要保证在同一时间 ITM_IDENT 相同的只有一个行项目
DATA: TEMP_MAT TYPE MATNR,
TEMP_WERKS TYPE WERKS_D,
TEMP_STLNR LIKE MAST-STLNR, "物料单号(bom号)
RETURN(220) TYPE C,
ISFIND(1) TYPE C,
FROMDATE(10) TYPE C.
DATA:TEMP_MATNR TYPE MATNR.
DATA: BEGIN OF ZLOG,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
INTERFACENAME(60) TYPE C,
LOGDATE TYPE DATUM,
LOGTIME TYPE UZEIT,
MAKTX TYPE MAKTX,
MEINS TYPE MEINS,
MBRSH TYPE MBRSH,
LVORM TYPE LVORM,
MTART TYPE MTART,
SPART TYPE SPART,
MATKL TYPE MATKL,
BISMT TYPE BISMT,
LGFSB TYPE LGFSB,
EORIGINNO(40) TYPE C,
CREATER(20) TYPE C,
MESSAGETYPE(1) TYPE C,
MESSAGE(220) TYPE C,
END OF ZLOG.
DATA: BEGIN OF SUBMATNR_COUNT,"用于记录在同一层级下相同子物料,相同数量,出现的次数。
SUBMATNR TYPE MATNR,
MENGE TYPE KMPMG,
COUNT TYPE I,
END OF SUBMATNR_COUNT.
DATA:SAP_SUBMATNR_COUNT LIKE SUBMATNR_COUNT,
PLM_SUBMATNR_COUNT LIKE SUBMATNR_COUNT.
DATA: NO1 TYPE I,
NO2 TYPE I.
DATA:I_STKO LIKE STKO_API01.
DATA:BEGIN OF GS_INPUTPBOM,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
IDNRK TYPE IDNRK,
KMPMG TYPE KMPMG,
XUHAO TYPE I,
MEINS TYPE MEINS,
SORTP TYPE SORTP,
LOGDATE TYPE DATUM,
LOGTIME TYPE UZEIT,
END OF GS_INPUTPBOM.
DATA:GT_STPO_INPUT LIKE TABLE OF STPO_API03 WITH HEADER LINE.
DATA:GT_STPO_INPUTTO LIKE TABLE OF STPO_API03 WITH HEADER LINE.
DATA: SAP_STPO LIKE TABLE OF STPO_API03 WITH HEADER LINE.
DATA: SAP_STPU LIKE TABLE OF STPU_API01 WITH HEADER LINE.
DATA: PDATAV LIKE CSAP_MBOM-DATUV.
DATA:INPUT_PBOM LIKE TABLE OF ZPBOM WITH HEADER LINE.
DATA:I_MATNR LIKE MARA-MATNR.
DATA:I_WERKS LIKE MARC-WERKS.
I_MATNR = '000000000001900578'.
I_WERKS = '1001'.
PDATAV = SY-DATUM+0(4) && '-' && SY-DATUM+4(2) && '-' && SY-DATUM+6(2) .
*1. 根据父物料字段,对输入BOM表排序:
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = I_MATNR
PLANT = I_WERKS
BOM_USAGE = '1'
* ALTERNATIVE = I_STLAL
VALID_FROM = PDATAV
TABLES
T_STPO = SAP_STPO
T_STPU = SAP_STPU
EXCEPTIONS
ERROR = 1
OTHERS = 2.
*2.将plm的bom格式转化为SAP能处理的单层bom,并处理(行项目新建或修改和删除的处理)
CLEAR TEMP_MAT.
CLEAR TEMP_WERKS.
I_STKO-BASE_QUAN = 1.
I_STKO-BOM_STATUS = '01'.
SELECT SINGLE DATUV INTO @DATA(LDATE1) FROM AENR WHERE AENNR = 'BG1010238'.
PDATAV = LDATE1+(4) && '-' && LDATE1+4(2) && '-' && LDATE1+6(2).
READ TABLE SAP_STPO INTO DATA(LSSTPO) WITH KEY ITM_IDENT = 'A0000002'.
CLEAR GT_STPO_INPUT[].
MOVE-CORRESPONDING LSSTPO TO GT_STPO_INPUT.
GT_STPO_INPUT-ITM_IDENT = 'A0000002'.
GT_STPO_INPUT-ID_ITEM_NO = LSSTPO-ID_ITEM_NO.
GT_STPO_INPUT-CHANGE_NO = 'BG1010238'.
GT_STPO_INPUT-VALID_FROM = PDATAV.
GT_STPO_INPUT-REL_PROD = 'X'."标识 与生产相关项目
GT_STPO_INPUT-IDENTIFIER = '2'."标识
* GT_STPO_INPUT-ITEM_NO = '9000'."INPUT_PBOM-POSNR. "项目号 默认9000
GT_STPO_INPUT-ITEM_CATEG = 'L'. "项目类别ICT 默认L
GT_STPO_INPUT-COMPONENT = 'S05139'."INPUT_PBOM-IDNRK. "组件:即子物料
GT_STPO_INPUT-COMP_QTY = 3. "数量
GT_STPO_INPUT-COMP_UNIT = 'EA'."INPUT_PBOM-MEINS'. "单位
GT_STPO_INPUT-REL_COST = 'X'. "成本核算标准相关
APPEND GT_STPO_INPUT.
* ENDIF.
I_STKO-BASE_QUAN = 1.
I_STKO-BASE_UNIT = 'EA'.
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
MATERIAL = '000000000001900578'
PLANT = '1001'
BOM_USAGE = '1' "物料清单用途 默认1
CHANGE_NO = 'BG1010238'
VALID_FROM = PDATAV
I_STKO = I_STKO
FL_COMMIT_AND_WAIT = 'X'
FL_BOM_CREATE = 'X'
FL_NEW_ITEM = 'X'
FL_COMPLETE = 'X'
TABLES
T_STPO = GT_STPO_INPUT
EXCEPTIONS
ERROR = 1
OTHERS = 2.
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 = RETURN.
WRITE:/ RETURN.