5 1 1 1 1 1 Rating 100% (1 Vote)
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.

report zabdelprbom.

parametersp_banfn type eban-banfn,
                        p_bnfpo type eban-bnfpo default '00010'.

class lcl_subcontracting definition.
  public section.
    class-methodsdelete_pr_bom importing value(i_requsition)    type eban-banfn
                                      value(i_position)      type eban-bnfpo
                                      value(i_show_messagestype abap_bool default abap_false
                            returning value(r_deleted)   type abap_bool.


      i_requsition    p_banfn
      i_position      p_bnfpo
      i_show_messages abap_true  ).

class lcl_subcontracting implementation.

    cl_message_handler_mm=>get_handler(  importing
                                         ex_handler data(message_handler).

    call function 'ME_COMPONENTS_REFRESH'.
    dataebkn     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'
        im_eban eban
        im_ebkn ebkn
        ex_mdpa mdpa.

    call function 'ME_COMPONENTS_MAINTAIN'
        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'
        im_eban eban
        im_ebkn ebkn
        ex_mdlb mdlb.
    append mdlb to mdlb_tab.

        i_number eban-banfn
        t_mdlb   mdlb_tab.

    if not line_existsmessages[ msgty 'E' ).
      r_deleted abap_true.
      commit work.
    if i_show_messages eq abap_true.
      message_handler->showim_amodal abap_true ).