I faced lately a small issue in one of the process in our company, I needed to re-explode the BOM of subcontracting item I n Purchase requisition. Normally users goes to me52n and press ' Explode BOM ' button, but I needed-do this from ABAP side. I started with if_purchase_requisition but although there are a method "Explode_bom" for item and then it was calling the SCR Een with the results instead of selecting and updating on the database. IF_BOM_MM didn ' t helped as well. I started to dig in the standard transactions and local classes of me52n and finally I had the figure out how to does this in B Ackgroud. The solution is to run FM Me_components_maintain and Me_components_update_prepare in correct is together with message Handler to not interrupt whole process. Here's the can find sample code how to Re-explode purchase requisition BOM in few lines.
Report Zabexplprbom.
PARAMETERS:P_BANFN type EBAN-BANFN,
P_BNFPO type Eban-bnfpo default ' 00010 '.
Class lcl_subcontracting definition.
Public section.
Class-methods:explode_pr_bom Importing Value (i_requsition) type EBAN-BANFN
Value (i_position) type Eban-bnfpo
Value (i_show_messages) type Abap_bool default Abap_false
Returning value (r_re_exploded) type Abap_bool.
Endclass.
Start-of-selection.
Lcl_subcontracting=>explode_pr_bom (
I_requsition = P_banfn
I_position = P_bnfpo
I_show_messages = abap_true).
Class lcl_subcontracting implementation.
Method:explode_pr_bom.
Cl_message_handler_mm=>get_handler (Importing
Ex_handler = data (Message_handler)).
Message_handler->co_handler_start ().
Message_handler->set_config_for_bapi ().
Call function ' Me_components_refresh '.
DATA:EBKN type EBKN,
Eban type Eban,
MDPA type MDPA,
MDLB type MDLB,
Mdlb_tab type standard table of MDLB.
Select Single * to corresponding fields of Eban
From Eban
where BANFN eq i_requsition
and Bnfpo eq i_position.
Select Single * from EBKN to EBKN
where BANFN eq i_requsition
and Bnfpo eq i_position.
Call function ' Me_fill_mdpa_from_eban '
Exporting
Im_eban = Eban
IM_EBKN = EBKN
Importing
EX_MDPA = MDPA.
Call function ' Me_components_maintain '
Exporting
I_ebeln = Eban-banfn
I_ebelp = Eban-bnfpo
I_fcall = Abap_true
I_MDPA = MDPA
I_mdpa_old = MDPA
I_TXZ01 = eban-txz01
I_vorga = ' M '.
Call function ' Me_fill_mdlb_from_eban '
Exporting
Im_eban = Eban
IM_EBKN = EBKN
Importing
EX_MDLB = mdlb.
Append mdlb to Mdlb_tab.
Call function ' Me_components_update_prepare '
Exporting
I_number = Eban-banfn
Tables
T_MDLB = Mdlb_tab.
Message_handler->co_handler_stop ().
Data (Messages) = Message_handler->get_list_for_bapi ().
If line_exists (messages[msgid = ' ME ' Msgno = ' 638 ']).
r_re_exploded = Abap_true.
Commit work.
endif.
If I_show_messages eq abap_true.
Message_handler->show (Im_amodal = abap_true).
endif.
EndMethod.
Endclass.