report zabdelprbom.
parameters: p_banfn type eban-banfn,
p_bnfpo type eban-bnfpo default '00010'.
class lcl_subcontracting definition.
public section.
class-methods: delete_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_deleted) type abap_bool.
endclass.
start-of-selection.
lcl_subcontracting=>delete_pr_bom(
i_requsition = p_banfn
i_position = p_bnfpo
i_show_messages = abap_true ).
class lcl_subcontracting implementation.
method: delete_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 * into corresponding fields of eban
from eban
where banfn eq i_requsition
and bnfpo eq i_position.
select single * from ebkn into 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 = 'D'.
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 not line_exists( messages[ msgty = 'E' ] ).
r_deleted = abap_true.
commit work.
endif.
if i_show_messages eq abap_true.
message_handler->show( im_amodal = abap_true ).
endif.
endmethod.
endclass.
Deletion of subcontracting BOM in Purchase Requisition
In previous post I've shown how to re-explode subcontracting components of purchase requisition using FM ME_COMPONENTS_MAINTAIN and ME_COMPONENTS_UPDATE_PREPARE . Using very similar code you can delete completly it's BOM.
You may wonder why would need to delete subcontracting BOM? This is not possible in standard transaction ME52N and in most cases it makes no sense to have the subcontracting item without BOM. But in the case that you don't want that components are taken into consideration by MRP until you really need this then it could be helpful.
The code is 99% same like during the re-exploding the BOM, the difference is that FM ME_COMPONENTS_MAINTAIN is called with parameter i_vorga = 'D' and message check at the end is bit different.
Enjoy!