report zabexpldelpobom.
parameters: p_ebeln type ekpo-ebeln,
p_ebelp type ekpo-ebelp default '00010'.
parameters: p_expl radiobutton group gr1 default 'X',
p_del radiobutton group gr1.
class lcl_subcontracting definition.
public section.
constants: action_delete type c value 'D',
action_explode type c value 'M'.
class-methods: explode_po_bom importing value(i_order) type ebeln
value(i_position) type ebelp
value(i_show_messages) type abap_bool default abap_false
returning value(r_re_exploded) type abap_bool.
class-methods: delete_po_bom importing value(i_order) type ebeln
value(i_position) type ebelp
value(i_show_messages) type abap_bool default abap_false
returning value(r_deleted) type abap_bool.
class-methods: call_components_update importing value(i_order) type ebeln
value(i_position) type ebelp
value(i_show_messages) type abap_bool default abap_false
value(i_action_type) type c
returning value(r_messages) type mepo_t_messages_bapi ,
prepare_po_mdpa
importing
value(i_order) type ebeln
value(i_position) type ebelp
exporting
value(e_mdpa) type mdpa
value(e_mdlb) type mdlb.
endclass.
start-of-selection.
if p_expl eq abap_true.
lcl_subcontracting=>explode_po_bom(
i_order = p_ebeln
i_position = p_ebelp
i_show_messages = abap_true ).
elseif p_del eq abap_true.
lcl_subcontracting=>delete_po_bom(
i_order = p_ebeln
i_position = p_ebelp
i_show_messages = abap_true ).
endif.
class lcl_subcontracting implementation.
method call_components_update.
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: ekpo type ekpo,
mdpa type mdpa,
mdlb type mdlb,
mdlb_tab type standard table of mdlb.
select single * into corresponding fields of ekpo
from ekpo
where ebeln eq i_order
and ebelp eq i_position.
prepare_po_mdpa( exporting i_order = i_order i_position = i_position
importing e_mdpa = mdpa e_mdlb = mdlb ).
check mdpa is not initial and mdlb is not initial.
append mdlb to mdlb_tab.
call function 'ME_COMPONENTS_MAINTAIN'
exporting
i_ebeln = i_order
i_ebelp = i_position
i_fcall = abap_true
i_mdpa = mdpa
i_mdpa_old = mdpa
i_txz01 = ekpo-txz01
i_vorga = i_action_type.
call function 'ME_COMPONENTS_UPDATE_PREPARE'
exporting
i_number = i_order
tables
t_mdlb = mdlb_tab.
message_handler->co_handler_stop( ).
r_messages = message_handler->get_list_for_bapi( ).
commit work.
if i_show_messages eq abap_true.
message_handler->show( im_amodal = abap_true ).
endif.
endmethod.
method prepare_po_mdpa.
data: header type mepoheader,
item type mepoitem,
schedule type meposchedule,
eban type eban,
mt06e type mt06e,
float type f,
t001w type t001w,
accounting type mepoaccounting,
order_handle type ref to cl_po_header_handle_mm,
order type ref to if_purchase_order_mm.
order_handle = new cl_po_header_handle_mm( im_po_number = i_order ).
order_handle->po_initialize( ).
order_handle->po_read(
exporting
im_tcode = 'ME23N'
im_trtyp = 'A' " Transaction Type
im_aktyp = 'A' " Activity Category
im_po_number = i_order " Document Number
importing
ex_result = data(po_was_read)
).
check po_was_read eq abap_true.
order ?= order_handle.
header = order->get_data( ).
data(items) = order->get_items( ).
loop at items assigning field-symbol(<item>).
item = <item>-item->get_data( ).
if item-ebelp eq i_position.
exit.
else.
clear item.
endif.
endloop.
check item is not initial and item-sobkz eq 'L'.
data(schedule_lines) = <item>-item->get_schedules( ).
loop at schedule_lines assigning field-symbol(<schline>).
schedule = <schline>-schedule->get_data( ).
exit.
endloop.
check item-attyp ne cl_mmpur_constants=>attyp_01. "no generic article
* populate mdpa structure
clear: e_mdpa, e_mdlb.
e_mdlb-ebeln = i_order.
e_mdlb-ebelp = i_position.
e_mdlb-kzbws = item-kzbws.
e_mdpa-matnr = item-matnr.
e_mdpa-pwwrk = item-werks.
e_mdpa-lgort = item-lgort.
e_mdpa-paart = header-bsart.
e_mdpa-beskz = 'F'.
e_mdpa-sobes = cl_mmpur_constants=>pstyp_3.
e_mdpa-gsmng = schedule-menge.
e_mdpa-flief = header-lifnr.
if item-meins ne item-lmein and not item-lmein is initial.
e_mdpa-gsmng = float = schedule-menge * item-umrez / item-umren.
endif.
e_mdpa-lagme = item-lmein.
if e_mdpa-lagme is initial and e_mdpa-matnr is initial.
e_mdpa-lagme = item-meins.
endif.
if schedule-eindt is initial.
e_mdpa-psttr = header-bedat.
else.
*-- reference to requisition-----------------------------------------*
if schedule-banfn ne space.
call function 'MEREQS_EBAN_LOOKUP'
exporting
im_banfn = schedule-banfn
im_bnfpo = schedule-bnfpo
importing
ex_eban = eban
exceptions
failure = 1.
endif.
*-- if requisition is created from prod. order ----*
*-- or from planned order and delivery date has not changed, ----*
*-- take over release date from the requisition ----*
if schedule-banfn ne space and
( eban-estkz = cl_mmpur_constants=>estkz_f or
eban-estkz = cl_mmpur_constants=>estkz_u )
and eban-lfdat eq schedule-eindt.
e_mdpa-psttr = eban-frgdt.
else.
call function 'MEX_READ_T001W'
exporting
im_werks = item-werks
importing
ex_t001w = t001w
exceptions
not_found = 1
others = 2.
if sy-subrc <> 0.
clear: e_mdpa, e_mdlb.
return.
endif.
call function 'ME_COMP_REQUIREMENT_DATE'
exporting
im_plant = item-werks
im_factory_calendar = t001w-fabkl
im_delivery_date = schedule-eindt
im_planned_del_time = item-plifz
importing
ex_requirement_date = e_mdpa-psttr.
if sy-subrc <> 0. "#EC *
clear: e_mdpa, e_mdlb.
return.
endif.
endif.
endif.
e_mdpa-pedtr = schedule-eindt.
e_mdpa-knttp = item-knttp.
e_mdpa-sobkz = item-sobkz.
e_mdpa-kzvbr = item-kzvbr.
e_mdpa-kzbws = item-kzbws.
e_mdpa-revlv = item-revlv.
e_mdpa-sernr = schedule-sernr.
e_mdpa-rsnum = schedule-rsnum.
e_mdpa-cuobj = item-cuobj.
* e_mdpa-verid = order_handle->verid.
* read material data
if not item-werks is initial.
call function 'ME_READ_MT06E'
exporting
i_matnr = item-matnr
i_werks = item-werks
importing
e_mt06e = mt06e
exceptions
others = 1.
endif.
e_mdpa-altsl = mt06e-altsl.
if item-knttp ne space and item-kzvbr ne 'U'.
* get accounting data
data(accounts) = <item>-item->get_accountings( ).
if lines( accounts ) eq 1.
assign accounts[ 1 ] to field-symbol(<acc>).
if sy-subrc is initial and not <acc> is initial.
accounting = <acc>-accounting->get_data( ).
endif.
e_mdpa-aufpl_ord = accounting-aufpl_ord.
e_mdpa-aplzl_ord = accounting-aplzl_ord.
* Account assignment data for make to order
if e_mdpa-sobkz eq cl_mmpur_constants=>sobkz_e or
e_mdpa-sobkz eq cl_mmpur_constants=>sobkz_q.
e_mdpa-kdauf = accounting-vbeln.
e_mdpa-kdpos = accounting-vbelp.
e_mdpa-kdein = accounting-veten.
e_mdpa-pspel = accounting-ps_psp_pnr.
e_mdlb-kdauf = accounting-vbeln.
e_mdlb-kdpos = accounting-vbelp.
e_mdlb-kdein = accounting-veten.
e_mdlb-pspel = accounting-ps_psp_pnr.
endif.
endif.
endif.
endmethod.
method explode_po_bom.
data(messages) = call_components_update(
i_order = i_order
i_position = i_position
i_show_messages = i_show_messages
i_action_type = action_explode
).
if line_exists( messages[ msgid = 'ME' msgno = '638' ] ).
r_re_exploded = abap_true.
endif.
endmethod.
method delete_po_bom.
data(messages) = call_components_update(
i_order = i_order
i_position = i_position
i_show_messages = i_show_messages
i_action_type = action_delete
).
if not line_exists( messages[ msgty = 'E' ] ).
r_deleted = abap_true.
endif.
endmethod.
endclass.
Re-explode or delete purchase order line subcontracting BOM
To continue previous two posts about re-exploding and deleting subcontracting BOM of purchase requisition item, let me describe you how to do the same thing with subcontracting BOM of purchase order line.
The main part is again to use FM ME_COMPONENTS_MAINTAIN and ME_COMPONENTS_UPDATE_PREPARE , but this time there is no easy way to fill MDPA and MDLB structures which are needed here.
So I had to use CL_PO_HEADER_HANDLE_MM and IF_PURCHASE_ORDER_MM to fetch all data from purchase order and to move them to MDPA and MDLB structures. Once it was ready the rest was peanuts and I could get rid of using this two buttons :-)
Enjoy!