How to use CS_BOM_EXPL_MAT_V2 to get correct quantity of component for BOM explosions?

Eric picture Eric · Jun 7, 2012 · Viewed 29.2k times · Source

I am getting an issue with my program. I am using function module CS_BOM_EXPL_MAT_V2 to get the BOMs of a material. For example I have a material MAT1 that has the ff. BOM explosion.

MAT1
- COMP1 with Qty 2
- COMP2 with Qty 1
- COMP3 with Qty 1

And then, for component COMP1, it also has sub-components:

COMP1
- SUBCOMP1 with Qty 1
- SUBCOMP2 with Qty 1

So what I am expecting in my program, using CS_BOM_EXPL_MAT_V2, is to have the report to have a quantity of SUBCOMP1 = 2 and SUBCOMP2 = 2 (because MAT1 uses 2 quantity of COMP1). But what I am getting is SUBCOMP1 = 1 qty and SUBCOMP2 = 1 qty because I think that it is only considering the BOM of COMP1 and the quantity of COMP1 is not taken into account.

When running transaction CS12, the output is correct (SUBCOMP1 = 2, SUBCOMP2 = 2) for material MAT1.

So, how do I make CS_BOM_EXPL_MAT_V2 work so that it will respect the count of the component, in this case COMP1 with Qty 2, and cascade the value to the sub-components, in this case SUBCOMP1 and SUBCOMP2, and multiply it so it will return the correct quantity, in this case both sub-components should have Qty 2 as in transaction CS12?

If this is not possible with FM CS_BOM_EXPL_MAT_V2, please suggest other ways to achieve this.

Here's how my FM currently looks like:

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
  EXPORTING
    aumgb                 = 'X'
    capid                 = 'PP01'
    datuv                 = v_datuv "date input in selection screen
    endhl                 = '1'
    mehrs                 = 'X'
    mmory                 = '1'
    mtnrv                 = v_matnr "material input in selection screen
    stlal                 = v_stlal "alternative BOM input in selection screen
    stpst                 = 0 "Level in multi-bom expl.
    svwvo                 = 'X'
    werks                 = v_werks "plant input in selection screen
    vrvso                 = 'X'
  IMPORTING
    topmat                = gs_top
  TABLES
    stb                   = gt_stb
    matcat                = gt_matca
  EXCEPTIONS
    alt_not_found         = 1
    call_invalid          = 2
    material_not_found    = 3
    missing_authorization = 4
    no_bom_found          = 5
    no_plant_data         = 6
    no_suitable_bom_found = 7
    conversion_error      = 8
    OTHERS                = 9.

Answer

Beginner picture Beginner · Sep 18, 2018

This is the answer Laurent Fournier gave on snc.sap.com. It was helpful to me, therefore I would like to preserve it here.

I think that you must set multilevel indicator. Take a look at the following code and see if this can help you.

FORM EXPLODE_BOM  USING U_DATE
                        U_MATNR
                        U_MENGE
                        U_WERKS
                        U_MULTI
                CHANGING   C_SUCCESS.

  CLEAR : C_SUCCESS.

  CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
    EXPORTING
*   FTREL                       = ' '
*   ALEKZ                       = ' '
*   ALTVO                       = ' '
*   AUFSW                       = ' '
    AUMGB                       = 'X'
*   AUMNG                       = 0
    AUSKZ                       = ' '
*   AMIND                       = ' '
*   BAGRP                       = ' '
*   BEIKZ                       = ' '
*   BESSL                       = ' '
*   BGIXO                       = ' '
*   BREMS                       = ' '
    CAPID                       = 'PP01'
*   CHLST                       = ' '
*   COSPR                       = ' '
*   CUOBJ                       = 000000000000000
*   CUOVS                       = 0
*   CUOLS                       = ' '
    DATUV                       = U_DATE
*   DELNL                       = ' '
*   DRLDT                       = ' '
*   EHNDL                       = ' '
*   EMENG                       = 0
*   ERSKZ                       = ' '
*   ERSSL                       = ' '
*   FBSTP                       = ' '
*   KNFBA                       = ' '
*   KSBVO                       = ' '
*   MBWLS                       = ' '
*   MKTLS                       = 'X'
*   MDMPS                       = ' '
    MEHRS                       = U_MULTI
*   MKMAT                       = ' '
*   MMAPS                       = ' '
*   SALWW                       = ' '
*   SPLWW                       = ' '
*   MMORY                       = ' '
    MTNRV                       = U_MATNR
*   NLINK                       = ' '
*   POSTP                       = ' '
*   RNDKZ                       = ' '
*   RVREL                       = ' '
*   SANFR                       = ' '
*   SANIN                       = ' '
*   SANKA                       = ' '
*   SANKO                       = ' '
*   SANVS                       = ' '
*   SCHGT                       = ' '
*   STKKZ                       = ' '
*   STLAL                       = '1'
*   STLAN                       = '1'
    STPST                       = 0
*   SVWVO                       = 'X'
    WERKS                       = U_WERKS
*   NORVL                       = ' '
*   MDNOT                       = ' '
*   PANOT                       = ' '
*   QVERW                       = ' '
*   VERID                       = ' '
*   VRSVO                       = 'X'

*  IMPORTING
*   TOPMAT                      =
*   DSTST                       =
    TABLES
    STB                         = BOM_EXPL
*   MATCAT                      =

   EXCEPTIONS
    ALT_NOT_FOUND               = 1
    CALL_INVALID                = 2
    MATERIAL_NOT_FOUND          = 3
    MISSING_AUTHORIZATION       = 4
    NO_BOM_FOUND                = 5
    NO_PLANT_DATA               = 6
    NO_SUITABLE_BOM_FOUND       = 7
    CONVERSION_ERROR            = 8
    OTHERS                      = 9