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 report

Former Member
0 Likes
2,889

hello all,

i need to develop alv for Bom Header details and corresponding Item details...

In header

Material Number, Plant, Bom Usage,Alternative Bom i need to display.

In Item

Component,Component Description,Quantity,Unit of Measure.

In selection screen

MATNR

Based on MATNR,i need to display Header details as well as Item details.pls tell me how to do this,main problem is i dont know which table i need to use for above values.

With Regards

MurugeshRajeev

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,286

mast---->Material to BOM Link

stpo------>item level

15 REPLIES 15
Read only

Former Member
0 Likes
2,287

mast---->Material to BOM Link

stpo------>item level

Read only

0 Likes
2,286

hello shani,

i tried this two table mast stpo only even i am getting repeated records.see my coding ..pls help me out..here we dont have pp consultant,so i need to take care of this issues..

TYPES: BEGIN OF XT_TAB,

        MATNR   LIKE MAST-MATNR,
        STLNR   LIKE MAST-STLNR,
        STLAL   LIKE MAST-STLAL,
        WERKS   LIKE MAST-WERKS,
        STLAN   LIKE MAST-STLAN,
       END OF XT_TAB.


TYPES: BEGIN OF YT_TAB,

        STLNR   LIKE STPO-STLNR,
        IDNRK   LIKE STPO-IDNRK,
        MEINS   LIKE STPO-MEINS,
        MENGE   LIKE STPO-MENGE,
*        PSWRK   LIKE STPO-PSWRK,
       END OF YT_TAB.

TYPES: BEGIN OF ZT_TAB,

       MATNR   LIKE MAST-MATNR,
       WERKS   LIKE MAST-WERKS,
       STLNR   LIKE MAST-STLNR,
       STLAL   LIKE MAST-STLAL,
       STLAN   LIKE MAST-STLAN,
*       PSWRK   LIKE STPO-PSWRK,
       IDNRK   LIKE STPO-IDNRK,
       MEINS   LIKE STPO-MEINS,
       MENGE   LIKE STPO-MENGE,


       END OF ZT_TAB.



*----------------------------------------------------------------------*
*        I N T E R N A L   T A B L E   D E C L A R A T I O N S         *
*----------------------------------------------------------------------*
*-----Internal table to store data

DATA: ITAB1   TYPE STANDARD TABLE OF XT_TAB INITIAL SIZE 0,
      WA_TAB1 TYPE XT_TAB.

*DATA: ITAB2   TYPE STANDARD TABLE OF XXT_TAB INITIAL SIZE 0,
*      WA_TAB2 TYPE XXT_TAB.

DATA: ITAB2  TYPE STANDARD TABLE OF YT_TAB INITIAL SIZE 0,
      WA_TAB2 TYPE YT_TAB.

DATA:   ITAB  TYPE STANDARD TABLE OF  ZT_TAB  WITH HEADER LINE,
        WA_FINAL TYPE ZT_TAB,

        ITAB_FINAL2 TYPE STANDARD TABLE OF ZT_TAB.


DATA: ITAB_TEMP1 TYPE STANDARD TABLE OF ZT_TAB  WITH HEADER LINE.

*----------------------------------------------------------------------*
*                 Selection Screen Declarations                        *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN begin OF LINE.
SELECTION-SCREEN COMMENT (23) text-002 FOR FIELD P_MATNR.
SELECT-OPTIONS: P_MATNR FOR MAST-MATNR.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK bk1.


START-OF-SELECTION.

      PERFORM XTRACT_DATA.

END-OF-SELECTION.
      PERFORM BUILD_FIELDCATALOG.
      PERFORM SORTING.
      PERFORM BUILD_LAYOUT.
      PERFORM BUILD_ALV_GRID_DISPLAY.


*----------------------------------------------------------------------*
*      Form  XTRACT_DATA
*----------------------------------------------------------------------*
FORM XTRACT_DATA .



SELECT
       a~MATNR
       a~WERKS
       a~STLNR
       a~STLAL
       a~STLAN
       b~IDNRK
       b~MEINS
       b~MENGE
*       b~PSWRK
  INTO TABLE ITAB
  FROM MAST as a INNER JOIN STPO as b
   ON  a~STLNR = b~STLNR
*       a~WERKS = b~PSWRK

  WHERE  MATNR IN P_MATNR.

ENDFORM.                    " XTRACT_DATA


*----------------------------------------------------------------------*
*      Form  BUILD_FIELDCATALOG
*---------------------------------------------------------------------*

FORM BUILD_FIELDCATALOG .

  REFRESH t_fcat.
  CLEAR t_fcat.
  wa_fcat-col_pos = 1.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'Material Number'.
  wa_fcat-seltext_m = 'Material Number'.
  wa_fcat-seltext_l = 'Material Number'.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.

  wa_fcat-col_pos = 2.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'PLANT'.
  wa_fcat-seltext_m = 'PLANT'.
  wa_fcat-seltext_l = 'PLANT'.
  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.

  wa_fcat-col_pos = 3.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'BOM Usage'.
  wa_fcat-seltext_m = 'BOM Usage'.
  wa_fcat-seltext_l = 'BOM Usage'.
  wa_fcat-fieldname = 'STLAN'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.

  wa_fcat-col_pos = 4.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'ALT_BOM'.
  wa_fcat-seltext_m = 'ALT_BOM'.
  wa_fcat-seltext_l = 'ALT_BOM'.
  wa_fcat-fieldname = 'STLAL'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.

  wa_fcat-col_pos = 5.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'Component'.
  wa_fcat-seltext_m = 'Component'.
  wa_fcat-seltext_l = 'Component'.
  wa_fcat-fieldname = 'IDNRK'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.


  wa_fcat-col_pos = 6.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'Component'.
  wa_fcat-seltext_m = 'Component'.
  wa_fcat-seltext_l = 'Component Quantity'.
  wa_fcat-fieldname = 'MENGE'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.

  wa_fcat-col_pos = 7.
  wa_fcat-row_pos = 1.
  wa_fcat-seltext_s = 'Component'.
  wa_fcat-seltext_m = 'Component'.
  wa_fcat-seltext_l = 'Component Unit'.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-tabname = 'ITAB'.
  APPEND wa_fcat TO t_fcat.
  CLEAR t_fcat.


ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  SORTING
*&---------------------------------------------------------------------*
FORM SORTING .

wa_sort-fieldname = 'MATNR'.
wa_sort-tabname   = 'ITAB'.
wa_sort-spos      = 1.
wa_sort-up        = 'X'.
wa_sort-subtot    = 'X'.
APPEND wa_sort TO it_sortcat.
CLEAR wa_sort.

wa_sort-fieldname = 'WERKS'.
wa_sort-tabname   = 'ITAB'.
wa_sort-spos      = 2.
wa_sort-up        = 'X'.
wa_sort-subtot    = 'X'.
APPEND wa_sort TO it_sortcat.
CLEAR wa_sort.

wa_sort-fieldname = 'STLAN'.
wa_sort-tabname   = 'ITAB'.
wa_sort-spos      = 3.
wa_sort-up        = 'X'.
wa_sort-subtot    = 'X'.
APPEND wa_sort TO it_sortcat.
CLEAR wa_sort.

wa_sort-fieldname = 'STLAL'.
wa_sort-tabname   = 'ITAB'.
wa_sort-spos      = 4.
wa_sort-up        = 'X'.
wa_sort-subtot    = 'X'.
APPEND wa_sort TO it_sortcat.





ENDFORM.                    " SORTING



*

*----------------------------------------------------------------------*
*      Form  BUILD_LAYOUT
*----------------------------------------------------------------------*

FORM BUILD_LAYOUT .

GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-TOTALS_TEXT = 'TOTALS'.

ENDFORM.                    " BUILD_LAYOUT

*---------------------------------------------------------------------*
*      Form  BUILD_ALV_GRID_DISPLAY
*----------------------------------------------------------------------*

FORM BUILD_ALV_GRID_DISPLAY .

gd_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program      = gd_repid
            i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM
            i_callback_user_command = 'USER_COMMAND'
            is_layout               = gd_layout
            it_fieldcat             = t_fcat[]
            it_events               = gt_events
            is_print                = gd_prntparams
            it_sort                 = it_sortcat[]
            i_save                  = 'X'
       TABLES
            t_outtab                = ITAB
       EXCEPTIONS
            program_error           = 1
            OTHERS                  = 2.

with regards

murugeshRajeev

Edited by: Matt on Jan 13, 2009 8:01 AM - added tags

Read only

0 Likes
2,286

use below f.m to get all bom details...

DATA: M_CAPID LIKE RC29L-CAPID VALUE 'PP01',

M_DATUV LIKE RC29L-DATUV,

M_EMENG LIKE RC29L-EMENG VALUE 1,

M_MATNR LIKE RC29L-MATNR.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

EXPORTING

CAPID = M_CAPID

DATUV = M_DATUV

EHNDL = '1'

EMENG = M_EMENG

MKTLS = 'X'

MEHRS = 'X' "Multi-level

MTNRV = ITAB-MATNR

STLAL = ITAB-STLAL

STLAN = '1'

WERKS = ITAB-WERKS

TABLES

STB = ISTB-------here u will get all bom details

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.

Read only

0 Likes
2,286

Hi,

To get all BOM components and other details

use this FM

CALL FUNCTION 'CSAP_MAT_BOM_READ'

EXPORTING

material = wa_mast-matnr

plant = wa_mast-werks

bom_usage = wa_mast-stlan

alternative = wa_mast-stlal

IMPORTING

fl_warning = fg_warning

TABLES

t_stpo = it_tstp2

t_stko = it_tstk2

EXCEPTIONS

error = 1

OTHERS = 2.

Read only

0 Likes
2,286

hi,

can i have some sample coding for requirment

with regards

murugeshRajeev

Read only

0 Likes
2,286

hello shan,

can i have some sample coding sir.

regards

murugesh

Read only

0 Likes
2,286

Hi,

Look at this code

READ TABLE it_mast INTO wa_mast WITH KEY matnr = v_ww_result

werks = wa_mat_plant-werks.

IF sy-subrc = 0.

CALL FUNCTION 'CSAP_MAT_BOM_READ'

EXPORTING

material = wa_mast-matnr

plant = wa_mast-werks

bom_usage = wa_mast-stlan

alternative = wa_mast-stlal

IMPORTING

fl_warning = fg_warning

TABLES

t_stpo = it_tstp2

t_stko = it_tstk2

EXCEPTIONS

error = 1

OTHERS = 2.

IF sy-subrc = 0.

READ TABLE it_tstk2 INTO wa_tstk2 INDEX 1.

v_base_quantity = wa_tstk2-base_quan.

TRANSLATE v_base_quantity USING ', '.

CONDENSE v_base_quantity NO-GAPS.

LOOP AT it_tstp2 INTO wa_tstp2 WHERE item_categ = c_l.

MOVE wa_tstp2-component TO wa_bom_com-idnrk.

APPEND wa_bom_com TO it_bom_com.

ENDLOOP.

ELSE.

wa_emsg-msg_type = c_error.

wa_emsg-plant = wa_mat_plant-werks.

wa_emsg-material = v_ww_result.

wa_emsg-eff_date = v_eff.

wa_emsg-description = text-108.

APPEND wa_emsg TO it_emsg.

PERFORM f_errfile.

ENDIF.

ELSE.

wa_emsg-msg_type = c_error.

wa_emsg-plant = wa_mat_plant-werks.

wa_emsg-material = v_ww_result.

wa_emsg-eff_date = v_eff.

wa_emsg-description = text-109.

APPEND wa_emsg TO it_emsg.

PERFORM f_errfile.

ENDIF.

U need to give only MATNR, WERKS, STLAN and STLAL. just check this in SE37.

Read only

0 Likes
2,286

TYPES: BEGIN OF XT_TAB,

MATNR LIKE MAST-MATNR,

STLNR LIKE MAST-STLNR,

STLAL LIKE MAST-STLAL,

WERKS LIKE MAST-WERKS,

STLAN LIKE MAST-STLAN,

END OF XT_TAB.

-


I N T E R N A L T A B L E D E C L A R A T I O N S *

-


*-----Internal table to store data

DATA: WA_TAB1 TYPE XT_TAB.

data : i_stpo type table of STPOX with header line.

-


Selection Screen Declarations *

-


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

SELECTION-SCREEN SKIP.

SELECTION-SCREEN begin OF LINE.

SELECTION-SCREEN COMMENT (23) text-002 FOR FIELD P_MATNR.

SELECT-OPTIONS: P_MATNR FOR MAST-MATNR.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK bk1.

START-OF-SELECTION.

PERFORM XTRACT_DATA.

END-OF-SELECTION.

PERFORM BUILD_FIELDCATALOG.

PERFORM SORTING.

PERFORM BUILD_LAYOUT.

PERFORM BUILD_ALV_GRID_DISPLAY.

-


Form XTRACT_DATA

-


FORM XTRACT_DATA .

SELECT single

MATNR

WERKS

STLNR

STLAL

STLAN

INTO xt_ ITAB1

FROM MAST

WHERE MATNR IN P_MATNR.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

EXPORTING

CAPID = M_CAPID

DATUV = M_DATUV

EHNDL = '1'

EMENG = M_EMENG

MKTLS = 'X'

MEHRS = 'X' "Multi-level

MTNRV = xt_ ITAB1-MATNR

STLAL = xt_ ITAB1-STLAL

STLAN = '1'

WERKS = xt_ ITAB1-WERKS

TABLES

STB = I_stpo-------here u will get all bom details

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.

ENDFORM. " XTRACT_DATA

-


Form BUILD_FIELDCATALOG

-


FORM BUILD_FIELDCATALOG .

REFRESH t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 1.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'Material Number'.

wa_fcat-seltext_m = 'Material Number'.

wa_fcat-seltext_l = 'Material Number'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 2.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'PLANT'.

wa_fcat-seltext_m = 'PLANT'.

wa_fcat-seltext_l = 'PLANT'.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 3.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'BOM Usage'.

wa_fcat-seltext_m = 'BOM Usage'.

wa_fcat-seltext_l = 'BOM Usage'.

wa_fcat-fieldname = 'STLAN'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 4.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'ALT_BOM'.

wa_fcat-seltext_m = 'ALT_BOM'.

wa_fcat-seltext_l = 'ALT_BOM'.

wa_fcat-fieldname = 'STLAL'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 5.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'Component'.

wa_fcat-seltext_m = 'Component'.

wa_fcat-seltext_l = 'Component'.

wa_fcat-fieldname = 'IDNRK'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 6.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'Component'.

wa_fcat-seltext_m = 'Component'.

wa_fcat-seltext_l = 'Component Quantity'.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

wa_fcat-col_pos = 7.

wa_fcat-row_pos = 1.

wa_fcat-seltext_s = 'Component'.

wa_fcat-seltext_m = 'Component'.

wa_fcat-seltext_l = 'Component Unit'.

wa_fcat-fieldname = 'MEINS'.

wa_fcat-tabname = 'ITAB'.

APPEND wa_fcat TO t_fcat.

CLEAR t_fcat.

ENDFORM. " BUILD_FIELDCATALOG

&----


*& Form SORTING

&----


FORM SORTING .

wa_sort-fieldname = 'MATNR'.

wa_sort-tabname = 'ITAB'.

wa_sort-spos = 1.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sortcat.

CLEAR wa_sort.

wa_sort-fieldname = 'WERKS'.

wa_sort-tabname = 'ITAB'.

wa_sort-spos = 2.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sortcat.

CLEAR wa_sort.

wa_sort-fieldname = 'STLAN'.

wa_sort-tabname = 'ITAB'.

wa_sort-spos = 3.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sortcat.

CLEAR wa_sort.

wa_sort-fieldname = 'STLAL'.

wa_sort-tabname = 'ITAB'.

wa_sort-spos = 4.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sortcat.

ENDFORM. " SORTING

*

-


Form BUILD_LAYOUT

-


FORM BUILD_LAYOUT .

GD_LAYOUT-NO_INPUT = 'X'.

GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

GD_LAYOUT-TOTALS_TEXT = 'TOTALS'.

ENDFORM. " BUILD_LAYOUT

-


Form BUILD_ALV_GRID_DISPLAY

-


FORM BUILD_ALV_GRID_DISPLAY .

gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = gd_repid

i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

i_callback_user_command = 'USER_COMMAND'

is_layout = gd_layout

it_fieldcat = t_fcat[]

it_events = gt_events

is_print = gd_prntparams

it_sort = it_sortcat[]

i_save = 'X'

TABLES

t_outtab = ITAB

EXCEPTIONS

program_error = 1

OTHERS = 2.

Edited by: shan palani on Jan 8, 2009 1:44 PM

Read only

Former Member
0 Likes
2,286

Hi

Please try below tables

MAST - Material to BOM Link

STKO- BOM Header

STPO- BOM Item

MKAL - Production Versions of Material

Regards

Shiva

Read only

Former Member
0 Likes
2,286

BOM REPORT AS ANSWERED

Read only

Former Member
0 Likes
2,286

This message was moderated.

Read only

0 Likes
2,286

HI Murugesh,

Please read the rules of posting in the forums. You should not give attraction of giving points. This is against forum rules.

Regards,

Nikita

Read only

Former Member
0 Likes
2,286

i am getting some error in this report.

pls help me,how to do this alv report using CS_BOM_EXPL_MAT_V2 BAPI. <<Text removed>>

regards

MurugeshRajeev

Edited by: Matt on Jan 13, 2009 8:00 AM - removed offer

Read only

Former Member
0 Likes
2,286

Hi murugesh



*---------------------------------------------------------------------*
*                           T Y P E S                                 *
*---------------------------------------------------------------------*
types:
  begin of type_mast,
    matnr like mast-matnr,             " Material Number
    werks like mast-werks,             " Plant
    stlan like mast-stlan,             " BOM Usage
    stlnr like mast-stlnr,             " Bill of material
    stlal like mast-stlal,             " Alternative BOM
  end of type_mast,

  begin of type_makt,
    matnr like makt-matnr,             " Material Number
    maktx like makt-maktx,             " Material Description
  end of type_makt,

  begin of type_bom_hdr,
    stlty like stko-stlty,             " BOM category
    stlnr like stko-stlnr,             " Bill of material
    datuv like stko-datuv,             " Valid-From Date
    bmeng like stko-bmeng,             " Base Quantity
    stktx like stko-stktx,             " Alternative BOM Text
    stlst like stko-stlst,             " BOM status
  end of type_bom_hdr,

  begin of type_bom_item,
    stlty like stpo-stlty,             " BOM category
    stlnr like stpo-stlnr,             " Bill of material
    idnrk like stpo-idnrk,             " BOM component
    postp like stpo-postp,             " Item Category(BOM)
    posnr like stpo-posnr,             " BOM Item Number
    menge like stpo-menge,             " Component quantity
   end of type_bom_item,

  begin of type_bom_text,
    stlty like stpo-stlty,             " BOM category
    stlnr like stpo-stlnr,             " Bill of material
    ztext type stzu-ztext,             " BOM Text
  end of type_bom_text,


  begin of type_output,
   matnr like mast-matnr,             " Material Number
   werks like mast-werks,             " Plant
   stlan like mast-stlan,             " BOM Usage
   stlnr like mast-stlnr,             " Bill of material
   ztext type stzu-ztext,             " BOM Text
   stlal like mast-stlal,             " Alternative BOM
   maktx like makt-maktx,             " Material Description
   stlty like stko-stlty,             " BOM category
   datuv like stko-datuv,             " Valid-From Date
   bmeng like stko-bmeng,             " Base Quantity
   stktx like stko-stktx,             " Alternative BOM Text
   stlst like stko-stlst,             " BOM status
   idnrk like stpo-idnrk,             " BOM component
   postp like stpo-postp,             " Item Category(BOM)
   posnr like stpo-posnr,             " BOM Item Number
   menge like stpo-menge,             " Component quantity
  end of type_output.

*----------------------------------------------------------------------*
*                            D A T A                                   *
*----------------------------------------------------------------------*
data:
  w_matnr type mast-matnr,             " Material Number
  w_werks type mast-werks,             " Plant
  w_stlan type mast-stlan,             " BOM Usage
  w_stlst type stko-stlst,             " BOM status
  w_stlty type stko-stlty,             " BOM category
  ok_code like sy-ucomm,               " User Command

* Data reference of class ALV Grid
 my_alv_grid type ref to cl_gui_alv_grid,

* Data reference of class Custom Container
 r_container type ref to cl_gui_custom_container.



*---------------------------------------------------------------------*
*                  I N T E R N A L   T A B L E S                      *
*---------------------------------------------------------------------*
data:
* Material Data
  i_mast          type standard table of type_mast,
  wa_mast         type type_mast,

* Material Description Data
  i_makt          type standard table of type_makt,
  wa_makt         type type_makt,

* BOM Header Data
  i_stko          type standard table of type_bom_hdr,
  wa_stko         type type_bom_hdr,

* Output table
  i_output        type standard table of type_output,
  wa_output       type type_output,

* BOM Item Data
  i_stpo          type standard table of type_bom_item,
  wa_stpo         type type_bom_item,

* BOM Text
  i_bom_text      type standard table of type_bom_text,
  wa_bom_text     type type_bom_text,

* Feld Catlog table
 it_fcat          type lvc_t_fcat,
 wa_fcat          type lvc_s_fcat.



*---------------------------------------------------------------------*
*                 S E L E C T I O N     S C R E E N                   *
*---------------------------------------------------------------------*

select-options:
  s_matnr for w_matnr,             " Material Number
  s_werks for w_werks obligatory,  " Plant
  s_stlan for w_stlan,             " BOM Usage
  s_stlst for w_stlst,             " BOM status
  s_stlty for w_stlty.             " BOM category


*----------------------------------------------------------------------*
*               A T   S E L E C T I O N   S C R E E N                  *
*----------------------------------------------------------------------*
at selection-screen.
  perform f010_validate_material.
  perform f020_validate_plant.
  perform f030_validate_bom_usage.
  perform f040_validate_bom_status.
  perform f050_validate_bom_category.

*---------------------------------------------------------------------*
*                S T A R T   O F   S E L E C T I O N                  *
*---------------------------------------------------------------------*
start-of-selection .
  perform f200_fetch_bom_link_data.
  perform f210_fetch_material_des_data.
  perform f220_fetch_bom_header_data.
  perform f230_fetch_bom_text.
  perform f240_fetch_bom_item_data.


*---------------------------------------------------------------------*
*                  E N D   O F   S E L E C T I O N                    *
*---------------------------------------------------------------------*
end-of-selection.
  perform f600_display_data.
  perform f650_field_catlog .
  call screen 100.

*&--------------------------------------------------------------------*
*&      Form  F010_VALIDATE_MATERIAL                                  *
*&--------------------------------------------------------------------*
*       --Validate Material                                           *
*---------------------------------------------------------------------*
form f010_validate_material .

* Validate Material
  if s_matnr is not initial.
    select matnr
      into w_matnr
      from mara
     up to 1 rows
    where matnr in s_matnr.
    endselect.

    check sy-subrc ne 0.
    set cursor field 'S_MATNR'.
    message e000.                      " Invalid Material
  endif.
endform.                               " F010_VALIDATE_MATERIAL

*&--------------------------------------------------------------------*
*&      Form  F020_VALIDATE_PLANT                                     *
*&--------------------------------------------------------------------*
*       - Validate Plant                                              *
*---------------------------------------------------------------------*
form f020_validate_plant .

* Validate Plant

  select werks
    into w_werks
    from t001w
   up to 1 rows
   where werks in s_werks.
  endselect.

  check sy-subrc ne 0.
  set cursor field 'S_WERKS-LOW'.
  message e001.                        " Invalid Plant

endform.                               " F020_VALIDATE_PLANT

*&--------------------------------------------------------------------*
*&      Form  F030_VALIDATE_BOM_USAGE                                 *
*&--------------------------------------------------------------------*
*       -Validate BOM Usage                                           *
*---------------------------------------------------------------------*
form f030_validate_bom_usage .

* Validate BOM Usage
  if s_stlan is not initial.
    select stlan
      into w_stlan
      from t416
     up to 1 rows
     where stlan in s_stlan.
    endselect.

    check sy-subrc ne 0.
    set cursor field 'S_STLAN'.
    message e002.                      " Invalid BOM Usage
  endif.
endform.                               " F030_VALIDATE_BOM_USAGE

*&--------------------------------------------------------------------*
*&      Form  F040_VALIDATE_BOM_STATUS                                *
*&--------------------------------------------------------------------*
*       - Validate BOM Status                                         *
*---------------------------------------------------------------------*
form f040_validate_bom_status .

* Validate BOM Status
  if s_stlst is not initial.

    select stlst
      into w_stlst
      from t415s
     up to 1 rows
     where stlst in s_stlst.
    endselect.

    check sy-subrc ne 0.
    set cursor field 'S_STLST'.
    message e003.                      " Invalid BOM Status

  endif.

endform.                               " F040_VALIDATE_BOM_STATUS

*&--------------------------------------------------------------------*
*&      Form  F050_VALIDATE_BOM_CATEGORY                              *
*&--------------------------------------------------------------------*
*       -Validate BOM Category                                        *
*---------------------------------------------------------------------*
form f050_validate_bom_category .

* Validate BOM Category
  if s_stlty is not initial.
    select stlty
      into w_stlty
      from stko
     up to 1 rows
     where stlty in s_stlty.
    endselect.

    check sy-subrc ne 0.
    set cursor field 'S_STLTY'.
    message e004.                      " Invalid BOM Category
  endif.
endform.                               " F050_VALIDATE_BOM_CATEGORY

*&--------------------------------------------------------------------*
*&      Form  F200_FETCH_BOM_LINK_DATA                                *
*&--------------------------------------------------------------------*
*       - Fetch Material BOM Link data                                *
*---------------------------------------------------------------------*
form f200_fetch_bom_link_data .

* Fetch Material BOM Link data
  select matnr                         " Material Number
         werks                         " Plant
         stlan                         " BOM Usage
         stlnr                         " Bill of material
         stlal                         " Alternative BOM
    into table i_mast
    from mast
   where matnr in s_matnr
     and werks in s_werks.

  if sy-subrc ne 0.
    message s008.                     " No Data Found
    stop.
  endif.                              " IF sy-subrc NE 0.
  sort i_mast ascending by stlnr .
endform.                               " F200_FETCH_BOM_LINK_DATA

*&--------------------------------------------------------------------*
*&      Form  F210_FETCH_MATERIAL_DES_DATA                            *
*&--------------------------------------------------------------------*
*       -Fetch Material Description Data                              *
*---------------------------------------------------------------------*
form f210_fetch_material_des_data .
  data:
    i_mast_temp like table of wa_mast.

  i_mast_temp = i_mast.
  sort i_mast_temp by matnr.
  delete adjacent duplicates from i_mast_temp.


  select matnr
         maktx
    into table i_makt
    from makt
     for all entries in i_mast_temp
   where matnr eq i_mast_temp-matnr.

  if sy-subrc ne 0.
    message s008.                      " No Data Found
    stop.
  endif.                               " IF sy-subrc NE 0.

endform.                               " F210_FETCH_MATERIAL_DES_DATA

*&--------------------------------------------------------------------*
*&      Form  F220_FETCH_BOM_HEADER_DATA                              *
*&--------------------------------------------------------------------*
*       - Fetch BOM Header data                                       *
*---------------------------------------------------------------------*
form f220_fetch_bom_header_data .

* Fetch BOM Header data
  select stlty                         " BOM category
         stlnr                         " Bill of material
         datuv                         " Valid-From Date
         bmeng                         " Base Quantity
         stktx                         " Alternative BOM Text
         stlst                         " BOM status
    into table i_stko
    from stko
     for all entries in i_mast
   where stlnr eq i_mast-stlnr
     and stlty in s_stlty.

  if sy-subrc ne 0.
    message s008.                      " No Data Found
    stop.
  endif.                               " IF sy-subrc NE 0.
  sort i_stko ascending by stlty stlnr.
endform.                               " f220_fetch_bom_header_data


*&---------------------------------------------------------------------*
*&      Form  F230_FETCH_BOM_TEXT                                      *
*&---------------------------------------------------------------------*
* Fetch Bill of Material Text                                          *
*----------------------------------------------------------------------*

form f230_fetch_bom_text .
  data:
    i_stko_temp like table of wa_stko.

  i_stko_temp = i_stko.
  sort i_stko_temp by stlty stlnr.
  delete adjacent duplicates from i_stko_temp
    comparing stlty stlnr.

  select stlty
         stlnr
         ztext
    from stzu
    into table i_bom_text
    for all entries in i_stko_temp
  where stlty eq i_stko_temp-stlty
    and stlnr eq i_stko_temp-stlnr.

  if sy-subrc ne 0.
    message s008.                      " No Data Found
    stop.
  endif.                               " IF sy-subrc NE 0.
  sort i_bom_text by stlty stlnr.

endform.                               " F230_FETCH_BOM_TEXT

*&--------------------------------------------------------------------*
*&      Form  F240_FETCH_BOM_ITEM_DATA                                *
*&--------------------------------------------------------------------*
*       - Fetch BOM Item data                                         *
*---------------------------------------------------------------------*
form f240_fetch_bom_item_data .

* Fetch BOM Item data
  select stlty                         " BOM category
         stlnr                         " Bill of material
         idnrk                         " BOM component
         postp                         " Item Category(BOM)
         posnr                         " BOM Item Number
         menge                         " Component quantity
    into table i_stpo
    from stpo
     for all entries in i_stko
   where stlty eq i_stko-stlty
     and stlnr eq i_stko-stlnr.

  if sy-subrc ne 0.
    message s008.                      " No Data Found
    stop.
  endif.                               " IF sy-subrc NE 0.

endform.                               " F240_FETCH_BOM_ITEM_DATA

*&--------------------------------------------------------------------*
*&      Form  f600_display_data                                       *
*&--------------------------------------------------------------------*
*       - Displaying the data                                         *
*---------------------------------------------------------------------*
form f600_display_data .

  loop at i_stpo into wa_stpo .
    clear wa_output.
    move:
      wa_stpo-idnrk to wa_output-idnrk,
      wa_stpo-postp to wa_output-postp,
      wa_stpo-posnr to wa_output-posnr,
      wa_stpo-menge to wa_output-menge.

    read table i_stko into wa_stko with key stlnr = wa_stpo-stlnr
                                    binary search.

    check sy-subrc eq 0.
    move :
         wa_stko-stlty to wa_output-stlty,
         wa_stko-datuv to wa_output-datuv,
         wa_stko-bmeng to wa_output-bmeng,
         wa_stko-stktx to wa_output-stktx,
         wa_stko-stlst to wa_output-stlst.

    check sy-subrc eq 0.
    read table i_bom_text into wa_bom_text
                               with key stlnr = wa_stko-stlnr
                                        stlty = wa_stko-stlty
                                        binary search.
    move wa_bom_text-ztext to wa_output-ztext.

    check sy-subrc eq 0.
    read table i_mast into wa_mast with key stlnr = wa_stko-stlnr
                                  binary search.
    move:
       wa_mast-werks to wa_output-werks,
       wa_mast-matnr to wa_output-matnr,
       wa_mast-stlnr to wa_output-stlnr,
       wa_mast-stlan to wa_output-stlan,
       wa_mast-stlal to wa_output-stlal.

    check sy-subrc eq 0.
    read table i_makt into wa_makt with key matnr = wa_mast-matnr.

    check sy-subrc eq 0.
    move wa_makt-maktx to wa_output-maktx.
    append wa_output to i_output.

  endloop.                             " LOOP AT i_stpo

endform.                               " F600_display_data

*&---------------------------------------------------------------------*
*&      Form  F650_Field_CATALOG                                       *
*&---------------------------------------------------------------------*
*   Field Catlog Structure                                             *
*----------------------------------------------------------------------*

form f650_field_catlog .


  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-ref_table = 'MAST'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-ref_table = 'MAST'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'MAKTX'.
  wa_fcat-ref_table = 'MAKT'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'STLTY'.
  wa_fcat-ref_table = 'STKO'.
  append wa_fcat to it_fcat.


  clear wa_fcat.
  wa_fcat-fieldname = 'STLAN'.
  wa_fcat-ref_table = 'MAST'.
  wa_fcat-ref_field = 'STLAN'.

  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'STLNR'.
  wa_fcat-ref_table = 'MAST'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ZTEXT'.
  wa_fcat-ref_table = 'STZU'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'STLAL'.
  wa_fcat-ref_table = 'MAST'.
  wa_fcat-ref_field = 'STLAL'.

  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'STKTX'.
  wa_fcat-ref_table = 'STKO'.
  wa_fcat-ref_field = 'STKTX'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'DATUV'.
  wa_fcat-ref_table = 'STKO'.
  wa_fcat-ref_field = 'DATUV'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'BMENG'.
  wa_fcat-ref_table = 'STKO'.
  wa_fcat-ref_field = 'BMENG'.

  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'STLST'.
  wa_fcat-ref_table = 'STKO'.
  wa_fcat-ref_field = 'STLST'.

  append wa_fcat to it_fcat.

  clear wa_fcat.

  wa_fcat-fieldname = 'IDNRK'.
  wa_fcat-ref_table = 'STPO'.
  wa_fcat-ref_field = 'IDNRK'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'POSTP'.
  wa_fcat-ref_table = 'STPO'.
  wa_fcat-ref_field = 'POSTP'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'POSNR'.
  wa_fcat-ref_table = 'STPO'.
  wa_fcat-ref_field = 'POSNR'.
  append wa_fcat to it_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'MENGE'.
  wa_fcat-ref_table = 'STPO'.
  wa_fcat-ref_field = 'MENGE'.
  append wa_fcat to it_fcat.

endform.                               " F650_FIELD_CATLOG
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT                                    *
*&---------------------------------------------------------------------*
*  Module For Process Before Output                                    *
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status 'OUTPUT'.
*  SET TITLEBAR 'xxx'.


  if r_container is not initial.
    if cl_gui_alv_grid=>offline( ) is initial.

      create object r_container
        exporting
*    PARENT                      =
          container_name              = 'CUSTOM'
*    STYLE                       =
*    LIFETIME                    = lifetime_default
*    REPID                       =
*    DYNNR                       =
*    NO_AUTODEF_PROGID_DYNNR     =
      exceptions
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        others                      = 6.
      if sy-subrc <> 0.
        write : sy-subrc.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
   endif.
  endif.

      create object my_alv_grid
        exporting
*    I_SHELLSTYLE      = 0
*    I_LIFETIME        =
          i_parent          = r_container
*    I_APPL_EVENTS     = space
*    I_PARENTDBG       =
*    I_APPLOGPARENT    =
*    I_GRAPHICSPARENT  =
*    I_NAME            =
*    I_FCAT_COMPLETE   = SPACE
      exceptions
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        others            = 5.
      if sy-subrc <> 0.
        write : sy-subrc.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.


  call method my_alv_grid->set_table_for_first_display
*  EXPORTING
*    I_BUFFER_ACTIVE               = I_BUFFER_ACTIVE
*    I_BYPASSING_BUFFER            = I_BYPASSING_BUFFER
*    I_CONSISTENCY_CHECK           = I_CONSISTENCY_CHECK
*    I_STRUCTURE_NAME              = 'WA_OUTPUT'
**    IS_VARIANT                    = IS_VARIANT
*    I_SAVE                        = I_SAVE
*    I_DEFAULT                     = 'X'
*    IS_LAYOUT                     = IS_LAYOUT
*    IS_PRINT                      = IS_PRINT
*    IT_SPECIAL_GROUPS             = IT_SPECIAL_GROUPS
*    IT_TOOLBAR_EXCLUDING          = IT_TOOLBAR_EXCLUDING
*    IT_HYPERLINK                  = IT_HYPERLINK
*    IT_ALV_GRAPHICS               = IT_ALV_GRAPHICS
*    IT_EXCEPT_QINFO               = IT_EXCEPT_QINFO
*    IR_SALV_ADAPTER               = IR_SALV_ADAPTER
     changing
       it_outtab                     = i_output
       it_fieldcatalog               = it_fcat
*    IT_SORT                       = IT_SORT
*    IT_FILTER                     = IT_FILTER
     exceptions
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 3.
  if sy-subrc <> 0.
    write : sy-subrc.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.


endmodule.                             " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT                               *
*&---------------------------------------------------------------------*
*  Module For Process After Input                                      *
*----------------------------------------------------------------------*
module user_command_0100 input.

  case ok_code.
    when 'BACK' or 'CANCEL' or 'EXIT'.
      leave to screen 0.
  endcase.
endmodule.

Regards,

Sravanthi

Read only

Former Member
0 Likes
2,286

helpful answer