Today we learn enhancement BADI-BOM_UPDATE.Tcode CS02 CS72.
It is for Saving data in interface.
Purpose:
使用TCODE:CS02/CS72更改物料BOM/WBS BOM的时候,
可以通过增强将相关信息(如订单号、更改日期等)存入自建表。
增强实现以后,使用CS02/CS72保存数据。
Trigger moment:
During tcode CS02/CS72,After clicking “Save” button.
Step:
T-code: SE19
Classic BAdI:ZBOM_AUFNR for bom_update.
Method:CHANGE_AT_SAVE
Sample Source Code:
method IF_EX_BOM_UPDATE~CHANGE_AT_SAVE.
TYPES:
BEGIN OF ty_sobsl,
stlnr TYPE mast-stlnr,
stlal TYPE mast-stlal,
matnr TYPE mast-matnr,
werks TYPE mast-werks,
sobsl TYPE marc-sobsl,
END OF ty_sobsl,
BEGIN OF ty_aufnr,
aufnr TYPE afko-aufnr,
END OF ty_aufnr,
BEGIN OF ty_itab.
INCLUDE TYPE ZDQ_PP_ORDER.
TYPES END OF ty_itab.
DATA:
it_sobsl TYPE STANDARD TABLE OF ty_sobsl,
it_sobsl1 TYPE STANDARD TABLE OF ty_sobsl,
it_sobsl2 TYPE STANDARD TABLE OF ty_sobsl,
it_itab TYPE STANDARD TABLE OF ty_itab,
it_aufnr TYPE STANDARD TABLE OF ty_aufnr,
wa_sobsl TYPE ty_sobsl,
wa_sobsl1 TYPE ty_sobsl,
wa_sobsl2 TYPE ty_sobsl,
wa_itab TYPE ty_itab,
wa_mast TYPE MASTB,
wa_aufnr TYPE ty_aufnr,
wa_prst TYPE prstb.
DATA : WULTB TYPE STANDARD TABLE OF STPOV ,
wa_tb TYPE STPOV.
CLEAR: wa_mast,
wa_prst.
READ TABLE DELTA_MASTB INTO wa_mast INDEX 1.
READ TABLE DELTA_PRSTB INTO wa_prst INDEX 1.
IF wa_mast-WERKS+0(2) = ’83’ or wa_prst-WERKS+0(2) = ’83’.
CLEAR :wa_mast,
wa_prst.
IF sy-tcode = ‘CS02’.
“取出本层的物料,HTTP://WWW.HOT583.COM
SELECT mast~matnr mast~werks mast~stlnr mast~stlal sobsl
INTO CORRESPONDING FIELDS OF TABLE it_sobsl1
FROM mast as mast
JOIN marc as marc on marc~matnr = mast~matnr
AND marc~werks = mast~werks
FOR ALL ENTRIES IN DELTA_MASTB
WHERE mast~stlnr = DELTA_MASTB-stlnr
AND mast~stlal = DELTA_MASTB-stlal.
*************循环获取上层
LOOP AT it_sobsl1 INTO wa_sobsl1.
IF wa_sobsl1-sobsl = ‘Z5’.
“取得上层物料
CALL FUNCTION ‘CS_WHERE_USED_MAT’
EXPORTING
DATUB = SY-DATUM
DATUV = SY-DATUM
MATNR = wa_sobsl1-matnr
WERKS = wa_sobsl1-werks
TABLES
WULTB = WULTB
EXCEPTIONS
CALL_INVALID = 1
MATERIAL_NOT_FOUND = 2
NO_WHERE_USED_REC_FOUND = 3
NO_WHERE_USED_REC_SELECTED = 4
NO_WHERE_USED_REC_VALID = 5
OTHERS = 6.
“根据上层物料找出特殊采购类型
IF WULTB[] IS NOT INITIAL.
CLEAR it_sobsl2.
SELECT matnr werks sobsl INTO CORRESPONDING FIELDS OF TABLE it_sobsl2
FROM marc
FOR ALL ENTRIES IN WULTB
WHERE matnr = WULTB-matnr AND werks = WULTB-werks.
“根据特殊采购类型进行归类
LOOP AT it_sobsl2 INTO wa_sobsl2.
READ TABLE WULTB INTO wa_tb with key matnr = wa_sobsl2-matnr werks = wa_sobsl2-werks.
wa_sobsl2-stlnr = wa_tb-stlnr.
wa_sobsl2-stlal = wa_tb-vwalt.
IF wa_sobsl2-sobsl = ‘Z5’.
APPEND wa_sobsl2 to it_sobsl1.
ELSE.
APPEND wa_sobsl2 to it_sobsl.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
APPEND wa_sobsl1 to it_sobsl.
delete it_sobsl1.
ENDIF.
ENDLOOP.
*************循环获取上层
ELSEIF sy-tcode = ‘CS72’.
“取出本层的物料
SELECT prst~matnr prst~werks prst~stlnr prst~stlal sobsl
INTO CORRESPONDING FIELDS OF TABLE it_sobsl1
FROM prst as prst
JOIN marc as marc on marc~matnr = prst~matnr
AND marc~werks = prst~werks
FOR ALL ENTRIES IN DELTA_PRSTB
WHERE prst~stlnr = DELTA_PRSTB-stlnr
AND prst~stlal = DELTA_PRSTB-stlal.
*************循环获取上层
LOOP AT it_sobsl1 INTO wa_sobsl1.
IF wa_sobsl1-sobsl = ‘Z5’.
“去上层物料
CALL FUNCTION ‘CS_WHERE_USED_MAT‘
EXPORTING
DATUB = SY-DATUM
DATUV = SY-DATUM
MATNR = wa_sobsl1-matnr
WERKS = wa_sobsl1-werks
TABLES
WULTB = WULTB
EXCEPTIONS
CALL_INVALID = 1
MATERIAL_NOT_FOUND = 2
NO_WHERE_USED_REC_FOUND = 3
NO_WHERE_USED_REC_SELECTED = 4
NO_WHERE_USED_REC_VALID = 5
OTHERS = 6.
“根据上层物料找出特殊采购类型
IF WULTB[] IS NOT INITIAL.
CLEAR it_sobsl2.
SELECT matnr werks sobsl INTO CORRESPONDING FIELDS OF TABLE it_sobsl2
FROM marc
FOR ALL ENTRIES IN WULTB
WHERE matnr = WULTB-matnr AND werks = WULTB-werks.
“根据特殊采购类型进行归类
LOOP AT it_sobsl2 INTO wa_sobsl2.
READ TABLE WULTB INTO wa_tb with key matnr = wa_sobsl2-matnr werks = wa_sobsl2-werks.
wa_sobsl2-stlnr = wa_tb-stlnr.
wa_sobsl2-stlal = wa_tb-vwalt.
IF wa_sobsl2-sobsl = ‘Z5’.
APPEND wa_sobsl2 to it_sobsl1.
ELSE.
APPEND wa_sobsl2 to it_sobsl.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
APPEND wa_sobsl1 to it_sobsl.
delete it_sobsl1.
ENDIF.
ENDLOOP.
*************循环获取上层
ENDIF.
*针对 it_sobsl中数据查找生产订单
IF it_sobsl IS NOT INITIAL.
SELECT afko~aufnr INTO CORRESPONDING FIELDS OF TABLE it_aufnr
FROM afko as afko
JOIN aufk as aufk on aufk~aufnr = afko~aufnr
FOR ALL ENTRIES IN it_sobsl
WHERE stlnr = it_sobsl-stlnr AND stlal = it_sobsl-stlal
AND ( auart = ‘DQ10’ OR auart = ‘DQ20’ )
AND phas2 <> ‘X’ AND phas3 <> ‘X’.
ENDIF.
* 保存到自建表里面去
LOOP AT it_aufnr INTO wa_aufnr.
CLEAR wa_itab.
wa_itab-mandt = sy-mandt.
wa_itab-ywlx = ‘BOM变更’.
wa_itab-aufnr = wa_aufnr-aufnr.
wa_itab-updats = sy-datum.
“取流水号
CALL FUNCTION ‘NUMBER_GET_NEXT’
EXPORTING
nr_range_nr = ’01’
object = ‘ZDQPP67XH’
IMPORTING
number = wa_itab-xh
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 7
OTHERS = 8.
APPEND wa_itab to it_itab.
ENDLOOP.
MODIFY ZDQ_PP_ORDER FROM TABLE it_itab.
ENDIF.
* ENDIF.
endmethod.
我的微信公众号【 hot583 】 或者在这个链接联系我
本文链接 :http://www.hot583.com/2022/06/24/bom_update/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
微信原文《全文完》