Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Getting the Parent Material (BOM)

Former Member
0 Likes
3,511

Hi Experts,

Is there a function that returns the parent

material of the component, not the immediate ancestor

but the PARENT (root) level of the BOM.

Thanks for your help.

Best regards,

Rose

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,214

You can use the function module CS_WHERE_USED_MAT. You will need to loop and do this function call over and over untill you get to the top level.

Regards,

Rich Heilman

Hi Experts,

Is there a function that returns the parent

material of the component, not the immediate ancestor

but the PARENT (root) level of the BOM.

Thanks for your help.

Best regards,

Rose

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,215

You can use the function module CS_WHERE_USED_MAT. You will need to loop and do this function call over and over untill you get to the top level.

Regards,

Rich Heilman

Read only

0 Likes
2,214

This sample program may be of some help. I fear that this may run a very long time depending on your BOM structure, if it is very complex and deep, then this will take a while, but if it is small like 1 for 1 for 1, then it should work fine.



report zrich_0001 .

data: begin of iitems occurs 0,
      matnr type marc-matnr,
      werks type marc-werks,
      end of iitems.

data: i_stpov type table of stpov with header line.

parameters: p_matnr type marc-matnr,
            p_werks type marc-werks.

start-of-selection.

  iitems-matnr = p_matnr.
  iitems-werks = p_werks.
  append iitems.


  loop at iitems.

    perform where_used tables i_stpov
                       using iitems-matnr
                             iitems-werks.
    if not i_stpov[] is initial.
      loop at i_stpov.
        iitems-matnr = i_stpov-matnr.
        iitems-werks = i_stpov-werks.
        append iitems.
      endloop.
      delete iitems.
    else.
     continue.
    endif.

  endloop.

  loop at iitems.
    write:/ iitems-matnr, iitems-werks.
  endloop.



************************************************************************
*  FORM WHERE_USED.
************************************************************************
form where_used tables itab
                using  matnr
                       werks.

  data: selpool like mc29s.
  data: eqpcat  like cscequi occurs 0.
  data: kndcat  like cscknd  occurs 0.
  data: matcat  like cscmat  occurs 0.
  data: prjcat  like cscprj  occurs 0.
  data: stdcat  like cscstd  occurs 0.
  data: tplcat  like csctpl  occurs 0.

  clear itab. refresh itab.
  call function 'CS_WHERE_USED_MAT'
       exporting
            datub                      = sy-datum
            datuv                      = sy-datum
            matnr                      = matnr
            postp                      = ' '
            stlan                      = ' '
            werks                      = werks
            stltp                      = ' '
       importing
            topmat                     = selpool  "Not Currently Used
       tables
            wultb                      = itab
            equicat                    = eqpcat  "Not Currently Used
            kndcat                     = kndcat  "Not Currently Used
            matcat                     = matcat  "Not Currently Used
            stdcat                     = stdcat  "Not Currently Used
            tplcat                     = tplcat  "Not Currently Used
            prjcat                     = prjcat  "Not Currently Used
       exceptions
            material_not_found         = 02
            no_where_used_rec_found    = 03
            no_where_used_rec_selected = 04
            no_where_used_rec_valid    = 05.

endform.

Regards,

Rich Heilman

Read only

0 Likes
2,214

Hi Rich,

The code is helpful but I get more than one parent

material. Is there a way to get the parent material

depending on which project it is being used?.

What I actually need is just the parent material

of the components which have project stocks.

I was able to get the project stock using

the table MSPR but I also need to get the

parent of these components. The parent of the

component should be the one which exists in network

order. (in Transaction CJ20). I was able to manually look trace the parent materiall using MD04, choose

procject stock then show the pegged requirements.

Maybe you know a better way to do it?

Thank you so very very much for your help.

Best Regards,

Rose

Read only

0 Likes
2,214

Getting multple parents is the basic functionality of the WHERE USED function module, because your component can reside in any number of BOMs. If you have specific requirements to narrow down to one specific parent, then you will need to come up with the logic, but you should still use the function module i have suggested.

Please make sure to award points for helpful answers.

Regards,

Rich Heilman

Read only

srinivas_akiri
Active Participant
0 Likes
2,214

Hi,

try with function module BOM_HIERARCHY .

in the table parameters we can get the materials involved in this BOM and their level indicator in STUFE field, by checking this we can find the top-most level material.