05-19-2010 9:17 AM
Hello,
I created a report to get the materials used in BOMs but only in two levels depth. Is there any way to to do this for multilevel ?
i try to do it, but nothing works and i also search in this forum but i didnt find anything useful.
I give you my code (and i am waiting for your responds).
Thx in advance.
LOOP AT GT_MATERIALS INTO GW_MATERIALS.
CALL FUNCTION 'CS_WHERE_USED_MAT'
EXPORTING
DATUB = P_DATUB
DATUV = P_DATUV
MATNR = GW_MATERIALS-MATNR
WERKS = P_WERKS
MCLMT = '00000000'
TABLES
WULTB = GT_STPOV
EQUICAT = GT_EQUICAT
KNDCAT = GT_KNDCAT
MATCAT = GT_MATCAT
STDCAT = GT_STDCAT
TPLCAT = GT_TPLCAT
PRJCAT = GT_PRJCAT
EXCEPTIONS
CALL_INVALID = 1
MATERIAL_NOT_FOUND = 2
NO_WHERE_USED_REC_FOUND = 3
NO_WHERE_USED_REC_SELECTED = 4
NO_WHERE_USED_REC_VALID = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
LOOP AT GT_STPOV INTO GW_STPOV.
MOVE-CORRESPONDING GW_STPOV TO GW_BOM_HEADER.
GW_BOM_HEADER-S_MATNR = GW_MATERIALS-MATNR.
GW_BOM_HEADER-D_EMENG = GW_BOM_HEADER-EMENG.
GW_BOM_HEADER-D_MATNR = GW_BOM_HEADER-MATNR.
APPEND GW_BOM_HEADER TO GT_BOM_HEADER.
IF P_MULTI = 'X'.
CALL FUNCTION 'CS_WHERE_USED_MAT'
EXPORTING
DATUB = P_DATUB
DATUV = P_DATUV
MATNR = GW_STPOV-MATNR
WERKS = P_WERKS
MCLMT = '00000000'
TABLES
WULTB = GT_STPOV_2
EQUICAT = GT_EQUICAT
KNDCAT = GT_KNDCAT
MATCAT = GT_MATCAT
STDCAT = GT_STDCAT
TPLCAT = GT_TPLCAT
PRJCAT = GT_PRJCAT
EXCEPTIONS
CALL_INVALID = 1
MATERIAL_NOT_FOUND = 2
NO_WHERE_USED_REC_FOUND = 3
NO_WHERE_USED_REC_SELECTED = 4
NO_WHERE_USED_REC_VALID = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
LOOP AT GT_STPOV_2 INTO GW_STPOV_2.
MOVE-CORRESPONDING GW_STPOV_2 TO GW_BOM_HEADER.
GW_BOM_HEADER-LEVEL = '2'.
GW_BOM_HEADER-S_MATNR = GW_MATERIALS-MATNR.
GW_BOM_HEADER-D_MATNR = GW_BOM_HEADER-MATNR.
APPEND GW_BOM_HEADER TO GT_BOM_HEADER.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
Edited by: stratos_chm on May 19, 2010 10:18 AM
05-19-2010 2:20 PM
Hi,
You can ckeck this link:[Inverse BOM Explosion|http://wiki.sdn.sap.com/wiki/display/Snippets/InverseBOMExplosion-ABAP].
You can go through the logic of recursive processing in it, hope so you can also remove the logic of summing the quantity .
It was written long back , hope you can write it much more better. But the logic is the same
Finally internal table IT_STORE will hold all the levels with parent material related to its child material.
Keshav
05-19-2010 10:34 AM
05-19-2010 11:25 AM
Hi stratos_chm,
have you tried with transaction CS11? This gives the full explosion for a material with BOM...
I hope this helps. Kind regards,
Alvaro
05-19-2010 11:45 AM
Hi,
You can use function module CS_BOM_EXPL_MAT_V2 to get all component of BOM.
05-19-2010 12:15 PM
HI,
Try FM : as folllows: CS_BOM_EXPL_MAT_V2.
Declare two internal tables like structures STPOX, CSCMAT
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = ITAB-ANDAT
MEHRS = 'X'
MTNRV = ITAB-MATNR
STLAL = ITAB-STLAL
STLAN = ITAB-STLAN
WERKS = ITAB-WERKS
TABLES
STB = I_STPOX
MATCAT = I_CSCMAT
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards,
Anil
05-19-2010 1:58 PM
Thanks for your answers,
But it's not what i want. If you notice my code, it works like transaction cs15, but for multiple materials.
My problem is the levels depth. I want to go deeper than level two: In the first i call the function "CS_WHERE_USED_MAT "loop in the selected materials get the table GT_STPOV append its lines to GT_BOM_HEADER.Now in the table GT_STPOV maybe some materials are used in another BOM, so i do a nested loop, get a table GT_STPOV_2 and append it's lines to theGT_BOM_HEADER setting the level to "2".
By this procedure i lost the infromation of deeper levels. So i want a flexible dynamic code, to go as fas as the GT_STPOV is initial!
How is this possible ?
Thx in advance.
LOOP AT GT_MATERIALS INTO GW_MATERIALS.
CALL FUNCTION 'CS_WHERE_USED_MAT'
EXPORTING
DATUB = P_DATUB
DATUV = P_DATUV
MATNR = GW_MATERIALS-MATNR
WERKS = P_WERKS
TABLES
WULTB = GT_STPOV
IF SY-SUBRC <> 0.
ELSE.
LOOP AT GT_STPOV INTO GW_STPOV.
MOVE-CORRESPONDING GW_STPOV TO GW_BOM_HEADER.
GW_BOM_HEADER-S_MATNR = GW_MATERIALS-MATNR.
APPEND GW_BOM_HEADER TO GT_BOM_HEADER.
CALL FUNCTION 'CS_WHERE_USED_MAT'
EXPORTING
DATUB = P_DATUB
DATUV = P_DATUV
MATNR = GW_STPOV-MATNR
WERKS = P_WERKS
TABLES
WULTB = GT_STPOV_2
IF SY-SUBRC <> 0.
ELSE.
LOOP AT GT_STPOV_2 INTO GW_STPOV_2.
MOVE-CORRESPONDING GW_STPOV_2 TO GW_BOM_HEADER.
GW_BOM_HEADER-LEVEL = '2'.
APPEND GW_BOM_HEADER TO GT_BOM_HEADER.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
Edited by: stratos_chm on May 19, 2010 3:11 PM
05-19-2010 2:20 PM
Hi,
You can ckeck this link:[Inverse BOM Explosion|http://wiki.sdn.sap.com/wiki/display/Snippets/InverseBOMExplosion-ABAP].
You can go through the logic of recursive processing in it, hope so you can also remove the logic of summing the quantity .
It was written long back , hope you can write it much more better. But the logic is the same
Finally internal table IT_STORE will hold all the levels with parent material related to its child material.
Keshav
05-19-2010 6:57 PM
thanks for the reply Keshav,
i have another idea and i want your opinion..
i will place a drop-down box at the selection screen with values 1 to 4 (we use 4 maximum depth).
and i will add 2 more loops with the if condition for the levels!
what to do you think abou that ?
05-20-2010 8:49 AM
Hi,
You no need to add any more loops, based on the hierarchy level selected loop the STPO table.
First of all why do you want to restrict the Explosion to levels ?
Just copy that program and execute it , it will give you the multilevel BOM.
05-20-2010 2:16 PM
Thx for the reply,
This program doesn't work properly for me! i test it and the results doesn't match! Is there a way to write the above code with less "hard-code" and do more automatically the loop ?
Thanks in advance!
05-20-2010 3:50 PM
Hello,
First understand what the program logic does, it explodes to the deepest level automatically.
When we give a HALB part as input , it explodes all its parents (FERT) with the amount of quantity required.
If you need not require the quantity to be summed up, remove that.
The alternative bom logic is like a material might contain alternative BOM, so it displays the alternative BOM for a particular material.
Your report output will be like below. Please try to debug it .
Parent material child material qty
P1 C1 2
P1 C2 6
C1 C4 5
06-11-2015 8:24 AM
Hello Stratos,
I see that this post was answered for you but I have a similar question.
I am trying to use the FM "CS_WHERE_USED_MAT" in an Infoset to get all levels for a material (as in CS15), but the code returns only one level.
This is my code:
REPORT zq_pp_where_used_report .
*
*---------------------------------------------------------------------*
* declarations
* (insert your declarations in this section)
*---------------------------------------------------------------------*
*
TABLES: marc.
TYPES: BEGIN OF y_marc,
mandt TYPE mandt,
matnr TYPE matnr,
werks TYPE werks_d,
END OF y_marc.
DATA: i_marc TYPE TABLE OF y_marc INITIAL SIZE 0,
w_marc TYPE y_marc.
DATA: stpov TYPE stpov,
i_stpov TYPE STANDARD TABLE OF stpov,
t_stpov TYPE STANDARD TABLE OF stpov,
w_stpov TYPE stpov.
DATA: selpool TYPE mc29s,
i_selpool TYPE STANDARD TABLE OF mc29s,
t_selpool TYPE STANDARD TABLE OF mc29s,
w_selpool TYPE mc29s.
DATA: eqpcat TYPE cscequi,
i_eqpcat TYPE STANDARD TABLE OF cscequi,
t_eqpcat TYPE STANDARD TABLE OF cscequi,
w_eqpcat TYPE cscequi.
DATA: kndcat TYPE cscknd,
i_kndcat TYPE STANDARD TABLE OF cscknd,
t_kndcat TYPE STANDARD TABLE OF cscknd,
w_kndcat TYPE cscknd.
DATA: matcat TYPE cscmat,
i_matcat TYPE STANDARD TABLE OF cscmat,
t_matcat TYPE STANDARD TABLE OF cscmat,
w_matcat TYPE cscmat.
DATA: stdcat TYPE cscstd,
i_stdcat TYPE STANDARD TABLE OF cscstd,
t_stdcat TYPE STANDARD TABLE OF cscstd,
w_stdcat TYPE cscstd.
DATA: tplcat TYPE csctpl,
i_tplcat TYPE STANDARD TABLE OF csctpl,
t_tplcat TYPE STANDARD TABLE OF csctpl,
w_tplcat TYPE csctpl.
DATA: prjcat TYPE cscprj,
i_prjcat TYPE STANDARD TABLE OF cscprj,
t_prjcat TYPE STANDARD TABLE OF cscprj,
w_prjcat TYPE cscprj.
FIELD-SYMBOLS: <struc> TYPE stpov.
*-------------------------------------------------------------------*
* selection screen statements
*-------------------------------------------------------------------*
* (define your selection-screen here)
*
SELECTION-SCREEN BEGIN OF BLOCK blk0.
SELECT-OPTIONS: s_matnr FOR marc-matnr
OBLIGATORY,
s_werks FOR marc-werks
OBLIGATORY NO INTERVALS,
s_stlan FOR stpov-stlan
OBLIGATORY NO INTERVALS NO-EXTENSION,
s_datuv FOR stpov-datuv
OBLIGATORY NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK blk0.
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_HEAD>
*-------------------------------------------------------------------*
* read data into IT_DATA
*-------------------------------------------------------------------*
* (select your data here into internal table IT_DATA)
CLEAR: i_marc. REFRESH: i_marc.
SELECT *
FROM marc CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE i_marc
WHERE matnr IN s_matnr
AND werks IN s_werks
AND mandt = '100' .
LOOP AT i_marc INTO w_marc.
CALL FUNCTION 'CS_WHERE_USED_MAT'
EXPORTING
datub = s_datuv-high
datuv = sy-datum
* s_datuv-low
matnr = w_marc-matnr
werks = w_marc-werks
* mclmt = '00000000'
* mehrs = 'X' " doesn't exist in structure?
stlan = stpov-stlan
* postp = SPACE rc29l-postp Item category
* retcode_only = SPACE csdata-xfeld no data - only set return code
TABLES
WULTB = T_STPOV
EQUICAT = T_EQPCAT
KNDCAT = T_KNDCAT
MATCAT = T_MATCAT
STDCAT = T_STDCAT
TPLCAT = T_TPLCAT
PRJCAT = T_PRJCAT
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.
IF sy-subrc EQ 0.
LOOP AT t_stpov INTO w_stpov.
APPEND w_stpov TO i_stpov.
ENDLOOP.
ENDIF.
ENDLOOP.
*------------------------------------------------------------*
* output of the data
* (this section can be left unchanged)
*------------------------------------------------------------*
LOOP AT i_stpov ASSIGNING <struc>.
MOVE-CORRESPONDING <struc> TO stpov .
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_BODY>
ENDLOOP.
How did you resolve this issue?
Thank you in advance.
04-17-2022 8:06 PM
Hi,
CS_WHERE_USED_MAT does not get multilevel BOM. But you can run CS15 in background as below.
cl_salv_bs_runtime_info=>set( display = abap_false
metadata = abap_false
data = abap_true ).
SUBMIT rcs15001 WITH pm_idnrk = iv_idnrk
WITH pm_werks = iv_werks
WITH pm_mehrs = 'X' "Multilevel
AND RETURN .
TRY.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = DATA(lobj_data) ).
ASSIGN lobj_data->* TO FIELD-SYMBOL(<lfs_data>).
CATCH cx_salv_bs_sc_runtime_info.
ENDTRY.
IF <lfs_data> IS ASSIGNED.
DATA: lt_stpov_alv TYPE TABLE OF stpov_alv.
lt_stpov_alv = CORRESPONDING #( <lfs_data> ).
ENDIF.