
I am very happy to share my first blog post on SAP ABAP Bill of Material (BOM) components changes Without Changing or Deleting the header information,
What is Bill of Material:
Bill of material (BOM) is a formally combination of components that make a finished product,
As like this we have multiple components in a Product, all these components again having a chance to became an product, in Above Example Mother board is a component of Laptop,
For Motherboard: CPU,storage,ROM,chipsets etc.. are the components this type of BOM we call it as Multi level BOM,
How to Update or Delete an Components using CSAP_MAT_BOM_MAINTAIN.
1. Create a Report Program using se38.
2. Declare all the work area and internal tables as below
3. Take selection screen inputs to for the BOM header details and select the line no to update or delete the Bom
4. After getting the inputs from the selection screen read the BOM details USING CSAP_MAT_BOM_READ it will provide all the header and component details to process further
CASE: 1 HOW TO CHANGE THE COMPONENTS
In delete case read the component with item number after reading the material pass all the ID Fields as mentioned above for changed scenario along with that pass one more Flag value FLDELETE = abap_true in STOP_API03 structure this falg will takes that component suppose to delete.
Below is the source code for both the scenarios
REPORT zupdate_bom_components.
DATA : lt_stpo TYPE TABLE OF stpo_api03,
lt_stpo_old TYPE TABLE OF stpo_api03,
lt_stko TYPE TABLE OF stko_api02,
lt_stko_input TYPE TABLE OF stko_api01,
lv_matnr TYPE matnr,
lv_plant TYPE werks_d,
lv_usage TYPE stlan,
fl_warnign TYPE capiflag-flwarning.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_matnr TYPE matnr,
p_plant TYPE werks,
P_Usage TYPE stlan.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
PARAMETERS : P_Itemno TYPE sposn.
PARAMETERS: Change TYPE c RADIOBUTTON GROUP m1 USER-COMMAND chg,
delete TYPE c RADIOBUTTON GROUP m1.
SELECTION-SCREEN END OF BLOCK b2.
lv_matnr = p_matnr.
lv_plant = p_plant.
lv_usage = p_usage.
START-OF-SELECTION.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
material = lv_matnr
plant = lv_plant
bom_usage = lv_usage
IMPORTING
fl_warning = fl_warnign " this says if this API having any warning messages
TABLES
t_stpo = lt_Stpo_old
t_stko = lt_stko
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno " this is display the system message automatically when ever exceptions are hit
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
** after succesfull reading the existing bom details
IF change EQ abap_true.
* check the line number of bom component want to change and read the component from old component getting from above fm (lt_stpo_old)
READ TABLE lt_Stpo_old INTO DATA(ls_stpo_old) WITH KEY item_no = p_itemno.
IF sy-subrc EQ 0. "" change the proparties of all the selected item and store it to an final internal table
ls_stpo_old-comp_qty = '100'.
ls_stpo_old-item_text1 = 'Chaneged item text 1'.
ls_stpo_old-item_text2 = 'Chaneged item text 2'.
"" Along with al the changed proparties pass the "ID fields as below"
ls_stpo_old-id_item_no = ls_stpo_old-item_no.
ls_stpo_old-id_comp = ls_stpo_old-component.
ls_stpo_old-id_itm_ctg = ls_stpo_old-item_categ.
APPEND ls_stpo_old TO lt_stpo.
ELSE.
MESSAGE 'component does not exist for the selected line' TYPE 'E'.
ENDIF.
ELSEIF delete EQ abap_true.
READ TABLE lt_stpo_old INTO ls_stpo_old WITH KEY item_no = p_itemno.
IF Sy-subrc = 0.
ls_stpo_old-id_item_no = ls_stpo_old-item_no.
ls_stpo_old-id_comp = ls_stpo_old-component.
ls_stpo_old-id_itm_ctg = ls_stpo_old-item_categ.
ls_stpo_old-fldelete = abap_true.
APPEND ls_stpo_old TO lt_stpo.
ENDIF.
ENDIF.
"" read header details from the lt_stko and pass it into below function module
MOVE-CORRESPONDING lt_stko TO lt_stko_input.
READ TABLE lt_stko_input INTO DATA(ls_stko) INDEX 1. ""
IF sy-subrc = 0.
"" call the standerd function module to update all the line items without changing the header of an BOM.
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
material = lv_matnr
plant = lv_plant
bom_usage = 'P'
valid_from = '10.05.2024'
fl_commit_and_wait = 'x'
i_stko = ls_stko
TABLES
t_stpo = lt_stpo
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno " this is display the system message automatically when ever exceptions are hit
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
COMMIT WORK.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno "" success message after commit work.
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 |