In this document ; Bill of material list report developed with alv concept to run all of materials which are listed by users. The most important trick is a solution of dublicate records in BOM tables so change number records.
For example : In belowed printscreen that you can see STPO table.
If you read STPO table without a restriction , you will get 2 rows for PY200005 Bom item material.
If you do not benefit change number functionality , you can join tables like belowed and it can be used to list BOMs.
But , change number functionality cause additional records in STPO and other related PP tables.
To solve this problem , you can benefit belowed alv report.
This report provides last record of changing component with change number.
Go to SE38 , add this code and list results.
*&---------------------------------------------------------------------*
*& Report ZPP_BILL_OF_MATERIAL
*&
*&---------------------------------------------------------------------*
*& M.Ozgur Unal ------ 04.11.2014
*& Ürün ağaçları listeleme raporudur.
*& özgü :)
*&---------------------------------------------------------------------*
REPORT ZPP_BILL_OF_MATERIAL.
TYPE-POOLS : slis.
CONSTANTS : c_tcode(4)TYPE c VALUE'CS03'.
TABLES : mast , stko , stpo , stas , makt , mara .
*************************
* DATA TYPES DEFINITIONS*
*************************
DATA: BEGINOF it_mast OCCURS0,
matnr LIKE mast-matnr,
werks LIKE mast-werks,
stlan LIKE mast-stlan,
stlnr LIKE mast-stlnr,
stlal LIKE mast-stlal,
maktx LIKE makt-maktx,
matkl LIKE mara-matkl,
ENDOF it_mast.
DATA : BEGINOF it_stko OCCURS 0,
stlnr LIKE stko-stlnr,
stlal LIKE stko-stlal,
datuv LIKE stko-datuv,
bmein LIKE stko-bmein,
bmeng LIKE stko-bmeng,
stlst LIKE stko-stlst,
ENDOF it_stko.
DATA : BEGINOF it_stpo OCCURS 0,
stlnr LIKE stpo-stlnr,
stlkn LIKE stpo-stlkn,
datuv LIKE stpo-datuv,
idnrk LIKE stpo-idnrk,
meins LIKE stpo-meins,
menge LIKE stpo-menge,
aennr LIKE stpo-aennr,
andat LIKE stpo-andat,
annam LIKE stpo-annam,
aenam LIKE stpo-aenam,
posnr LIKE stpo-posnr,
maktx LIKE makt-maktx,
vgknt LIKE stpo-vgknt,
stvkn LIKE stpo-stvkn,
stpoz LIKE stpo-stpoz,
vgpzl LIKE stpo-vgpzl,
matkl LIKE mara-matkl,
ENDOF it_stpo.
DATA : BEGINOF it_stas OCCURS 0,
stlnr LIKE stas-stlnr,
stlal LIKE stas-stlal,
stlkn LIKE stas-stlkn,
aennr LIKE stas-aennr,
lkenz LIKE stas-lkenz,
stvkn LIKE stas-stvkn,
ENDOF it_stas.
DATA : BEGINOF it_final OCCURS 0,
matnr LIKE mast-matnr,
werks LIKE mast-werks,
stlan LIKE mast-stlan,
stlnr LIKE mast-stlnr,
stlal LIKE mast-stlal,
datuv LIKE stko-datuv,
bmein LIKE stko-bmein,
bmeng LIKE stko-bmeng,
idnrk LIKE stpo-idnrk,
posnr LIKE stpo-posnr,
meins LIKE stpo-meins,
menge LIKE stpo-menge,
maktx LIKE makt-maktx,
aennr LIKE stpo-aennr,
andat LIKE stpo-andat,
annam LIKE stpo-annam,
aenam LIKE stpo-aenam,
matkl LIKE mara-matkl,
stlst LIKE stko-stlst,
lkenz LIKE stas-lkenz,
maktx2 LIKE makt-maktx,
stvkn LIKE stas-stvkn,
vgknt LIKE stpo-vgknt,
stlkn LIKE stpo-stlkn,
stvkn2 LIKE stpo-stvkn,
stpoz LIKE stpo-stpoz,
vgpzl LIKE stpo-vgpzl,
matkl2 LIKE mara-matkl,
ENDOF it_final.
DATA : wa_mast LIKELINEOF it_mast.
DATA : wa_stko LIKELINEOF it_stko.
DATA : wa_stpo LIKELINEOF it_stpo,
wa_stas LIKELINEOF it_stas,
gw_final LIKELINEOF it_final,
gw_final2 LIKELINEOF it_final,
gt_fcat TYPE slis_t_fieldcat_alv,
gw_fcat TYPE slis_fieldcat_alv.
******************
*SELECTION SCREEN*
******************
SELECTION-SCREENBEGINOFBLOCK blk WITHFRAMETITLE text-001.
SELECT-OPTIONS: s_matnr FOR mast-matnr,
s_matkl FOR mara-matkl.
PARAMETERS p_werks TYPE mast-werks OBLIGATORYDEFAULT1006.
SELECTION-SCREENENDOFBLOCK blk.
*******************************
*GET DATA & INSERT TO GT_FINAL*
*******************************
PERFORM get_data.
PERFORM loop_data.
IF it_final[] ISNOTINITIAL.
PERFORM f_fill_fcat .
PERFORM f_display_alv .
ELSE.
MESSAGE'Veri bulunamadı'TYPE'I'.
ENDIF.
PERFORM plant_validation.
*&---------------------------------------------------------------------*
*& Form FETCH_DATA_RETREIVE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
" break ounal.
SELECT mast~matnr mast~werks mast~stlan mast~stlnr mast~stlal
makt~maktx mara~matkl
INTOCORRESPONDINGFIELDSOFTABLE it_mast
FROM mast
INNERJOIN makt
ON mast~matnr = makt~matnr
INNERJOIN mara
ON makt~matnr = mara~matnr
WHERE mast~matnr IN s_matnr
AND mast~werks = p_werks
AND mast~stlan ='1'
AND mara~matkl IN s_matkl.
IFLINES( it_mast )GT0.
SELECT stlnr stlal datuv bmein bmeng
aennr andat annam aenam stlst
FROM stko
INTOCORRESPONDINGFIELDSOFTABLE it_stko
FORALLENTRIESIN it_mast
WHERE stlnr = it_mast-stlnr AND
stlal = it_mast-stlal.
SORT it_stko BY datuv DESCENDING.
SELECT stlnr stlal stlkn lkenz aennr stvkn
FROM stas INTOCORRESPONDINGFIELDSOFTABLE it_stas
FORALLENTRIESIN it_mast
WHERE stlnr = it_mast-stlnr AND
stlal = it_mast-stlal.
SORT it_stas BY lkenz DESCENDING.
ENDIF.
*20.11.2014 - M.Ozgur Unal
*Üretim tarafından bileşenlerin mal grubu eklenmesi talebi ile
*revize edildi.
IFLINES( it_stko )GT0.
SELECT stpo~stlnr stpo~stlkn stpo~datuv stpo~idnrk
stpo~posnr stpo~meins stpo~menge stpo~aennr
stpo~andat stpo~annam stpo~aenam stpo~posnr
makt~maktx stpo~vgknt stpo~stvkn stpo~stpoz
stpo~vgpzl mara~matkl
FROM stpo
INNERJOIN makt
ON stpo~idnrk = makt~matnr
INNERJOIN mara
ON makt~matnr = mara~matnr
INTOCORRESPONDINGFIELDSOFTABLE it_stpo
FORALLENTRIESIN it_mast
WHERE stlnr = it_mast-stlnr.
ENDIF.
ENDFORM. " FETCH_DATA_RETREIVE
*&---------------------------------------------------------------------*
*& Form LOOP_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM loop_data .
REFRESH it_final.
LOOPAT it_mast INTO wa_mast.
LOOPAT it_stpo INTO wa_stpo WHERE stlnr = wa_mast-stlnr.
IF sy-subrc =0.
MOVE: wa_mast-matnr TO gw_final-matnr,
wa_mast-stlnr TO gw_final-stlnr,
wa_mast-werks TO gw_final-werks,
wa_mast-stlal TO gw_final-stlal,
wa_mast-stlan TO gw_final-stlan,
wa_mast-matkl TO gw_final-matkl,
wa_mast-maktx TO gw_final-maktx2,
wa_stpo-matkl TO gw_final-matkl2,
wa_stpo-idnrk TO gw_final-idnrk,
wa_stpo-menge TO gw_final-menge,
wa_stpo-aennr TO gw_final-aennr,
wa_stpo-andat TO gw_final-andat,
wa_stpo-annam TO gw_final-annam,
wa_stpo-aenam TO gw_final-aenam,
wa_stpo-posnr TO gw_final-posnr,
wa_stpo-meins TO gw_final-meins,
wa_stpo-maktx TO gw_final-maktx,
wa_stpo-datuv TO gw_final-datuv,
wa_stpo-stlkn TO gw_final-stlkn,
wa_stpo-vgknt TO gw_final-vgknt,
wa_stpo-stvkn TO gw_final-stvkn2,
wa_stpo-stpoz TO gw_final-stpoz,
wa_stpo-vgpzl TO gw_final-vgpzl.
READTABLE it_stko INTO wa_stko WITHKEY stlnr = wa_mast-stlnr
stlal = wa_mast-stlal.
IF sy-subrc =0.
MOVE: wa_stko-stlst TO gw_final-stlst,
wa_stko-bmein TO gw_final-bmein,
wa_stko-bmeng TO gw_final-bmeng.
ENDIF.
ENDIF.
READTABLE it_stas INTO wa_stas WITHKEY stlnr = wa_stpo-stlnr
" stlkn = wa_stpo-stlkn
stvkn = wa_stpo-stvkn.
MOVE: wa_stas-stvkn TO gw_final-stvkn,
wa_stas-lkenz TO gw_final-lkenz.
APPEND gw_final TO it_final.
CLEAR gw_final.
ENDLOOP.
ENDLOOP.
*add by ounal.
*Silinip yerine değişiklik no ile atama yapılan kalemlerin ürün
*ağaçlarında standart dışında eski düğüm ve eski sayaç no yu
*kullanarak atama yapıyoruz.
FIELD-SYMBOLS: <fs_it_final>LIKELINEOF it_final,
<fs_it_final2>LIKELINEOF it_final.
SORT it_final BY stlnr stlkn ASCENDING.
IFLINES( it_final )NE0.
LOOPAT it_final ASSIGNING<fs_it_final>.
LOOPAT it_final ASSIGNING<fs_it_final2>.
IF<fs_it_final>ISASSIGNED.
IF<fs_it_final2>ISASSIGNED.
IF<fs_it_final>-stlnr =<fs_it_final2>-stlnr AND
<fs_it_final>-stlkn =<fs_it_final2>-vgknt AND
<fs_it_final>-stpoz =<fs_it_final2>-vgpzl.
<fs_it_final>-idnrk =<fs_it_final2>-idnrk.
<fs_it_final>-menge =<fs_it_final2>-menge.
<fs_it_final>-aennr =<fs_it_final2>-aennr.
<fs_it_final>-matkl2 =<fs_it_final2>-matkl2.
<fs_it_final>-lkenz =''.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDFORM. " LOOP_DATA
*&---------------------------------------------------------------------*
*& Form f_fill_fcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_fill_fcat .
gw_fcat-col_pos =1.
gw_fcat-fieldname ='WERKS'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Üretim yeri'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =2.
gw_fcat-fieldname ='STLNR'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Ürün ağacı no.'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =3.
gw_fcat-fieldname ='STLAL'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Alternatif bom'.
* gw_fcat-do_sum = 'X'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =4.
gw_fcat-fieldname ='MATNR'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Malzeme No.'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =5.
gw_fcat-fieldname ='MAKTX2'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Kısa metin'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =6.
gw_fcat-fieldname ='IDNRK'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Bileşen'.
gw_fcat-outputlen =10.
* gw_fcat-emphasize = 'X'.
* gw_fcat-key = 'X'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =7.
gw_fcat-fieldname ='POSNR'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Kalem no'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =8.
gw_fcat-fieldname ='BMENG'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Temel miktar'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =9.
gw_fcat-fieldname ='MENGE'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Bileşen miktarı'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =10.
gw_fcat-fieldname ='AENAM'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Değiştiren'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =11.
gw_fcat-fieldname ='MATKL'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Mal grubu'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =12.
gw_fcat-fieldname ='AENNR'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Değişiklik no'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =13.
gw_fcat-fieldname ='ANDAT'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Kayıt tarihi'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =14.
gw_fcat-fieldname ='ANNAM'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Kaydeden'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =15.
gw_fcat-fieldname ='DATUV'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Geçerlilik başı'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =16.
gw_fcat-fieldname ='STLST'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Statü'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =17.
gw_fcat-fieldname ='BMEIN'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Temel ölçü'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =18.
gw_fcat-fieldname ='MEINS'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Bileşen ölçü'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =19.
gw_fcat-fieldname ='MAKTX'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Bileşen metni'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =20.
gw_fcat-fieldname ='LKENZ'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Silme'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =21.
gw_fcat-fieldname ='STVKN'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Düğüm as'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =22.
gw_fcat-fieldname ='VGKNT'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Önceki düğüm'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =23.
gw_fcat-fieldname ='STVKN2'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Düğüm po'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =24.
gw_fcat-fieldname ='STLKN'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Düğüm'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =25.
gw_fcat-fieldname ='STPOZ'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Dahili sayaç'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =26.
gw_fcat-fieldname ='VGPZL'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Eski sayaç'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
gw_fcat-col_pos =27.
gw_fcat-fieldname ='MATKL2'.
gw_fcat-tabname ='IT_FINAL'.
gw_fcat-seltext_m ='Bileşen mal grubu'.
APPEND gw_fcat TO gt_fcat.
CLEAR gw_fcat.
ENDFORM. "f_fill_fcat
*&---------------------------------------------------------------------*
*& Form f_display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_display_alv .
DATA:lv_repid TYPE sy-repid.
lv_repid = sy-cprog.
DATA: w_layout TYPE slis_layout_alv.
w_layout-colwidth_optimize ='X'.
w_layout-zebra ='X'.
CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
is_layout = w_layout
i_callback_user_command ='USER_COMMAND'
it_fieldcat = gt_fcat[]
i_default ='X'
i_save ='A'
TABLES
t_outtab = it_final
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.
ENDFORM. "f_display_alv
*&---------------------------------------------------------------------*
*& Form PLANT_VALIDATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM plant_validation .
DATA : lv_plant TYPE mast-werks.
SELECTSINGLE werks
FROM mast
INTO lv_plant
WHERE werks = p_werks.
IF sy-subrc NE0.
MESSAGE'Üretim yerini kontrol ediniz'TYPE'I'.
RETURN.
ENDIF.
ENDFORM. "PLANT_VALIDATION
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE
slis_selfield.
IF r_ucomm ='&IC1'.
READTABLE it_final INTO gw_final INDEX rs_selfield-tabindex.
rs_selfield-value = gw_final-matnr.
SETPARAMETERID'MAT'FIELD rs_selfield-value.
CALLTRANSACTION'CS03'ANDSKIPFIRSTSCREEN.
ENDIF.
ENDFORM. "user_command
Finally , you can get this list.
Regards.
M.Ozgur Unal