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

BOM function module to find sub components

Former Member
0 Likes
3,279

Hi all ,

I got a requirement . I have to find out the components required for a given product .Like if A is made up of X,Y and Z . If i have A , a final product , then how could i know its sub components X,Y and Z .

Is there any Function module .

Regards ,

Raj

7 REPLIES 7
Read only

Former Member
0 Likes
1,683

You can use:


        CALL FUNCTION 'CS_BOM_EXPLOSION'
          EXPORTING
            capid                 = 'PP01'
            datuv                 = sy-datum
            mehrs                 = 'X'
            mtnrv                 = i_conf-materialnr
            stlal                 =   alt_bom
            werks                 = i_conf-prodplant
            verid                 =   i_conf-prodversion
          TABLES
            stbd                  = i_stbd
            stbe                  = i_stbe
            stbk                  = i_stbk
            stbm                  = i_stbm
            stbp                  = i_stbp
            stbt                  = i_stbt
          EXCEPTIONS
            alt_not_found         = 1
            call_invalid          = 2
            missing_authorization = 3
            no_bom_found          = 4
            no_plant_data         = 5
            no_suitable_bom_found = 6
            object_not_found      = 7
            conversion_error      = 8
            OTHERS                = 9.

Read only

0 Likes
1,683

Aparna,

One doubt.Does the function module metioned by you will even explode if a Component under the header material is having a sub-assembly which again is having some components and those componenets also have sub-assembly so on....

I mean in one shot if we give the header material it should explode all the BOMS of the corresponding components.

We have developed a small program kindly have a look at it.Does this whole program can be replaced by that function module alone?

As we need supply area w.r.t a component under header material we are displaying only those fields in the output.


REPORT ZBOMEXPLOSION.
TABLES: MBEW,
        MARA, "Material Master
        MAKT,
        MARC,
        MAST, "BOM Header
        STKO, "BOM Detail
        STPO, "Bom Components
        STAS. "BOM Alternative


*Declarations for ALV
type-pools slis.
DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA:itrepid TYPE sy-repid.
itrepid = sy-repid.
DATA:itevent TYPE slis_t_event.
DATA:itlistheader TYPE slis_t_listheader.
DATA:walistheader LIKE LINE OF itlistheader.
DATA:itlayout TYPE slis_layout_alv.
DATA:top TYPE slis_formname.
DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
DATA :itsort1 TYPE slis_sortinfo_alv.
DATA:itprintparams TYPE slis_print_alv.
DATA:itvariant TYPE disvariant.
data : title type lvc_title.
field-symbols <fs> type LVC_TITLE.
concatenate 'BOM Explosion level by level' ' ' into title separated by
space.
assign title to <fs>.


DATA:PARENT-MATNR LIKE MAST-MATNR,
CHILD-MATNR LIKE STPO-IDNRK,
CHILD-WERKS LIKE MAST-WERKS,
CHILD-STLAL LIKE MAST-STLAL,
W_MAKTX LIKE MAKT-MAKTX,
W_LEVEL TYPE I,
W_DOT(1),
W_LVL(12),
W_LVL1(12),
W_LVL2(2),
WCNT TYPE I.

DATA: BEGIN OF ITAB OCCURS 100,
CNT TYPE I,
LEVEL TYPE I,
LVL1 LIKE W_LVL1,
WERKS LIKE MAST-WERKS,
POSNR LIKE STPO-POSNR,
IDNRK LIKE STPO-IDNRK,
PRVBE LIKE STPO-PRVBE,
END OF ITAB.


DATA: BEGIN OF ITAB1 OCCURS 100,
WERKS LIKE MAST-WERKS,
IDNRK LIKE STPO-IDNRK,
END OF ITAB1.

DATA: BEGIN OF ITAB2 OCCURS 100,
CNT TYPE I,
SUBCNT TYPE I,
LEVEL TYPE I,
LVL1 LIKE W_LVL1,
WERKS LIKE MAST-WERKS,
POSNR LIKE STPO-POSNR,
IDNRK LIKE STPO-IDNRK,
prvbe like stpo-prvbe,
SBASE TYPE P,
MAKTX LIKE MAKT-MAKTX,
END OF ITAB2.




PARAMETERS: P_WERKS LIKE MAST-WERKS,
            P_MATNR LIKE MAST-MATNR,
            P_STLNR LIKE MAST-STLNR,
            P_STLAN LIKE MAST-STLAN,
            P_STLAL LIKE MAST-STLAL.

perform zmm.
perform alv.

*&---------------------------------------------------------------------*
*&      Form  zmmspt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form zmm .
SELECT * FROM MAST WHERE WERKS = P_WERKS
                     AND MATNR = P_MATNR
                     AND STLNR = P_STLNR
                     AND STLAN = P_STLAN
                     AND STLAL = P_STLAL.
SELECT SINGLE * FROM MARA WHERE MATNR = MAST-MATNR.
IF SY-SUBRC NE 0.
CONTINUE.
ENDIF.
IF MARA-LVORM <> 'X'.
PARENT-MATNR = MAST-MATNR.
CHILD-MATNR = MAST-MATNR.
CHILD-WERKS = MAST-WERKS.
CHILD-STLAL = MAST-STLAL.
CLEAR ITAB.
CLEAR ITAB-LEVEL.
MOVE MAST-WERKS TO ITAB-WERKS.
MOVE MAST-MATNR TO ITAB-IDNRK.
WCNT = WCNT + 1.
MOVE WCNT TO ITAB-CNT.
APPEND ITAB.
W_LEVEL = 1.
PERFORM GETCHILD.
ENDIF.
ENDSELECT.
SORT ITAB BY LEVEL DESCENDING.
LOOP AT ITAB.
PERFORM GET_BOM.
MOVE ITAB-WERKS TO ITAB1-WERKS.
MOVE ITAB-IDNRK TO ITAB1-IDNRK.
APPEND ITAB1.
CLEAR ITAB2.
MOVE-CORRESPONDING ITAB TO ITAB2.
APPEND ITAB2.
ENDLOOP.
SORT ITAB2 BY CNT.
LOOP AT ITAB2.
CLEAR: MAKT-MAKTX.
SELECT SINGLE * FROM MAKT WHERE MATNR = ITAB2-IDNRK AND
SPRAS = 'E'.
SELECT SINGLE * FROM MBEW WHERE MATNR = ITAB2-IDNRK AND
BWKEY = ITAB2-WERKS.
ITAB2-MAKTX = MAKT-MAKTX.
MODIFY ITAB2.
ENDLOOP.

endform.                    " zmm

*&---------------------------------------------------------------------*
*&      Form  GETCHILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GETCHILD .
SELECT * FROM STPO WHERE STLNR = MAST-STLNR
ORDER BY POSNR.
SELECT SINGLE * FROM STKO WHERE STLNR = STPO-STLNR
AND STLAL = MAST-STLAL.
SELECT SINGLE * FROM STAS WHERE STLNR = STPO-STLNR AND
STLKN = STPO-STLKN AND
STLAL = MAST-STLAL.
IF SY-SUBRC EQ 0.
CLEAR: W_DOT, W_LVL, W_LVL1.
PERFORM MOV_DATA.
CHILD-MATNR = STPO-IDNRK.
W_LEVEL = W_LEVEL + 1.
PERFORM SUBCHILD.
W_LEVEL = W_LEVEL - 1.
ENDIF.
ENDSELECT.
endform.                    " GETCHILD


*&---------------------------------------------------------------------*
*&      Form  SUBCHILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SUBCHILD .
SELECT SINGLE * FROM MAST WHERE MATNR = CHILD-MATNR
AND WERKS = CHILD-WERKS.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
SELECT * FROM STPO WHERE STLNR = MAST-STLNR
ORDER BY POSNR.
SELECT SINGLE * FROM STKO WHERE STLNR = STPO-STLNR AND
STLAL = MAST-STLAL.
SELECT SINGLE * FROM STAS WHERE STLNR = STPO-STLNR AND
STLKN = STPO-STLKN AND
STLAL = STKO-STLAL.
IF SY-SUBRC EQ 0.
W_DOT = '.'.
PERFORM MOV_DATA.
CHILD-MATNR = STPO-IDNRK.
W_LEVEL = W_LEVEL + 1.
PERFORM SUBCHILD.
W_LEVEL = W_LEVEL - 1.
SHIFT W_LVL.
ENDIF.
ENDSELECT.
endform.                    " SUBCHILD

*&---------------------------------------------------------------------*
*&      Form  MOV_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form MOV_DATA .
W_LVL2 = W_LEVEL.
CONCATENATE W_DOT W_LVL INTO W_LVL.
CONCATENATE W_LVL W_LVL2 INTO W_LVL1.
MOVE W_LVL1 TO ITAB-LVL1.
MOVE W_LEVEL TO ITAB-LEVEL.
MOVE MAST-WERKS TO ITAB-WERKS.
MOVE STPO-POSNR TO ITAB-POSNR.
MOVE STPO-IDNRK TO ITAB-IDNRK.
MOVE STPO-PRVBE TO ITAB-PRVBE.
WCNT = WCNT + 1.
ITAB-CNT = WCNT.
APPEND ITAB.
endform.                    " MOV_DATA

*&---------------------------------------------------------------------*
*&      Form  GET_BOM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_BOM .
SELECT SINGLE * FROM MAST WHERE MATNR EQ ITAB-IDNRK AND
WERKS = ITAB-WERKS.
IF SY-SUBRC EQ 0.
SELECT * FROM STPO WHERE STLTY = 'M' AND
STLNR = MAST-STLNR AND
DATUV LE SY-DATUM.
SELECT SINGLE * FROM STKO WHERE STLTY = 'M' AND
STLNR = STPO-STLNR AND
STLAL = MAST-STLAL.
SELECT SINGLE * FROM STAS WHERE STLNR = STPO-STLNR AND
STLKN = STPO-STLKN AND
STLAL = STKO-STLAL.
ENDSELECT.
ENDIF.
endform.                    " GET_BOM

*&---------------------------------------------------------------------*
*&      Form  alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form alv .
IF itab2[] IS INITIAL.
MESSAGE 'No Values exist for the Selection.' TYPE 'S'.
STOP.
ENDIF.

DEFINE m_fieldcat.
    itfieldcat-fieldname = &1.
    itfieldcat-col_pos = &2.
    itfieldcat-seltext_l = &3.
    itfieldcat-do_sum = &4.
    itfieldcat-outputlen = &5.
    append itfieldcat to itfieldcat.
    clear itfieldcat.
  END-OF-DEFINITION.

  m_fieldcat 'LVL1' '' 'Level' '' 04.
  m_fieldcat 'POSNR' '' 'Item' '' 06.
  m_fieldcat 'IDNRK' '' 'Component' '' 18.
  m_fieldcat 'MAKTX' '' 'Description'  '' 40.
  m_fieldcat 'PRVBE' '' 'Supply Area' '' 12.


  itlayout-zebra = 'X'.
  itlayout-colwidth_optimize = 'X'.
  itlayout-no_subtotals = ' '.


  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
*     I_INTERFACE_CHECK              = ' '
*     I_BYPASSING_BUFFER             =
*     I_BUFFER_ACTIVE                = ' '
     I_CALLBACK_PROGRAM             = sy-repid
*     I_CALLBACK_PF_STATUS_SET       = ' '
*     I_CALLBACK_USER_COMMAND        = ' '
*     I_STRUCTURE_NAME               =
     IS_LAYOUT                      = itlayout
     IT_FIELDCAT                    = itfieldcat[]
*     IT_EXCLUDING                   =
*     IT_SPECIAL_GROUPS              =
     IT_SORT                        = itsort[]
*     IT_FILTER                      =
*     IS_SEL_HIDE                    =
*     I_DEFAULT                      = 'X'
*     I_SAVE                         = ' '
*     IS_VARIANT                     =
*     IT_EVENTS                      =
*     IT_EVENT_EXIT                  =
*     IS_PRINT                       =
*     IS_REPREP_ID                   =
*     I_SCREEN_START_COLUMN          = 0
*     I_SCREEN_START_LINE            = 0
*     I_SCREEN_END_COLUMN            = 0
*     I_SCREEN_END_LINE              = 0
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER        =
*     ES_EXIT_CAUSED_BY_USER         =
    TABLES
      t_outtab                       = itab2
*   EXCEPTIONS
*     PROGRAM_ERROR                  = 1
*     OTHERS                         = 2
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
EXPORT ITAB2 TO MEMORY ID 'KK_ITAB2'.

endform.                    " alv

K.Kiran.

Read only

0 Likes
1,683

Yes you can do multi level BOM explosion with CS_BOM_EXPLOSION.

For Multilevel Explosion you have to use:


MEHRS = 'X' 

in the exporting parameters.

You can also use: CS_BOM_EXPL_MAT_V2

If you search the forum for multi level bom explosion you will find lots of threads with examples.

Read only

0 Likes
1,683

Hi Aparna ,

Ya my exact requirement is , i have to explode the sub components and if sub components have its subcomponents then i shud retrieve the data . It is like hierarachial and i sholud get until the bottom one (Raw Material ) ..

You explained that if keep Mehrs = 'X' , it is possible .

if yes . i think i will get the information from export parameters of FM TopMat like CSTMAT

Please let me know .......

Regards

Raj

Read only

Former Member
0 Likes
1,683

Check the fm's CS_BOM_EXPL_MAT_V2 & CSAI_BOM_READ.

Read only

Former Member
0 Likes
1,683

Please check the link below.

Hope this will help you,

Murthy.

Read only

Former Member
0 Likes
1,683

Hi,

try with 'CABM_READ_BOM'.

thanx.