Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
naveenm0607
Discoverer
0 Kudos
1,386

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,

  • Example --> I have one laptop as my product,
  1. Keyboard is one of the Component
  2. Mother Board is my second component
  3. Screen is my Third component 

      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.

naveenm0607_0-1721301913429.png

2. Declare all the work area and internal tables as below

naveenm0607_1-1721301913432.png

 

3. Take selection screen inputs to for the BOM header details and select the line no to update or delete the Bom

naveenm0607_2-1721301913436.png

naveenm0607_3-1721301913437.png

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

naveenm0607_4-1721301913440.png

CASE: 1 HOW TO CHANGE THE COMPONENTS

  • After successful Reading an Existing Bom details process the line item,
  • As Above function module is giving all the line items read that table with our line-item number and get that particular component and change the properties of that selected component,
  •  In below case we are changing the quantity and item text 1 and item text 2.
  • Along with that in STOP_API03 Structure we have ID fields to identify the specific component user wants to change, pass these id_item_no, id_comp, id_itm_ctg,
  • After passing above parameter append the work area into final internal table to collect all the changed components

naveenm0607_5-1721301913442.png

 

  • CASE: 2  HOW TO DELETE 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.

naveenm0607_6-1721301913444.png

 

  • After passing above fields append the work area into final internal table,
  • Call the Function module CSAP_MAT_BOM_MAINTAIN and pass the final stop and header information.
  • after successful execution of Function module call commit work.

naveenm0607_0-1721369610954.png

  • We will get success message as mentioned below.

naveenm0607_8-1721301913451.png

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.

 

 

 

 

Labels in this area