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

Former Member
0 Likes
626

Hi Gurus,

I want to extract the BOM details ..

i.e ) my report must work similar to CS12 transaction.

I have to extract the main component and the subcomponents associated with the main component .

Can you please give me some FM or BAPI that would help me .

I would definitely reward points .

Thanks ,

Roseline.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
553

You need to use MAST ,STKO,STPO Table

Try to use FM : CS_BOM_EXPL_MAT_V2

I have done one report similar to CS12 .

Check the program :

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

Thanks

Seshu

Hi Gurus,

I want to extract the BOM details ..

i.e ) my report must work similar to CS12 transaction.

I have to extract the main component and the subcomponents associated with the main component .

Can you please give me some FM or BAPI that would help me .

I would definitely reward points .

Thanks ,

Roseline.

2 REPLIES 2
Read only

Former Member
0 Likes
553

Hi Roseline,

Have a look at this link.

http://help.sap.com/saphelp_46c/helpdata/en/2e/e62c7dd435d1118b3f0060b03ca329/frameset.htm

It may not be much help to you.

Thanks

Aneesh.

Read only

Former Member
0 Likes
554

You need to use MAST ,STKO,STPO Table

Try to use FM : CS_BOM_EXPL_MAT_V2

I have done one report similar to CS12 .

Check the program :

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

Thanks

Seshu