Skip to Content
author's profile photo
Former Member

multi level where used list (cs_where_use_mat)

How to get Multi level where use list of a component?

CS_WHERE_USE_MAT has details of a material. but i need to dig where use list for all materials of that component. CS15 does not give compleate details(only few fields are there)

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • author's profile photo
    Former Member
    Posted on Jul 16, 2007 at 02:54 AM

    Try with FM : CS_BOM_EXPL_MAT_V2 ,This will give multile level,this is equl to CS12,CS11 Transaction.

    I have developed one custom report ,see the below code :

    REPORT ZPPR_BOM_INFOML_REPORT no standard page heading

    line-size 160

    line-count 60.

    ======================================================================

    • *

    • Program Name : ZPPR_BOM_INFOML_REPORT

    • *

    • *

    • Description : This Program would be used for BOM List for a material*

    • and the component's where used list *

    • *

    • *

    • *

    • Author : Seshu *

    • Date : 07/24/2006 *

    • *

    ----


    • MODIFICATION HISTORY *

    ----


    • DATE | AUTHOR | CHANGE # | DESCRIPTION OF MODIFICATION *

    --


    |
    |

    |
    --


    • | | | *

    ======================================================================

    ----


    • Table definition *

    ----


    TABLES: mast,

    • stko,

    stpo.

    • makt.

    ----


    • Internal Table Declaration *

    ----


    DATA: t_mast LIKE STANDARD TABLE OF mast WITH HEADER LINE.

    *DATA: t_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE.

    • BOM Function module Related

    DATA: t_matcat LIKE cscmat OCCURS 0 WITH HEADER LINE.

    DATA: t_stb LIKE stpox OCCURS 0 WITH HEADER LINE.

    • Internal Table for STPO

    *-- BOM Line item

    TYPES: BEGIN OF ty_stpo,

    stlty TYPE stpo-stlty,

    stlnr TYPE stpo-stlnr,

    stlkn TYPE stpo-stlkn,

    stpoz TYPE stpo-stpoz,

    idnrk TYPE stpo-idnrk,

    meins TYPE stpo-meins,

    menge TYPE stpo-menge, "Component Qty

    END OF ty_stpo.

    DATA: t_stpo TYPE STANDARD TABLE OF ty_stpo WITH HEADER LINE.

    *-- BOM Header

    TYPES: BEGIN OF ty_stko,

    stlty TYPE stko-stlty,

    stlnr TYPE stko-stlnr,

    stlal TYPE stko-stlal,

    stkoz TYPE stko-stkoz,

    bmein TYPE stko-bmein,

    bmeng TYPE stko-bmeng,

    END OF ty_stko.

    DATA: t_stko TYPE STANDARD TABLE OF ty_stko WITH HEADER LINE .

    data : t_makt like makt occurs 0 with header line.

    • Variables

    data : v_maktx like makt-maktx.

    data wa_stko like stko.

    ----


    • Selection Screen *

    ----


    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    PARAMETERS: p_werks LIKE marc-werks DEFAULT '1000' OBLIGATORY.

    SELECT-OPTIONS s_stlal FOR mast-stlal .

    SELECT-OPTIONS s_stlan FOR mast-stlan DEFAULT '1'.

    SELECTION-SCREEN SKIP.

    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

    SELECTION-SCREEN SKIP.

    PARAMETERS: p_bomlst RADIOBUTTON GROUP g1 DEFAULT 'X'.

    SELECT-OPTIONS s_matnr FOR mast-matnr.

    SELECTION-SCREEN SKIP.

    PARAMETERS: p_compon RADIOBUTTON GROUP g1.

    SELECT-OPTIONS: s_idnrk FOR stpo-idnrk.

    SELECTION-SCREEN END OF BLOCK b2.

    SELECTION-SCREEN END OF BLOCK b1.

    ************************************************************************

                                  • S T A R T - O F - S E L E C T I O N *******************

                                  ************************************************************************

                                  start-of-selection.

                                  • Get the data from MAST and MAKT Table

                                  if p_bomlst = 'X'.

                                  perform get_data.

                                  else.

                                  perform get_data_component.

                                  endif.

                                  &----


                                  *& Form get_data

                                  &----


                                  • Get data from MAST and MAKT Table

                                  ----


                                  FORM get_data.

                                  data : wa_lines type sy-index.

                                  • Get the data from MAST Table

                                  • Get all the information from MAST - BOM Table

                                  SELECT * FROM mast INTO TABLE t_mast WHERE matnr IN s_matnr AND

                                  werks = p_werks AND

                                  stlan IN s_stlan AND

                                  stlal IN s_stlal.

                                  describe table t_mast lines wa_lines.

                                  if wa_lines is initial.

                                  Write:/2 'List contains no data'.

                                  stop.

                                  endif.

                                  loop at t_mast.

                                  clear : v_maktx.

                                  if sy-tabix ne 1.

                                  new-page.

                                  endif.

                                  • Get the material Description

                                  select single maktx from makt into v_maktx

                                  where matnr = t_mast-matnr

                                  and spras = 'E'.

                                  • Get the material details from STKO Table

                                  select single * from stko into wa_stko

                                  where STLTY = 'M'

                                  and STLNR = t_mast-stlnr

                                  and STLAL = t_mast-stlal.

                                  • Main Header for Each Material

                                  format color 5 on.

                                  write:/2 'Material',20 'Material Description',65 'Alternative BOM',

                                  90 'Base Qty', 115 'Base Unit'.

                                  format color 5 off.

                                  format color 1 on.

                                  write:/2 t_mast-matnr,20 v_maktx,65 wa_stko-STLAL, 85 wa_stko-BMENG,

                                  115 wa_stko-BMEIN.

                                  format color 1 off.

                                  CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

                                  EXPORTING

                                  capid = 'PP01'

                                  datuv = sy-datum

                                  mktls = 'X'

                                  mehrs = 'X'

                                  mtnrv = t_mast-matnr

                                  stlal = '01'

                                  stlan = '1'

                                  stpst = 0

                                  svwvo = 'X'

                                  werks = p_werks

                                  vrsvo = 'X'

                                  TABLES

                                  stb = t_stb

                                  matcat = t_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.

                                  IF SY-SUBRC <> 0.

                                  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                                  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

                                  ENDIF.

                                  loop at t_stb.

                                    • Get the material details from STKO Table

                                  • select single * from stpo into wa_stko1

                                  • where STLTY = t_stb-stlty

                                  • and STLNR = t_stb-stlnr

                                  • and STpoz = t_stb-stpoz

                                  • and stlkn = t_stb-stlkn

                                  • and idnrk = t_stb-idnrk.

                                  • if sy-tabix = 1.

                                    format color 3 on.

                                    write:/2 'Level',15 'Component',35 'Material Description',

                                    75 'Alternative BOM',100 'Base Qty', 115 'Base Unit'.

                                    .

                                    format color 3 on.

                                    endif.

                                    if t_stb-STUFE = '1'.

                                    format color 1 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 1 off.

                                    elseif t_stb-STUFE = '2'.

                                    format color 2 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 2 off.

                                    elseif t_stb-STUFE = '3'.

                                    format color 3 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 3 off.

                                    elseif t_stb-STUFE = '4'.

                                    format color 4 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 4 off.

                                    elseif t_stb-STUFE = '5'.

                                    format color 5 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 5 off.

                                    elseif t_stb-STUFE = '6'.

                                    format color 6 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 6 off.

                                    elseif t_stb-STUFE = '7'.

                                    format color 7 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 7 off.

                                    else.

                                    format color 1 on.

                                    write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                    90 t_stb-mngko,115 t_stb-MEINs.

                                    format color 1 off.

                                    endif.

                                    endloop.

                                    endloop.

                                    ENDFORM. " get_data

                                    ----


                                    • Top of page *

                                    ----


                                    top-of-page.

                                    perform report_header .

                                    &----


                                    *& Form report_header

                                    &----


                                    • text

                                    ----


                                    • --> p1 text

                                    • <-- p2 text

                                    ----


                                    FORM report_header.

                                    new-page line-size 160 .

                                    format color col_heading intensified on.

                                    write:/ sy-uline(160) .

                                    *--- Write Company Name.

                                    perform calc_col_and_write using text-h00

                                    sy-linsz.

                                    *--- Write Report Title.

                                    perform calc_col_and_write using sy-title

                                    sy-linsz.

                                    *--- Write User Id, Date / Time, Program Id, Page etc.

                                    perform write_other_hdr_details.

                                    write:/ sy-uline(160) .

                                    ENDFORM. " report_header

                                    &----


                                    *& Form calc_col_and_write

                                    &----


                                    • text

                                    ----


                                    • -->P_TEXT_H00 text

                                    • -->P_SY_LINSZ text

                                    ----


                                    FORM calc_col_and_write USING P_TEXT

                                    P_LINSZ.

                                    data: col1 type i,

                                    • col2 type i,

                                    len type i,

                                    str type i.

                                    str = strlen( p_text ).

                                    col1 = ( p_linsz / 2 ) - ( str / 2 ) .

                                    len = p_linsz - col1 - 2.

                                    write: at /1 '|'.

                                    write: at col1 p_text,

                                    at sy-colno(len) space.

                                    write at 160 '|'.

                                    ENDFORM. " calc_col_and_write

                                    &----


                                    *& Form write_other_hdr_details

                                    &----


                                    • text

                                    ----


                                    • --> p1 text

                                    • <-- p2 text

                                    ----


                                    FORM write_other_hdr_details.

                                    data: col1 type i,

                                    col2 type i,

                                    len type i.

                                    col1 = 3.

                                    write:/1 '|'.

                                    write: at col1 'UserId : ',

                                    sy-uname.

                                    len = sy-linsz - 1.

                                    write at sy-colno(len) space.

                                    col2 = sy-linsz - 18.

                                    write: at col2 'Date: ',

                                    sy-datum mm/dd/yyyy.

                                    write: at sy-linsz '|'.

                                    write:/1 '|'.

                                    write: at col1 'ReportId: ',

                                    sy-repid.

                                    write at sy-colno(len) space.

                                    col2 = sy-linsz - 18.

                                    write: at col2 'Page: ',

                                    sy-pagno.

                                    write: at sy-linsz '|'.

                                    ENDFORM. " write_other_hdr_details

                                    &----


                                    *& Form get_data_component

                                    &----


                                    • Get the data based on Component level

                                    ----


                                    FORM get_data_component.

                                    data wa_lines type i.

                                    *-- Get the BOM item details

                                    SELECT stlty stlnr stlkn stpoz idnrk meins menge

                                    FROM stpo

                                    INTO TABLE t_stpo

                                    WHERE idnrk IN s_idnrk.

                                    IF sy-subrc = 0.

                                    CLEAR wa_lines.

                                    DESCRIBE TABLE t_stpo LINES wa_lines.

                                    IF wa_lines > 0.

                                    SELECT stlty stlnr stlal stkoz bmein bmeng

                                    FROM stko

                                    INTO TABLE t_stko

                                    FOR ALL ENTRIES IN t_stpo

                                    WHERE stlnr = t_stpo-stlnr.

                                    CLEAR wa_lines.

                                    DELETE ADJACENT DUPLICATES FROM t_stko COMPARING ALL FIELDS.

                                    DESCRIBE TABLE t_stko LINES wa_lines.

                                    IF wa_lines > 0.

                                    *-- Get the BOM item details

                                    SELECT * FROM mast INTO TABLE t_mast FOR ALL ENTRIES IN t_stko

                                    WHERE werks = p_werks AND

                                    stlnr = t_stko-stlnr

                                    and stlal in s_stlal.

                                    ENDIF.

                                    ENDIF.

                                    else.

                                    Write:/2 'List contains no data'.

                                    stop.

                                    endif.

                                    loop at t_mast.

                                    clear : v_maktx.

                                    if sy-tabix ne 1.

                                    new-page.

                                    endif.

                                    • Get the material Description

                                    select single maktx from makt into v_maktx

                                    where matnr = t_mast-matnr

                                    and spras = 'E'.

                                    • Get the material details from STKO Table

                                    select single * from stko into wa_stko

                                    where STLTY = 'M'

                                    and STLNR = t_mast-stlnr

                                    and STLAL = t_mast-stlal.

                                    • Main Header for Each Material

                                    format color 5 on.

                                    write:/2 'Material',20 'Material Description',65 'Alternative BOM',

                                    90 'Base Qty', 115 'Base Unit'.

                                    format color 5 off.

                                    format color 1 on.

                                    write:/2 t_mast-matnr,20 v_maktx,65 wa_stko-STLAL, 85 wa_stko-BMENG,

                                    115 wa_stko-BMEIN.

                                    format color 1 off.

                                    CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

                                    EXPORTING

                                    capid = 'PP01'

                                    datuv = sy-datum

                                    mktls = 'X'

                                    mehrs = 'X'

                                    mtnrv = t_mast-matnr

                                    stlal = '01'

                                    stlan = '1'

                                    stpst = 0

                                    svwvo = 'X'

                                    werks = p_werks

                                    vrsvo = 'X'

                                    TABLES

                                    stb = t_stb

                                    matcat = t_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.

                                    IF SY-SUBRC <> 0.

                                    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                                    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

                                    ENDIF.

                                    loop at t_stb.

                                      • Get the material details from STKO Table

                                    • select single * from stpo into wa_stko1

                                    • where STLTY = t_stb-stlty

                                    • and STLNR = t_stb-stlnr

                                    • and STpoz = t_stb-stpoz

                                    • and stlkn = t_stb-stlkn

                                    • and idnrk = t_stb-idnrk.

                                    • if sy-tabix = 1.

                                      format color 3 on.

                                      write:/2 'Level',15 'Component',35 'Material Description',

                                      75 'Alternative BOM',100 'Base Qty', 115 'Base Unit'.

                                      .

                                      format color 3 on.

                                      endif.

                                      if t_stb-STUFE = '1'.

                                      format color 1 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 1 off.

                                      elseif t_stb-STUFE = '2'.

                                      format color 2 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 2 off.

                                      elseif t_stb-STUFE = '3'.

                                      format color 3 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 3 off.

                                      elseif t_stb-STUFE = '4'.

                                      format color 4 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 4 off.

                                      elseif t_stb-STUFE = '5'.

                                      format color 5 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 5 off.

                                      elseif t_stb-STUFE = '6'.

                                      format color 6 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 6 off.

                                      elseif t_stb-STUFE = '7'.

                                      format color 7 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 7 off.

                                      else.

                                      format color 1 on.

                                      write:/2 t_stb-STUFE,15 t_stb-idnrk,35 t_stb-OJTXP,75 t_stb-stlal,

                                      90 t_stb-mngko,115 t_stb-MEINs.

                                      format color 1 off.

                                      endif.

                                      endloop.

                                      endloop.

                                      ENDFORM. " get_data_component

                                      Text elements :

                                      P_BOMLST BOM Components List

                                      P_COMPON Components Where Used List

                                      P_WERKS Plant

                                      S_IDNRK Component

                                      S_MATNR Material

                                      S_STLAL Alternative BOM

                                      S_STLAN BOM usage

                                      Reward points if it is helpful

                                      Thanks

                                      Seshu

                                    Add comment
                                    10|10000 characters needed characters exceeded

                                    • Former Member Former Member

                                      Hi Seshu,

                                      Would you please explain me about this (bloded lines)

                                      I could not understand this case statement in subroutine <b>"alv_stb_prep"</b>

                                      Plz Help me .

                                      ********************************************

                                      CASE t_stb-objty.

                                      WHEN otyp_mat.

                                      WRITE: stb_orig-idnrk TO ecfld.

                                      <b> stb_add-objic = '@A6@'.</b>

                                      WHEN 'M'.

                                      WRITE: stb_orig-idnrk TO ecfld.

                                      <b>stb_add-objic = '@A6@'.</b>

                                      WHEN otyp_noo.

                                      WRITE: stb_orig-potx1 TO ecfld.

                                      <b> stb_add-objic = '@0Q@'.</b>

                                      WHEN otyp_doc.

                                      WRITE stb_orig-doknr TO ecfld. "note 489354

                                      IF ecfld CP '*# '. ENDIF. "note 489354

                                      sy-fdpos = sy-fdpos + 1. "note 489354

                                      CONCATENATE

                                      *d stb_orig-doknr "note 489354

                                      stb_orig-dokar

                                      stb_orig-doktl

                                      stb_orig-dokvr

                                      *d INTO ecfld "note 489354

                                      INTO ecfld+sy-fdpos "note 489354

                                      SEPARATED BY space.

                                      <b> stb_add-objic = '@AR@'.</b>

                                      WHEN otyp_kla.

                                      CONCATENATE

                                      stb_orig-class

                                      stb_orig-klart

                                      INTO ecfld

                                      SEPARATED BY space.

                                      <b>stb_add-objic = '@7C@'.</b>

                                      WHEN otyp_ntm.

                                      WRITE: stb_orig-intrm TO ecfld.

                                      WHEN OTHERS.

                                      ENDCASE.

                                  • author's profile photo
                                    Former Member
                                    Posted on Jul 16, 2007 at 04:03 AM

                                    I am not sure that cs_where_use_mat fm can give the multilevel or not... I think it is only for the upper level. you can try this sample program it may help you.

                                    data : IWULTB	LIKE	STPOV OCCURS 0 WITH HEADER LINE,
                                           IEQUICAT	LIKE	CSCEQUI OCCURS 0 WITH HEADER LINE,
                                           IKNDCAT	LIKE	CSCKND OCCURS 0 WITH HEADER LINE,
                                           IMATCAT	LIKE	CSCMAT OCCURS 0 WITH HEADER LINE,
                                           ISTDCAT	LIKE	CSCSTD OCCURS 0 WITH HEADER LINE,
                                           ITPLCAT	LIKE	CSCTPL OCCURS 0 WITH HEADER LINE,
                                           IPRJCAT	LIKE	CSCPRJ OCCURS 0 WITH HEADER LINE.
                                    
                                    DATA : TEMPMATCAT LIKE CSCMAT OCCURS 0 WITH HEADER LINE.
                                    
                                    TEMPMATCAT-MATNR = '123GJ'.
                                    APPEND TEMPMATCAT.
                                    
                                    LOOP AT TEMPMATCAT.
                                    
                                    CALL FUNCTION 'CS_WHERE_USED_MAT'
                                      EXPORTING
                                        datub                            = SY-DATUM
                                        datuv                            = SY-DATUM
                                        matnr                            = TEMPMATCAT-MATNR
                                    *   POSTP                            = ' '
                                    *   RETCODE_ONLY                     = ' '
                                    *   STLAN                            = ' '
                                       WERKS                            = '3000'
                                    *   MCLMT                            = ' '
                                    *   MNSTL                            = ' '
                                    *   MXSTL                            = ' '
                                    *   STLTP                            = ' '
                                    *   NEWSI                            = ' '
                                    * IMPORTING
                                    *   TOPMAT                           =
                                      tables
                                        wultb                            =    Iwultb
                                        equicat                          =    Iequicat
                                        kndcat                           =    Ikndcat
                                        matcat                           =     Imatcat
                                        stdcat                           =     Istdcat
                                        tplcat                           =     Itplcat
                                    *   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.
                                    EXIT.
                                    ENDIF.
                                    
                                    READ TABLE IMATCAT INDEX 1.
                                    WRITE : / IMATCAT-MATNR.
                                    APPEND IMATCAT TO TEMPMATCAT.
                                    ENDLOOP.
                                    
                                    

                                    regards

                                    shiba dutta

                                    Add comment
                                    10|10000 characters needed characters exceeded