Skip to Content
1
Jul 30, 2007 at 02:43 AM

Report Not able to generate values in output

37 Views

hi gurus,

i am not able to get the output for this report,pls help me in correcting the code and suggest me a sloution.Urgent...............

 

&----


*& Report ZRPP006

*&

&----


*&

*&

&----


&----


*& Modification History

&----


*& Change # | By | Date | Purpose of Change

&----


*& C0001 |pradeep.R | 20070629 | Total component request for sop&Copa

*& | | |

*& | | |

&----


-

report zrpp006 line-size 180 line-count 90

no standard page heading.

*

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

  • Class

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

*class cl_gui_column_tree definition load.

*class cl_gui_cfw definition load.

*

*data tree1 type ref to cl_gui_alv_tree.

*data mr_toolbar type ref to cl_gui_toolbar.

*

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

  • Include

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

*include <icon>.

*include bcalv_toolbar_event_receiver.

*include bcalv_tree_event_receiver.

include zipp007.

*

*

  • selection screen

selection-screen begin of block selscrb with frame title text-s01.

parameters: ra_SOP radiobutton group GRP default 'X',

ra_COPA radiobutton group GRP.

selection-screen end of block selscrb.

Data:pa_m_frm(6) type c,

pa_m_to(6) type c,

pa_y_frm(4) type c,

pa_y_to(4) type c,

ra_mth,

ra_yea,

l_mode.

*parameter: pa_m_frm(6) type c,

  • pa_m_to(6) type c,

  • pa_y_frm(4) type c,

  • pa_y_to(4) type c..

data: so_matnr,

so_matkl,

pa_stprs,

pa_werks ,

pa_vrsio .

selection-screen skip 1.

initialization.

clear: ta_vrsio, ta_type.

refresh: ta_vrsio, ta_type.

*at selection-screen on value-request for pa_vrsio.

  • call function 'F4IF_INT_TABLE_VALUE_REQUEST'

  • EXPORTING

  • retfield = 'VRSIO'

  • dynprofield = 'PA_VRSIO'

  • dynpprog = sy-cprog

  • dynpnr = sy-dynnr

  • value_org = 'S'

  • TABLES

  • value_tab = ta_vrsio.

Start-of-selection.

if ra_SOP eq 'X'.

submit ZRPP023 via selection-screen and return.

elseif ra_COPA eq 'X'.

submit ZRPP026 via selection-screen and return..

endif.

select * into corresponding fields of table ta_vrsio

from p44v

where gstru = 'S076'.

sort ta_vrsio by vrsio.

delete adjacent duplicates from ta_vrsio.

move 'MONTH' to ta_type-out_type.

append ta_type.

move 'YEAR' to ta_type-out_type.

append ta_type.

at selection-screen output.

if ra_mth = 'X'.

loop at screen.

if screen-name = 'PA_M_FRM'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C001007_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C002009_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = 'PA_M_TO'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C003012_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C004014_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = 'PA_Y_FRM'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C005017_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C006019_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = 'PA_Y_TO'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C007022_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C008024_1000'.

screen-active = '0'.

modify screen.

endif.

endloop.

elseif ra_yea = 'X'.

loop at screen.

if screen-name = 'PA_M_FRM'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C001007_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C002009_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = 'PA_M_TO'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C003012_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = '%C004014_1000'.

screen-active = '0'.

modify screen.

endif.

if screen-name = 'PA_Y_FRM'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C005017_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C006019_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = 'PA_Y_TO'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C007022_1000'.

screen-active = '1'.

modify screen.

endif.

if screen-name = '%C008024_1000'.

screen-active = '1'.

modify screen.

endif.

endloop.

endif.

End-of-selection.

perform get_header_data.

perform get_top_page.

&----


*& Form display_alv

&----


  • text

----


form display_alv.

  • ALV ***

g_repid = sy-repid.

perform layout_init using gs_layout.

perform eventtab_build using gt_events[].

gs_variant-report = g_repid.

g_save = 'A'.

  • perform comment_build using gt_list_top_of_page[].

  • Display monthly report

if ra_mth = 'X' and

pa_m_frm <> 0 and

pa_m_to <> 0.

perform fieldcat_init_mth using gt_fieldcat[].

perform printer_setting using print_set.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_background_id = 'ALV_BACKGROUND'

i_buffer_active = 'X'

i_callback_program = g_repid

i_structure_name = 'ITAB_MSALE'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

i_save = g_save

is_variant = gs_variant

it_events = gt_events[]

it_sort = gt_it_sort[]

is_print = print_set

  • I_SCREEN_START_COLUMN = 0 "Use coordinates for

  • I_SCREEN_START_LINE = 0 "display as dialog box

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

importing

e_exit_caused_by_caller = g_exit_caused_by_caller

es_exit_caused_by_user = gs_exit_caused_by_user

tables

t_outtab = itab_msale

exceptions

program_error = 1

others = 2.

if sy-subrc = 0.

if g_exit_caused_by_caller = 'X'.

*" Forced Exit by calling program

*" <do_something>.

else.

*" User left list via F3, F12 or F15

if gs_exit_caused_by_user-back = 'X'. "F3

*" <do_something>.

else.

if gs_exit_caused_by_user-exit = 'X'. "F15

*" <do_something>.

else.

if gs_exit_caused_by_user-cancel = 'X'. "F12

*" <do_something>.

else.

*" should not occur!

*" <do_Abnormal_End>.

endif.

endif.

endif.

endif.

else.

"Fatal error callin ALVAXXX(XY) WITH ...

endif.

  • Display yearly report

elseif ra_yea = 'X' and

pa_y_frm <> 0 and

pa_y_to <> 0.

perform fieldcat_init_yr using gt_fieldcat[].

perform printer_setting using print_set.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_background_id = 'ALV_BACKGROUND'

i_buffer_active = 'X'

i_callback_program = g_repid

i_structure_name = 'ITAB_YSALE'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

i_save = g_save

is_variant = gs_variant

it_events = gt_events[]

it_sort = gt_it_sort[]

is_print = print_set

  • I_SCREEN_START_COLUMN = 0 "Use coordinates for

  • I_SCREEN_START_LINE = 0 "display as dialog box

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

importing

e_exit_caused_by_caller = g_exit_caused_by_caller

es_exit_caused_by_user = gs_exit_caused_by_user

tables

t_outtab = itab_ysale

exceptions

program_error = 1

others = 2.

if sy-subrc = 0.

if g_exit_caused_by_caller = 'X'.

*" Forced Exit by calling program

*" <do_something>.

else.

*" User left list via F3, F12 or F15

if gs_exit_caused_by_user-back = 'X'. "F3

*" <do_something>.

else.

if gs_exit_caused_by_user-exit = 'X'. "F15

*" <do_something>.

else.

if gs_exit_caused_by_user-cancel = 'X'. "F12

*" <do_something>.

else.

*" should not occur!

*" <do_Abnormal_End>.

endif.

endif.

endif.

endif.

else.

*"Fatal error callin ALV

  • MESSAGE AXXX(XY) WITH ...

endif.

else.

endif.

endform. "display_alv

&----


*& Form get_top_page

&----


  • text

----


form get_top_page.

move 'Total Component Requirement by Sales Forecast' to

gt_list_top_of_page-info.

gt_list_top_of_page-typ = 'H'.

append gt_list_top_of_page.

concatenate 'Plant :' pa_werks

into gt_list_top_of_page-info separated by space.

gt_list_top_of_page-typ = 'S'.

append gt_list_top_of_page.

select single vetxt into tp_vetxt

from p44v

where gstru = 'S076'

and vrsio = pa_vrsio.

concatenate 'Version :' pa_vrsio tp_vetxt

into gt_list_top_of_page-info separated by space.

gt_list_top_of_page-typ = 'S'.

append gt_list_top_of_page.

call function 'DATUMSAUFBEREITUNG'

EXPORTING

idate = sy-datum

IMPORTING

tdat8 = l_date_string

EXCEPTIONS

datfm_ungueltig = 1

datum_ungueltig = 2

others = 3.

concatenate sy-uzeit(2) ':' sy-uzeit2(2) ':' sy-uzeit4(2)

into l_time.

concatenate 'Date/Time :' l_date_string l_time

into gt_list_top_of_page-info separated by space.

gt_list_top_of_page-typ = 'S'.

append gt_list_top_of_page.

endform. "get_top_page

&----


*& Form get_header_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_header_data.

select pmnux into ta_mat-matnr

from s076

where pmnux = so_matnr

and wenux = pa_werks

and vrsio = pa_vrsio.

append ta_mat.

clear ta_mat.

endselect.

if sy-subrc = 0.

sort ta_mat by matnr .

delete adjacent duplicates from ta_mat.

loop at ta_mat.

select matnr stlnr stlan stlal

appending corresponding fields of table ta_mat2

from mast

where matnr = ta_mat-matnr

and werks = pa_werks.

endloop.

loop at ta_mat2 into wa_ta_mat.

select stlst bmeng bmein into (tp_stlst,tp_bmeng,tp_bmein)

from stko where stlnr = wa_ta_mat-stlnr

and stlal = wa_ta_mat-stlal.

wa_ta_mat-stlst = tp_stlst.

wa_ta_mat-bmeng = tp_bmeng.

wa_ta_mat-bmein = tp_bmein.

append wa_ta_mat to ta_header.

endselect.

endloop.

perform checking. "checking if monthly or yearly report is being selected

else.

message i003(zwpp001).

endif.

endform. " get_header_data

&----


*& Form checking

&----


  • text

----


form checking.

data : date1 like vtbbewe-dbervon,

date2 like vtbbewe-dberbis.

data : emonths like vtbbewe-atage.

data : lv_m_frm(6) type n,

lv_m_to(6) type n,

lv_y_frm(4) type n,

lv_y_to(4) type n.

  • check if the Display monthly report is being selected *****

if ra_mth = 'X' and

pa_m_frm <> 0 and

pa_m_to <> 0.

  • check for correct input format

lv_m_frm = pa_m_frm.

lv_m_to = pa_m_to.

if lv_m_frm ge '200000' and lv_m_to ge '200000'.

  • calculate the months in between

clear date1.

clear date2.

concatenate pa_m_frm '01' into date1.

concatenate pa_m_to '01' into date2.

  • concatenate pa_m_to '31' into date2.

perform months_calculate using date1 date2 changing emonths.

  • check if months <= 36.

if emonths <= 36.

perform get_sales.

perform retrieve_bom.

else.

message i000(zwpp001).

exit. " error message

endif.

else.

message i002(zwpp001).

endif.

  • check if the Display yearly report is being selected *****

elseif ra_yea = 'X' and

pa_y_frm <> 0 and

pa_y_to <> 0.

itab_bom-requantity = lp_s076-absat. "for current year 2006 ."added by pradeep on 4/07/07

itab_bom-requantity = lp_s076-absat + 1. "ie 2007.

itab_bom-requantity = lp_s076-absat + 2. "ie 2008.

  • check for correct input format

lv_y_frm = pa_y_frm.

lv_y_to = pa_y_to.

if lv_y_frm ge '2000' and lv_y_to ge '2000'.

  • calculate the months in between

clear date1.

clear date2.

concatenate pa_y_frm '0101' into date1.

concatenate pa_y_to '1201' into date2.

  • concatenate pa_y_to '1231' into date2.

perform months_calculate using date1 date2 changing emonths.

  • check if months <= 36.

if emonths <= 36.

perform get_sales.

perform retrieve_bom.

else.

message i001(zwpp001).

exit. " error message

endif.

else.

message i002(zwpp001).

endif.

else.

exit.

endif.

  • added by pradeep on 04/07/07

  • if emonths = 4.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • if emonths = 5.

  • tp_totalprice = lp_s076-absat * ta_mat-stprs.

  • endif.

  • if emonths = 6.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • if emonths = 7.

  • tp_totalprice = lp_s076-absat * ta_mat-stprs.

  • endif.

  • if emonths = 8.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • endform. " checking

    &----


    *& Form get_sales

    &----


    • text

    ----


    form get_sales.

    data: iseq type i,

    tp_sales type p decimals 2,

    tp_totalprice type p decimals 2,"added by pradeep on 03/07/07

    tp_maktx like makt-maktx,

    tp_tabix like sy-tabix,

    tp_pmnux like s076-pmnux,

    seq type i.

    data: yr_frm(6) type c,

    yr_to(6) type c.

    data: year_frm(4) type c,

    year_to(4) type c.

    data: month1(2) type c,

    month12(4) type c.

    data: totalsales like zspp003-mth1.

    data: yr_index like sy-subrc.

    • check if the Display monthly report is being selected *****

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    • retrieve months

    perform get_months.

    select * into corresponding fields of table lp_s076 from s076

    where pmnux = so_matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio

    and spmon ge pa_m_frm

    and spmon le pa_m_to.

    iseq = 1.

    seq = 0.

    loop at lp_s076.

    if sy-tabix = 1.

    write : lp_s076-pmnux to tp_pmnux.

    endif.

    select single maktx into tp_maktx from makt

    where matnr = lp_s076-pmnux.

    clear wa.

    read table ta_s076 into wa with key

    matnr = lp_s076-pmnux.

    if sy-subrc ne 0.

    wa-seq = iseq.

    wa-matnr = lp_s076-pmnux.

    wa-maktx = tp_maktx.

    endif.

    move lp_s076-absat to tp_sales.

    case lp_s076-spmon.

    when t_mth1.

    move tp_sales to wa-mth1.

    move t_mth1 to wa-sp1.

    ind1 = '1'.

    when t_mth2.

    move tp_sales to wa-mth2.

    move t_mth2 to wa-sp2.

    ind2 = '1'.

    when t_mth3.

    move tp_sales to wa-mth3.

    move t_mth3 to wa-sp3.

    ind3 = '1'.

    when t_mth4.

    move tp_sales to wa-mth4.

    move t_mth4 to wa-sp4.

    ind4 = '1'.

    when t_mth5.

    move tp_sales to wa-mth5.

    move t_mth5 to wa-sp5.

    ind5 = '1'.

    when t_mth6.

    move tp_sales to wa-mth6.

    move t_mth6 to wa-sp6.

    ind6 = '1'.

    when t_mth7.

    move tp_sales to wa-mth7.

    move t_mth7 to wa-sp7.

    ind7 = '1'.

    when t_mth8.

    move tp_sales to wa-mth8.

    move t_mth8 to wa-sp8.

    ind8 = '1'.

    when t_mth9.

    move tp_sales to wa-mth9.

    move t_mth9 to wa-sp9.

    ind9 = '1'.

    when t_mth10.

    move tp_sales to wa-mth10.

    move t_mth10 to wa-sp10.

    ind10 = '1'.

    when t_mth11.

    move tp_sales to wa-mth11.

    move t_mth11 to wa-sp11.

    ind11 = '1'.

    when t_mth12.

    move tp_sales to wa-mth12.

    move t_mth12 to wa-sp12.

    ind12 = '1'.

    when t_mth13.

    move tp_sales to wa-mth13.

    move t_mth13 to wa-sp13.

    ind13 = '1'.

    when t_mth14.

    move tp_sales to wa-mth14.

    move t_mth14 to wa-sp14.

    ind14 = '1'.

    when t_mth15.

    move tp_sales to wa-mth15.

    move t_mth15 to wa-sp15.

    ind15 = '1'.

    when t_mth16.

    move tp_sales to wa-mth16.

    move t_mth16 to wa-sp16.

    ind16 = '1'.

    when t_mth17.

    move tp_sales to wa-mth17.

    move t_mth17 to wa-sp17.

    ind17 = '1'.

    when t_mth18.

    move tp_sales to wa-mth18.

    move t_mth18 to wa-sp18.

    ind18 = '1'.

    when t_mth19.

    move tp_sales to wa-mth19.

    move t_mth19 to wa-sp19.

    ind19 = '1'.

    when t_mth20.

    move tp_sales to wa-mth20.

    move t_mth20 to wa-sp20.

    ind20 = '1'.

    when t_mth21.

    move tp_sales to wa-mth21.

    move t_mth21 to wa-sp21.

    ind21 = '1'.

    when t_mth22.

    move tp_sales to wa-mth22.

    move t_mth22 to wa-sp22.

    ind22 = '1'.

    when t_mth23.

    move tp_sales to wa-mth23.

    move t_mth23 to wa-sp23.

    ind23 = '1'.

    when t_mth24.

    move tp_sales to wa-mth24.

    move t_mth24 to wa-sp24.

    ind24 = '1'.

    when t_mth25.

    move tp_sales to wa-mth25.

    move t_mth25 to wa-sp25.

    ind25 = '1'.

    when t_mth26.

    move tp_sales to wa-mth26.

    move t_mth26 to wa-sp26.

    ind26 = '1'.

    when t_mth27.

    move tp_sales to wa-mth27.

    move t_mth27 to wa-sp27.

    ind27 = '1'.

    when t_mth28.

    move tp_sales to wa-mth28.

    move t_mth28 to wa-sp28.

    ind28 = '1'.

    when t_mth29.

    move tp_sales to wa-mth29.

    move t_mth29 to wa-sp29.

    ind29 = '1'.

    when t_mth30.

    move tp_sales to wa-mth30.

    move t_mth30 to wa-sp30.

    ind30 = '1'.

    when t_mth31.

    move tp_sales to wa-mth31.

    move t_mth31 to wa-sp31.

    ind31 = '1'.

    when t_mth32.

    move tp_sales to wa-mth32.

    move t_mth32 to wa-sp32.

    ind32 = '1'.

    when t_mth33.

    move tp_sales to wa-mth33.

    move t_mth33 to wa-sp33.

    ind33 = '1'.

    when t_mth34.

    move tp_sales to wa-mth34.

    move t_mth34 to wa-sp34.

    ind34 = '1'.

    when t_mth35.

    move tp_sales to wa-mth35.

    move t_mth35 to wa-sp35.

    ind35 = '1'.

    when t_mth36.

    move tp_sales to wa-mth36.

    move t_mth36 to wa-sp36.

    ind36 = '1'.

    endcase.

    • move seq to itab_seq-seq.

    • append itab_seq.

    tp_tabix = sy-tabix.

    if sy-subrc = 0.

    • modify table ta_s076 from wa.

    modify ta_s076 from wa index tp_tabix.

    if lp_s076-pmnux = tp_pmnux.

    seq = seq + 1.

    move seq to itab_seq.

    append itab_seq.

    endif.

    else.

    append wa to ta_s076.

    if lp_s076-pmnux = tp_pmnux.

    seq = seq + 1.

    move seq to itab_seq.

    append itab_seq.

    endif.

    endif.

    iseq = iseq + 1.

    endloop. " endloop for lp_s076.

    itb_sales[] = ta_s076[].

    • itb_sales12[] = ta_s076[].

    • check if the Display yearly report is being selected *****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear year1.

    clear year2.

    clear year3.

    perform get_years.

    loop at ta_mat.

    loop at ta_yr.

    clear yr_index.

    yr_index = sy-tabix.

    case yr_index.

    when '1'.

    year1 = ta_yr-year.

    when '2'.

    year2 = ta_yr-year.

    when '3'.

    year3 = ta_yr-year.

    endcase.

    clear yr_frm.

    clear yr_to.

    year_frm = ta_yr-year.

    year_to = ta_yr-year.

    month1 = '01'.

    month12 = '12'.

    concatenate year_frm month1 into yr_frm.

    concatenate year_to month12 into yr_to.

    select * into corresponding fields of table lp_s076 from s076

    where pmnux = ta_mat-matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio

    and spmon ge yr_frm

    and spmon le yr_to.

    • calculate total sales.

    totalsales = 0.

    loop at lp_s076.

    at first.

    sum.

    totalsales = lp_s076-absat.

    endat.

    at end of absat."added by pradeep on 4/07/07

    sum.

    tp_totalprice = lp_s076-absat * ta_mat-stprs.

    itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

    endat.

    endloop. "endloop for lp_s076

    select single maktx into tp_maktx from makt

    where matnr = ta_mat-matnr.

    read table ta_s076 into wa with key

    matnr = ta_mat-matnr.

    if sy-subrc ne 0.

    wa-matnr = lp_s076-pmnux.

    wa-maktx = tp_maktx.

    endif.

    case yr_index.

    when '1'.

    move totalsales to wa-sales_y1.

    move tp_totalprice to wa-sales_y1."added by pradeep

    move ta_yr-year to wa-year1.

    ind1 = '1'.

    when '2'.

    move totalsales to wa-sales_y2.

    move tp_totalprice to wa-sales_y2.

    move ta_yr-year to wa-year2.

    ind2 = '1'.

    when '3'.

    move totalsales to wa-sales_y3.

    move tp_totalprice to wa-sales_y3.

    move ta_yr-year to wa-year3.

    ind3 = '1'.

    endcase.

    tp_tabix = sy-tabix.

    if sy-subrc = 0.

    • modify table ta_s076 from wa.

    modify ta_s076 from wa index tp_tabix.

    else.

    append wa to ta_s076.

    endif.

    endloop. "endloop for ta_yr

    endloop. "endloop for ta_mat

    itb_sales[] = ta_s076[].

    else.

    exit.

    endif.

    endform. "get_sales

    &----


    *& Form get_months

    &----


    • text

    ----


    form get_months.

    move pa_m_frm to t_mth1.

    perform get_next_few_months

    using t_mth1 '1'

    changing t_mth2.

    perform get_next_few_months

    using t_mth2 '1'

    changing t_mth3.

    perform get_next_few_months

    using t_mth3 '1'

    changing t_mth4.

    perform get_next_few_months

    using t_mth4 '1'

    changing t_mth5.

    perform get_next_few_months

    using t_mth5 '1'

    changing t_mth6.

    perform get_next_few_months

    using t_mth6 '1'

    changing t_mth7.

    perform get_next_few_months

    using t_mth7 '1'

    changing t_mth8.

    perform get_next_few_months

    using t_mth8 '1'

    changing t_mth9.

    perform get_next_few_months

    using t_mth9 '1'

    changing t_mth10.

    perform get_next_few_months

    using t_mth10 '1'

    changing t_mth11.

    perform get_next_few_months

    using t_mth11 '1'

    changing t_mth12.

    perform get_next_few_months

    using t_mth12 '1'

    changing t_mth13.

    perform get_next_few_months

    using t_mth13 '1'

    changing t_mth14.

    perform get_next_few_months

    using t_mth14 '1'

    changing t_mth15.

    perform get_next_few_months

    using t_mth15 '1'

    changing t_mth16.

    perform get_next_few_months

    using t_mth16 '1'

    changing t_mth17.

    perform get_next_few_months

    using t_mth17 '1'

    changing t_mth18.

    perform get_next_few_months

    using t_mth18 '1'

    changing t_mth19.

    perform get_next_few_months

    using t_mth19 '1'

    changing t_mth20.

    perform get_next_few_months

    using t_mth20 '1'

    changing t_mth21.

    perform get_next_few_months

    using t_mth21 '1'

    changing t_mth22.

    perform get_next_few_months

    using t_mth22 '1'

    changing t_mth23.

    perform get_next_few_months

    using t_mth23 '1'

    changing t_mth24.

    perform get_next_few_months

    using t_mth24 '1'

    changing t_mth25.

    perform get_next_few_months

    using t_mth25 '1'

    changing t_mth26.

    perform get_next_few_months

    using t_mth26 '1'

    changing t_mth27.

    perform get_next_few_months

    using t_mth27 '1'

    changing t_mth28.

    perform get_next_few_months

    using t_mth28 '1'

    changing t_mth29.

    perform get_next_few_months

    using t_mth29 '1'

    changing t_mth30.

    perform get_next_few_months

    using t_mth30 '1'

    changing t_mth31.

    perform get_next_few_months

    using t_mth31 '1'

    changing t_mth32.

    perform get_next_few_months

    using t_mth32 '1'

    changing t_mth33.

    perform get_next_few_months

    using t_mth33 '1'

    changing t_mth34.

    perform get_next_few_months

    using t_mth34 '1'

    changing t_mth35.

    perform get_next_few_months

    using t_mth35 '1'

    changing t_mth36.

    endform. "get_months

    &----


    *& Form get_years

    &----


    • text

    ----


    form get_years.

    data : tp_yr_frm(4) type n.

    data : tp_yr_to(4) type n.

    data : yr_diff(4) type n.

    move pa_y_frm to tp_yr_frm.

    move pa_y_to to tp_yr_to.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    yr_diff = tp_yr_to - tp_yr_frm.

    *number of years = 3

    if yr_diff = 2.

    do 2 times.

    tp_yr_frm = tp_yr_frm + 1.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    enddo.

    *number of years = 2

    elseif yr_diff = 1.

    tp_yr_frm = tp_yr_frm + 1.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    else.

    exit.

    endif.

    endform. "get_years

    &----


    *& Form get_next_few_months

    &----


    • text

    ----


    • -->LV_CURR_MONTH text

    • -->LV_MONTHS text

    • -->LV_TARGET_MTH text

    ----


    form get_next_few_months using lv_curr_month lv_months

    changing lv_target_mth.

    data : tp_month_curr like sy-datum,

    tp_month_plus like sy-datum.

    concatenate lv_curr_month '01' into tp_month_curr.

    call function 'SG_PS_ADD_MONTH_TO_DATE'

    EXPORTING

    months = lv_months

    olddate = tp_month_curr

    IMPORTING

    newdate = tp_month_plus.

    move tp_month_plus(6) to lv_target_mth.

    endform. " get_months

    &----


    *& Form months_calculate

    &----


    • text

    ----


    • -->P_DATE1 text

    • -->P_DATE2 text

    • <--P_EMONTHS text

    ----


    form months_calculate using p_date1

    p_date2

    changing p_emonths.

    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

    exporting

    i_date_from = p_date1

    • I_KEY_DAY_FROM =

    i_date_to = p_date2

    • I_KEY_DAY_TO =

    • I_FLG_SEPARATE = ' '

    importing

    • E_DAYS =

    e_months = p_emonths.

    • E_YEARS =

    endform. " months_calculate

    &----


    *& Form retrieve_bom

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form retrieve_bom .

    • retrieve BOM components

    sort ta_header by matnr.

    loop at ta_header where stlan = '1' and stlst = '01'.

    tp_bmeng = '1'.

    perform get_bom tables ta_stpo using

    ta_header-matnr ta_header-werks ta_header-stlan ta_header-stlal tp_bmeng.

    • requirement quantity calculation for active bom

    perform calculation1.

    • retrieve BOM components for pgm

    sort itab_bom2 by idnrk ascending.

    delete adjacent duplicates from itab_bom2 comparing matnr idnrk.

    • loop at itab_bom2. " commented by weihong

    tp_stlan = '1'.

    tp_stlal = '02'.

    perform get_pgm tables ta_stpo12 using

    itab_bom2-matnr ta_header-werks tp_stlan tp_stlal.

    • endloop. " endloop for itab_bom2.(commented by weihong)

    • requirement quantity calculation for inactive bom

    perform calculation2.

    refresh : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    clear : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    endloop. " endloop for ta_header.

    **itab_msale itab_ysale

    *break-point.

    perform display_alv.

    endform. "retrieve bom

    &----


    *& Form get_bom

    &----


    • text

    ----


    • -->LV_MATNR text

    • -->LV_WERKS text

    • -->LV_STLAN text

    • -->LV_STLAL text

    ----


    form get_bom tables lt_stpo structure stpox

    using lv_matnr like mast-matnr

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal

    lv_emeng like stko-bmeng .

    data: ta_topmat type cstmat,

    tp_dstst like csdata-xfeld,

    ta_matcat type cscmat occurs 0,

    tp_index like sy-tabix,

    tp_stufe like stpox-stufe,

    tp_diff like stpox-stufe,

    tp_indx like sy-tabix,

    tp_date like sy-datum,

    lv_stufe like stpox-stufe,

    lv_wegxx like stpox-wegxx,

    lv_stprs like stpox-stprs,

    lv_waers like stpox-waers,

    • lv_cuky_new like cdpos-cuky_new,

    • lv_value_new like cdpos-value_new,

    lv_index like sy-tabix,

    lv_datum like sy-datum,"added by pradeep on 02-07-07

    nxt_index like sy-tabix.

    • added by weihong.

    data: tp_mtart like mara-mtart,

    tp_matkl like mara-matkl,

    tp_stprs like stpox-stprs,

    tp_bomlv1 like mast-matnr,

    tp_bomlv2 like mast-matnr,

    tp_bomlv3 like mast-matnr,

    tp_bomlv4 like mast-matnr,

    tp_indln type i.

    write : lv_matnr to itab_bom1-matnr.

    write : lv_matnr to itab_bom2-matnr.

    write : lv_matnr to itab_path-matnr.

    call function 'CS_BOM_EXPL_MAT_V2'

    exporting

    capid = 'PP01'

    datuv = sy-datum

    emeng = lv_emeng

    • ftrel = lv_level

    mktls = 'X'

    mehrs = 'X'

    rndkz = '2'

    mtnrv = lv_matnr

    stlal = lv_stlal

    stlan = lv_stlan

    stpst = '0'

    svwvo = 'X'

    werks = lv_werks

    vrsvo = 'X'

    ehndl = '2'

    importing

    topmat = ta_topmat

    dstst = tp_dstst

    tables

    stb = lt_stpo

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

    loop at lt_stpo.

    move lt_stpo-stufe to itab_path-stufe.

    move lt_stpo-wegxx to itab_path-wegxx.

    move lt_stpo-idnrk to itab_path-idnrk.

    append itab_path.

    endloop.

    *sort itab_path by stufe wegxx.

    loop at lt_stpo into wa_stpo.

    tp_tabix = sy-tabix.

    • check if level 1

    if wa_stpo-stufe = '1'.

    itab_bom1-bom = lv_matnr.

    • check if level 2

    elseif wa_stpo-stufe = '2'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '1'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv1 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '2'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv1..

    endif.

    • check if level 3

    elseif wa_stpo-stufe = '3'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '2'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv2 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '3'

    • wegxx = '1'.

    *

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv2.

    endif.

    • check if level 4

    elseif wa_stpo-stufe = '4'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '3'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv3 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '4'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv3.

    endif.

    elseif wa_stpo-stufe = '5'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '4'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv4 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '5'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv4.

    endif.

    else.

    endif.

    select single maktx into itab_bom1-c_maktx from makt

    where matnr = wa_stpo-idnrk.

    • if wa_stpo-mtart <> 'ZRUH'.

    move-corresponding wa_stpo to itab_bom1.

    append itab_bom1.

    • else.

    if wa_stpo-mtart eq 'ZRUH'.

    move-corresponding wa_stpo to itab_bom2.

    append itab_bom2.

    endif.

    *clear: tp_bomlv.

    endloop.

    refresh: lt_stpo.

    clear:lt_stpo.

    temp_bom1[] = itab_bom1[].

    describe table itab_bom1 lines tp_indln.

    loop at itab_bom1 where matnr = lv_matnr.

    if itab_bom1-mtart = 'ZHLB' and itab_bom1-matkl <> 'WP0100'

    and itab_bom1-matkl <> 'WP0110'

    and itab_bom1-matkl <> 'WP0120'.

    • tp_indx = sy-tabix.

    • lv_stufe = itab_bom1-stufe.

    • lv_wegxx = itab_bom1-wegxx + 1.

    • nxt_index = tp_indx + 1.

    *

    *

    • read table temp_bom1 index nxt_index.

    • if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    *

    • read table temp_bom1 with key stufe = lv_stufe

    • wegxx = lv_wegxx.

    • lv_index = sy-tabix - 1.

    • if lv_index > nxt_index.

    • append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    • endif.

    • clear: tp_indx, nxt_index, lv_index.

    *

    • endif.

    tp_indx = sy-tabix.

    lv_stufe = itab_bom1-stufe.

    lv_wegxx = itab_bom1-wegxx + 1.

    nxt_index = tp_indx + 1.

    read table temp_bom1 index nxt_index.

    if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    read table temp_bom1 with key stufe = lv_stufe

    wegxx = lv_wegxx.

    lv_index = sy-tabix - 1.

    if lv_index > nxt_index.

    append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    elseif lv_index < 0.

    append lines of itab_bom1 from nxt_index to tp_indln to itb_bm1.

    endif.

    clear: tp_indx, nxt_index, lv_index.

    endif.

    endif.

    endloop.

    • clear table

    • loop at itb_bm1 where matnr = ta_header-matnr.

    loop at itb_bm1 where matnr = lv_matnr.

    • loop at itab_bom1 where matnr = itb_bm1-matnr.

    delete itab_bom1 where stufe = itb_bm1-stufe and wegxx = itb_bm1-wegxx.

    • read table itab_bom1 with key stufe = itb_bm1-stufe

    • wegxx = itb_bm1-wegxx

    • matnr = itb_bm1-matnr

    • bom = itb_bm1-bom

    • idnrk = itb_bm1-idnrk.

    • if sy-subrc eq 0.

    • delete itab_bom1 index lv_index.

    • endif.

    • endloop.

    endloop.

    clear: itb_bm1.

    refresh: itb_bm1.

    loop at itab_bom1.

    tp_tabix = sy-tabix.

    if itab_bom1-mtart eq 'ZRUH'.

    delete itab_bom1 index tp_tabix.

    endif.

    endloop.

    if itab_bom1-stprs = ''.

    write: itab_bom-cuky_new.

    itab_bom1-stprs = 0.

    else.

    read table temp_bom1 with key objectid = itab_bom1-component.

    *

    endif.

    endform. "get_bom

    &----


    *& Form calculation1

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form calculation1.

    data : tp_tabix like sy-tabix.

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    clear wa.

    • loop at ta_s076 into wa where matnr = itab_bom11.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-mth1 = wa-mth1 * wa_bom1-mngko.

    wa-mth2 = wa-mth2 * wa_bom1-mngko.

    wa-mth3 = wa-mth3 * wa_bom1-mngko.

    wa-mth4 = wa-mth4 * wa_bom1-mngko.

    wa-mth5 = wa-mth5 * wa_bom1-mngko.

    wa-mth6 = wa-mth6 * wa_bom1-mngko.

    wa-mth7 = wa-mth7 * wa_bom1-mngko.

    wa-mth8 = wa-mth8 * wa_bom1-mngko.

    wa-mth9 = wa-mth9 * wa_bom1-mngko.

    wa-mth10 = wa-mth10 * wa_bom1-mngko.

    wa-mth11 = wa-mth11 * wa_bom1-mngko.

    wa-mth12 = wa-mth12 * wa_bom1-mngko.

    wa-mth13 = wa-mth13 * wa_bom1-mngko.

    wa-mth14 = wa-mth14 * wa_bom1-mngko.

    wa-mth15 = wa-mth15 * wa_bom1-mngko.

    wa-mth16 = wa-mth16 * wa_bom1-mngko.

    wa-mth17 = wa-mth17 * wa_bom1-mngko.

    wa-mth18 = wa-mth18 * wa_bom1-mngko.

    wa-mth19 = wa-mth19 * wa_bom1-mngko.

    wa-mth20 = wa-mth20 * wa_bom1-mngko.

    wa-mth21 = wa-mth21 * wa_bom1-mngko.

    wa-mth22 = wa-mth22 * wa_bom1-mngko.

    wa-mth23 = wa-mth23 * wa_bom1-mngko.

    wa-mth24 = wa-mth24 * wa_bom1-mngko.

    wa-mth25 = wa-mth25 * wa_bom1-mngko.

    wa-mth26 = wa-mth26 * wa_bom1-mngko.

    wa-mth27 = wa-mth27 * wa_bom1-mngko.

    wa-mth28 = wa-mth28 * wa_bom1-mngko.

    wa-mth29 = wa-mth29 * wa_bom1-mngko.

    wa-mth31 = wa-mth31 * wa_bom1-mngko.

    wa-mth32 = wa-mth32 * wa_bom1-mngko.

    wa-mth33 = wa-mth33 * wa_bom1-mngko.

    wa-mth34 = wa-mth34 * wa_bom1-mngko.

    wa-mth35 = wa-mth35 * wa_bom1-mngko.

    wa-mth36 = wa-mth36 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    wa-bom = wa_bom1-bom.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop. " endloop for itab_bom

    • check if the Display yearly report is being selected ****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear wa.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom1-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom1-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-bom = wa_bom1-bom.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop. " endloop for itab_bom

    else.

    endif.

    endform. " calculation1

    &----


    *& Form get_pgm

    &----


    • text

    ----


    • -->P_TA_STPO2 text

    • -->P_ITAB_BOM_MATNR text

    • -->P_PA_WERKS text

    • -->P_TP_STLAN text

    • -->P_TP_STLAL text

    ----


    form get_pgm tables lt_stpo12 structure bom_item_api01

    using lv_matnr like mast-matnr

    • lv_idnrk like stpox-idnrk

    pa_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal.

    data: lt_stko12 type stko_api02 occurs 0.

    data: tp_quantity like stpox-menge.

    write : lv_matnr to itab_pgm-matnr.

    • if lt_stpo12 is not initial.

    • refresh: lt_stpo12.

    • clear:lt_stpo12.

    • endif.

    call function 'CSEP_MAT_BOM_READ'

    EXPORTING

    material = lv_matnr

    plant = pa_werks

    bom_usage = lv_stlan

    alternative = lv_stlal

    TABLES

    t_stpo = lt_stpo12

    t_stko = lt_stko12

    EXCEPTIONS

    error = 1.

    • if sy-subrc ne 0.

    • message e066(zwaa001).

    • endif.

    if sy-subrc = 0.

    loop at lt_stpo12 into wa_stpo12.

    replace all occurrences of ',' in wa_stpo12-comp_qty with ''.

    move wa_stpo12-comp_qty to tp_quantity.

    select single maktx into itab_pgm-c_maktx from makt

    where matnr = wa_stpo12-component and

    spras = 'E'.

    move wa_stpo12-comp_qty to itab_pgm-mngko.

    move-corresponding wa_stpo12 to itab_pgm.

    • Added by Soh.

    select single matkl into itab_pgm-matkl

    from mara

    where matnr = itab_pgm-component.

    • Added by pradeep

    select single stprs into itab_pgm-stprs

    from mbew

    where matnr = itab_pgm-reQuantity.

    append itab_pgm.

    endloop.

    refresh: lt_stpo12.

    clear:lt_stpo12.

    endif.

    endform. " get_pgm

    &----


    *& Form calculation2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form calculation2.

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-mth1 = wa-mth1 * wa_bom2-mngko.

    wa-mth2 = wa-mth2 * wa_bom2-mngko.

    wa-mth3 = wa-mth3 * wa_bom2-mngko.

    wa-mth4 = wa-mth4 * wa_bom2-mngko.

    wa-mth5 = wa-mth5 * wa_bom2-mngko.

    wa-mth6 = wa-mth6 * wa_bom2-mngko.

    wa-mth7 = wa-mth7 * wa_bom2-mngko.

    wa-mth8 = wa-mth8 * wa_bom2-mngko.

    wa-mth9 = wa-mth9 * wa_bom2-mngko.

    wa-mth10 = wa-mth10 * wa_bom2-mngko.

    wa-mth11 = wa-mth11 * wa_bom2-mngko.

    wa-mth12 = wa-mth12 * wa_bom2-mngko.

    wa-mth13 = wa-mth13 * wa_bom2-mngko.

    wa-mth14 = wa-mth14 * wa_bom2-mngko.

    wa-mth15 = wa-mth15 * wa_bom2-mngko.

    wa-mth16 = wa-mth16 * wa_bom2-mngko.

    wa-mth17 = wa-mth17 * wa_bom2-mngko.

    wa-mth18 = wa-mth18 * wa_bom2-mngko.

    wa-mth19 = wa-mth19 * wa_bom2-mngko.

    wa-mth20 = wa-mth20 * wa_bom2-mngko.

    wa-mth21 = wa-mth21 * wa_bom2-mngko.

    wa-mth22 = wa-mth22 * wa_bom2-mngko.

    wa-mth23 = wa-mth23 * wa_bom2-mngko.

    wa-mth24 = wa-mth24 * wa_bom2-mngko.

    wa-mth25 = wa-mth25 * wa_bom2-mngko.

    wa-mth26 = wa-mth26 * wa_bom2-mngko.

    wa-mth27 = wa-mth27 * wa_bom2-mngko.

    wa-mth28 = wa-mth28 * wa_bom2-mngko.

    wa-mth29 = wa-mth29 * wa_bom2-mngko.

    wa-mth31 = wa-mth31 * wa_bom2-mngko.

    wa-mth32 = wa-mth32 * wa_bom2-mngko.

    wa-mth33 = wa-mth33 * wa_bom2-mngko.

    wa-mth34 = wa-mth34 * wa_bom2-mngko.

    wa-mth35 = wa-mth35 * wa_bom2-mngko.

    wa-mth36 = wa-mth36 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop.

    • check if the Display yearly report is being selected ****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom2-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom2-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop.

    else.

    endif.

    endform. " calculation_2

    Sop-

     
    

    &----


    *& Report ZRPP023

    *&

    &----


    &----


    *& Developer : Pradeep

    *& Date : 16/07/2007

    *& Description : Creation of sop Details

    &----


    report zrpp023 line-count 80 line-size 160 no standard page heading.

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

    • Class

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

    class cl_gui_column_tree definition load.

    class cl_gui_cfw definition load.

    data tree1 type ref to cl_gui_alv_tree.

    data mr_toolbar type ref to cl_gui_toolbar.

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

    • Include

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

    include <icon>.

    include bcalv_toolbar_event_receiver.

    include bcalv_tree_event_receiver.

    *include zrpp006top.

    include zipp007.

    • selection screen

    selection-screen begin of block selscrb with frame title text-s01. .

    select-options: so_matnr for mara-matnr.

    select-options: so_matkl for mara-matkl.

    parameter: pa_stprs like mbew-stprs.

    *parameter: pa_matnr like mara-matnr.

    parameter: pa_werks like t001l-werks obligatory default 'MY11',

    pa_vrsio like s076-vrsio obligatory default 'A00'.

    parameter:ra_mth radiobutton group rapt default 'X',

    ra_yea radiobutton group rapt.

    selection-screen end of block selscrb.

    Data:pa_m_frm(6) type c,

    pa_m_to(6) type c,

    pa_y_frm(4) type c,

    pa_y_to(4) type c.

    initialization.

    clear: ta_versi, ta_type.

    refresh: ta_versi, ta_type.

    at selection-screen on value-request for pa_vrsio.

    call function 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

    retfield = 'VRSIO'

    dynprofield = 'PA_VRSIO'

    dynpprog = sy-cprog

    dynpnr = sy-dynnr

    value_org = 'S'

    TABLES

    value_tab = ta_vrsio.

    Start-of-selection.

    if ra_mth eq 'X'.

    submit zrpp024 via selection-screen and return with pa_mth = ra_mth.

    elseif ra_yea eq 'X'.

    submit zrpp025 via selection-screen and return with pa_yea = ra_yea.

    endif.

    select * into corresponding fields of table ta_vrsio

    from p44v

    where gstru = 'S076'.

    sort ta_vrsio by vrsio.

    delete adjacent duplicates from ta_vrsio.

    move 'MONTH' to ta_type-out_type.

    append ta_type.

    move 'YEAR' to ta_type-out_type.

    append ta_type.

    End-of-selection.

    *call screen 100.

    perform get_header_data.

    perform get_top_page.

    *----


    • MODULE STATUS_0100 OUTPUT

    *----


    **

    *----


    *module status_0100 output.

    **

    • set pf-status 'SCREEN100'.

    • set titlebar 'SCREEN100'.

    *

    • if tree1 is initial.

    • perform init_tree.

    • endif.

    • call method cl_gui_cfw=>flush.

    *endmodule. " PBO OUTPUT

    *&----


    *& Form display_alv

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM display_alv .

    • ALV ***

    g_repid = sy-repid.

    perform layout_init using gs_layout.

    perform eventtab_build using gt_events[].

    gs_variant-report = g_repid.

    g_save = 'A'.

    • perform comment_build using gt_list_top_of_page[].

    • Display monthly report

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    perform fieldcat_init_mth using gt_fieldcat[].

    perform printer_setting using print_set.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_background_id = 'ALV_BACKGROUND'

    i_buffer_active = 'X'

    i_callback_program = g_repid

    i_structure_name = 'ITAB_MSALE'

    is_layout = gs_layout

    it_fieldcat = gt_fieldcat[]

    i_save = g_save

    is_variant = gs_variant

    it_events = gt_events[]

    it_sort = gt_it_sort[]

    is_print = print_set

    • I_SCREEN_START_COLUMN = 0 "Use coordinates for

    • I_SCREEN_START_LINE = 0 "display as dialog box

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    importing

    e_exit_caused_by_caller = g_exit_caused_by_caller

    es_exit_caused_by_user = gs_exit_caused_by_user

    tables

    t_outtab = itab_msale

    exceptions

    program_error = 1

    others = 2.

    if sy-subrc = 0.

    if g_exit_caused_by_caller = 'X'.

    *" Forced Exit by calling program

    *" <do_something>.

    else.

    *" User left list via F3, F12 or F15

    if gs_exit_caused_by_user-back = 'X'. "F3

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-exit = 'X'. "F15

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-cancel = 'X'. "F12

    *" <do_something>.

    else.

    *" should not occur!

    *" <do_Abnormal_End>.

    endif.

    endif.

    endif.

    endif.

    else.

    "Fatal error callin ALVAXXX(XY) WITH ...

    endif.

    • Display yearly report

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    perform fieldcat_init_yr using gt_fieldcat[].

    perform printer_setting using print_set.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_background_id = 'ALV_BACKGROUND'

    i_buffer_active = 'X'

    i_callback_program = g_repid

    i_structure_name = 'ITAB_YSALE'

    is_layout = gs_layout

    it_fieldcat = gt_fieldcat[]

    i_save = g_save

    is_variant = gs_variant

    it_events = gt_events[]

    it_sort = gt_it_sort[]

    is_print = print_set

    • I_SCREEN_START_COLUMN = 0 "Use coordinates for

    • I_SCREEN_START_LINE = 0 "display as dialog box

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    importing

    e_exit_caused_by_caller = g_exit_caused_by_caller

    es_exit_caused_by_user = gs_exit_caused_by_user

    tables

    t_outtab = itab_ysale

    exceptions

    program_error = 1

    others = 2.

    if sy-subrc = 0.

    if g_exit_caused_by_caller = 'X'.

    *" Forced Exit by calling program

    *" <do_something>.

    else.

    *" User left list via F3, F12 or F15

    if gs_exit_caused_by_user-back = 'X'. "F3

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-exit = 'X'. "F15

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-cancel = 'X'. "F12

    *" <do_something>.

    else.

    *" should not occur!

    *" <do_Abnormal_End>.

    endif.

    endif.

    endif.

    endif.

    else.

    *"Fatal error callin ALV

    • MESSAGE AXXX(XY) WITH ...

    endif.

    else.

    endif.

    ENDFORM. " display_alv

    &----


    *& Form get_top_page

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_top_page .

    move 'Total Component Requirement by Sales Forecast For Sop' to

    gt_list_top_of_page-info.

    gt_list_top_of_page-typ = 'H'.

    append gt_list_top_of_page.

    concatenate 'Plant :' pa_werks

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    select single vetxt into tp_vetxt

    from p44v

    where gstru = 'S076'

    and vrsio = pa_vrsio.

    concatenate 'Version :' pa_vrsio tp_vetxt

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    call function 'DATUMSAUFBEREITUNG'

    EXPORTING

    idate = sy-datum

    IMPORTING

    tdat8 = l_date_string

    EXCEPTIONS

    datfm_ungueltig = 1

    datum_ungueltig = 2

    others = 3.

    concatenate sy-uzeit(2) ':' sy-uzeit2(2) ':' sy-uzeit4(2)

    into l_time.

    concatenate 'Date/Time :' l_date_string l_time

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    ENDFORM. " get_top_page

    &----


    *& Form get_header_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_header_data .

    select pmnux into ta_mat-matnr

    from s076

    where pmnux in so_matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio.

    append ta_mat.

    clear ta_mat.

    endselect.

    if sy-subrc = 0.

    sort ta_mat by matnr .

    delete adjacent duplicates from ta_mat.

    loop at ta_mat.

    select matnr stlnr stlan stlal

    appending corresponding fields of table ta_mat2

    from mast

    where matnr = ta_mat-matnr

    and werks = pa_werks.

    endloop.

    loop at ta_mat2 into wa_ta_mat.

    select stlst bmeng bmein into (tp_stlst,tp_bmeng,tp_bmein)

    from stko

    where stlnr = wa_ta_mat-stlnr

    and stlal = wa_ta_mat-stlal.

    wa_ta_mat-stlst = tp_stlst.

    wa_ta_mat-bmeng = tp_bmeng.

    wa_ta_mat-bmein = tp_bmein.

    append wa_ta_mat to ta_header.

    endselect.

    endloop.

    perform checking. "checking if monthly or yearly report is being selected

    else.

    message i003(zwpp001).

    endif.

    ENDFORM. " get_header_data

    &----


    *& Form checking

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM checking .

    data : date1 like vtbbewe-dbervon,

    date2 like vtbbewe-dberbis.

    data : emonths like vtbbewe-atage.

    data : lv_m_frm(6) type n,

    lv_m_to(6) type n,

    lv_y_frm(4) type n,

    lv_y_to(4) type n.

    • check if the Display monthly report is being selected *****

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-XMENG .

    • check for correct input format

    lv_m_frm = pa_m_frm.

    lv_m_to = pa_m_to.

    if lv_m_frm ge '200000' and lv_m_to ge '200000'.

    • calculate the months in between

    clear date1.

    clear date2.

    concatenate pa_m_frm '01' into date1.

    concatenate pa_m_to '01' into date2.

    • concatenate pa_m_to '31' into date2.

    perform months_calculate using date1 date2 changing emonths.

    • check if months <= 36.

    if emonths <= 36.

    perform get_sales.

    perform retrieve_bom.

    else.

    message i000(zwpp001).

    exit. " error message

    endif.

    else.

    message i002(zwpp001).

    endif.

    • check if the Display yearly report is being selected *****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    *

    itab_bom-requantity = lp_s076-absat. "for current year 2006 ."added by pradeep on 4/07/07

    itab_bom-requantity = lp_s076-absat + 1. "ie 2007.

    itab_bom-requantity = lp_s076-absat + 2. "ie 2008.

    • check for correct input format

    lv_y_frm = pa_y_frm.

    lv_y_to = pa_y_to.

    if lv_y_frm ge '2000' and lv_y_to ge '2000'.

    • calculate the months in between

    clear date1.

    clear date2.

    concatenate pa_y_frm '0101' into date1.

    concatenate pa_y_to '1201' into date2.

    • concatenate pa_y_to '1231' into date2.

    perform months_calculate using date1 date2 changing emonths.

    • check if months <= 36.

    if emonths <= 36.

    perform get_sales.

    perform retrieve_bom.

    else.

    message i001(zwpp001).

    exit. " error message

    endif.

    else.

    message i002(zwpp001).

    endif.

    else.

    exit.

    endif.

    • added by pradeep on 04/07/07

  • if emonths = 4.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • if emonths = 5.

  • tp_totalprice = lp_s076-absat * ta_mat-stprs.

  • endif.

  • if emonths = 6.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • if emonths = 7.

  • tp_totalprice = lp_s076-absat * ta_mat-stprs.

  • endif.

  • if emonths = 8.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • endform. " checking

    &----


    *& Form get_sales

    &----


    • text

    ----


    form get_sales.

    data: iseq type i,

    tp_sales type p decimals 2,

    tp_totalprice type p decimals 2,"added by pradeep on 03/07/07

    tp_maktx like makt-maktx,

    tp_tabix like sy-tabix,

    tp_pmnux like s076-pmnux,

    seq type i.

    data: yr_frm(6) type c,

    yr_to(6) type c.

    data: year_frm(4) type c,

    year_to(4) type c.

    data: month1(2) type c,

    month12(4) type c.

    data: totalsales like zspp003-mth1.

    data: yr_index like sy-subrc.

    • check if the Display monthly report is being selected *****

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    • retrieve months

    perform get_months.

    select * into corresponding fields of table lp_s076 from s076

    where pmnux in so_matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio

    and spmon ge pa_m_frm

    and spmon le pa_m_to.

    iseq = 1.

    seq = 0.

    loop at lp_s076.

    if sy-tabix = 1.

    write : lp_s076-pmnux to tp_pmnux.

    endif.

    select single maktx into tp_maktx from makt

    where matnr = lp_s076-pmnux.

    clear wa.

    read table ta_s076 into wa with key

    matnr = lp_s076-pmnux.

    if sy-subrc ne 0.

    wa-seq = iseq.

    wa-matnr = lp_s076-pmnux.

    wa-maktx = tp_maktx.

    endif.

    move lp_s076-absat to tp_sales.

    case lp_s076-spmon.

    when t_mth1.

    move tp_sales to wa-mth1.

    move t_mth1 to wa-sp1.

    ind1 = '1'.

    when t_mth2.

    move tp_sales to wa-mth2.

    move t_mth2 to wa-sp2.

    ind2 = '1'.

    when t_mth3.

    move tp_sales to wa-mth3.

    move t_mth3 to wa-sp3.

    ind3 = '1'.

    when t_mth4.

    move tp_sales to wa-mth4.

    move t_mth4 to wa-sp4.

    ind4 = '1'.

    when t_mth5.

    move tp_sales to wa-mth5.

    move t_mth5 to wa-sp5.

    ind5 = '1'.

    when t_mth6.

    move tp_sales to wa-mth6.

    move t_mth6 to wa-sp6.

    ind6 = '1'.

    when t_mth7.

    move tp_sales to wa-mth7.

    move t_mth7 to wa-sp7.

    ind7 = '1'.

    when t_mth8.

    move tp_sales to wa-mth8.

    move t_mth8 to wa-sp8.

    ind8 = '1'.

    when t_mth9.

    move tp_sales to wa-mth9.

    move t_mth9 to wa-sp9.

    ind9 = '1'.

    when t_mth10.

    move tp_sales to wa-mth10.

    move t_mth10 to wa-sp10.

    ind10 = '1'.

    when t_mth11.

    move tp_sales to wa-mth11.

    move t_mth11 to wa-sp11.

    ind11 = '1'.

    when t_mth12.

    move tp_sales to wa-mth12.

    move t_mth12 to wa-sp12.

    ind12 = '1'.

    when t_mth13.

    move tp_sales to wa-mth13.

    move t_mth13 to wa-sp13.

    ind13 = '1'.

    when t_mth14.

    move tp_sales to wa-mth14.

    move t_mth14 to wa-sp14.

    ind14 = '1'.

    when t_mth15.

    move tp_sales to wa-mth15.

    move t_mth15 to wa-sp15.

    ind15 = '1'.

    when t_mth16.

    move tp_sales to wa-mth16.

    move t_mth16 to wa-sp16.

    ind16 = '1'.

    when t_mth17.

    move tp_sales to wa-mth17.

    move t_mth17 to wa-sp17.

    ind17 = '1'.

    when t_mth18.

    move tp_sales to wa-mth18.

    move t_mth18 to wa-sp18.

    ind18 = '1'.

    when t_mth19.

    move tp_sales to wa-mth19.

    move t_mth19 to wa-sp19.

    ind19 = '1'.

    when t_mth20.

    move tp_sales to wa-mth20.

    move t_mth20 to wa-sp20.

    ind20 = '1'.

    when t_mth21.

    move tp_sales to wa-mth21.

    move t_mth21 to wa-sp21.

    ind21 = '1'.

    when t_mth22.

    move tp_sales to wa-mth22.

    move t_mth22 to wa-sp22.

    ind22 = '1'.

    when t_mth23.

    move tp_sales to wa-mth23.

    move t_mth23 to wa-sp23.

    ind23 = '1'.

    when t_mth24.

    move tp_sales to wa-mth24.

    move t_mth24 to wa-sp24.

    ind24 = '1'.

    when t_mth25.

    move tp_sales to wa-mth25.

    move t_mth25 to wa-sp25.

    ind25 = '1'.

    when t_mth26.

    move tp_sales to wa-mth26.

    move t_mth26 to wa-sp26.

    ind26 = '1'.

    when t_mth27.

    move tp_sales to wa-mth27.

    move t_mth27 to wa-sp27.

    ind27 = '1'.

    when t_mth28.

    move tp_sales to wa-mth28.

    move t_mth28 to wa-sp28.

    ind28 = '1'.

    when t_mth29.

    move tp_sales to wa-mth29.

    move t_mth29 to wa-sp29.

    ind29 = '1'.

    when t_mth30.

    move tp_sales to wa-mth30.

    move t_mth30 to wa-sp30.

    ind30 = '1'.

    when t_mth31.

    move tp_sales to wa-mth31.

    move t_mth31 to wa-sp31.

    ind31 = '1'.

    when t_mth32.

    move tp_sales to wa-mth32.

    move t_mth32 to wa-sp32.

    ind32 = '1'.

    when t_mth33.

    move tp_sales to wa-mth33.

    move t_mth33 to wa-sp33.

    ind33 = '1'.

    when t_mth34.

    move tp_sales to wa-mth34.

    move t_mth34 to wa-sp34.

    ind34 = '1'.

    when t_mth35.

    move tp_sales to wa-mth35.

    move t_mth35 to wa-sp35.

    ind35 = '1'.

    when t_mth36.

    move tp_sales to wa-mth36.

    move t_mth36 to wa-sp36.

    ind36 = '1'.

    endcase.

    • move seq to itab_seq-seq.

    • append itab_seq.

    tp_tabix = sy-tabix.

    if sy-subrc = 0.

    • modify table ta_s076 from wa.

    modify ta_s076 from wa index tp_tabix.

    if lp_s076-pmnux = tp_pmnux.

    seq = seq + 1.

    move seq to itab_seq.

    append itab_seq.

    endif.

    else.

    append wa to ta_s076.

    if lp_s076-pmnux = tp_pmnux.

    seq = seq + 1.

    move seq to itab_seq.

    append itab_seq.

    endif.

    endif.

    iseq = iseq + 1.

    endloop. " endloop for lp_s076.

    itb_sales[] = ta_s076[].

    • itb_sales12[] = ta_s076[].

    • check if the Display yearly report is being selected *****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear year1.

    clear year2.

    clear year3.

    perform get_years.

    loop at ta_mat.

    loop at ta_yr.

    clear yr_index.

    yr_index = sy-tabix.

    case yr_index.

    when '1'.

    year1 = ta_yr-year.

    when '2'.

    year2 = ta_yr-year.

    when '3'.

    year3 = ta_yr-year.

    endcase.

    clear yr_frm.

    clear yr_to.

    year_frm = ta_yr-year.

    year_to = ta_yr-year.

    month1 = '01'.

    month12 = '12'.

    concatenate year_frm month1 into yr_frm.

    concatenate year_to month12 into yr_to.

    select * into corresponding fields of table lp_s076 from s076

    where pmnux = ta_mat-matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio

    and spmon ge yr_frm

    and spmon le yr_to.

    • calculate total sales.

    totalsales = 0.

    loop at lp_s076.

    at first.

    sum.

    totalsales = lp_s076-absat.

    endat.

    at end of absat."added by pradeep on 4/07/07

    sum.

    tp_totalprice = lp_s076-absat * ta_mat-stprs.

    itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

    endat.

    endloop. "endloop for lp_s076

    select single maktx into tp_maktx from makt

    where matnr = ta_mat-matnr.

    read table ta_s076 into wa with key

    matnr = ta_mat-matnr.

    if sy-subrc ne 0.

    wa-matnr = lp_s076-pmnux.

    wa-maktx = tp_maktx.

    endif.

    case yr_index.

    when '1'.

    move totalsales to wa-sales_y1.

    move tp_totalprice to wa-sales_y1."added by pradeep

    move ta_yr-year to wa-year1.

    ind1 = '1'.

    when '2'.

    move totalsales to wa-sales_y2.

    move tp_totalprice to wa-sales_y2.

    move ta_yr-year to wa-year2.

    ind2 = '1'.

    when '3'.

    move totalsales to wa-sales_y3.

    move tp_totalprice to wa-sales_y3.

    move ta_yr-year to wa-year3.

    ind3 = '1'.

    endcase.

    tp_tabix = sy-tabix.

    if sy-subrc = 0.

    • modify table ta_s076 from wa.

    modify ta_s076 from wa index tp_tabix.

    else.

    append wa to ta_s076.

    endif.

    endloop. "endloop for ta_yr

    endloop. "endloop for ta_mat

    itb_sales[] = ta_s076[].

    else.

    exit.

    endif.

    endform. "get_sales

    &----


    *& Form get_months

    &----


    • text

    ----


    form get_months.

    move pa_m_frm to t_mth1.

    perform get_next_few_months

    using t_mth1 '1'

    changing t_mth2.

    perform get_next_few_months

    using t_mth2 '1'

    changing t_mth3.

    perform get_next_few_months

    using t_mth3 '1'

    changing t_mth4.

    perform get_next_few_months

    using t_mth4 '1'

    changing t_mth5.

    perform get_next_few_months

    using t_mth5 '1'

    changing t_mth6.

    perform get_next_few_months

    using t_mth6 '1'

    changing t_mth7.

    perform get_next_few_months

    using t_mth7 '1'

    changing t_mth8.

    perform get_next_few_months

    using t_mth8 '1'

    changing t_mth9.

    perform get_next_few_months

    using t_mth9 '1'

    changing t_mth10.

    perform get_next_few_months

    using t_mth10 '1'

    changing t_mth11.

    perform get_next_few_months

    using t_mth11 '1'

    changing t_mth12.

    perform get_next_few_months

    using t_mth12 '1'

    changing t_mth13.

    perform get_next_few_months

    using t_mth13 '1'

    changing t_mth14.

    perform get_next_few_months

    using t_mth14 '1'

    changing t_mth15.

    perform get_next_few_months

    using t_mth15 '1'

    changing t_mth16.

    perform get_next_few_months

    using t_mth16 '1'

    changing t_mth17.

    perform get_next_few_months

    using t_mth17 '1'

    changing t_mth18.

    perform get_next_few_months

    using t_mth18 '1'

    changing t_mth19.

    perform get_next_few_months

    using t_mth19 '1'

    changing t_mth20.

    perform get_next_few_months

    using t_mth20 '1'

    changing t_mth21.

    perform get_next_few_months

    using t_mth21 '1'

    changing t_mth22.

    perform get_next_few_months

    using t_mth22 '1'

    changing t_mth23.

    perform get_next_few_months

    using t_mth23 '1'

    changing t_mth24.

    perform get_next_few_months

    using t_mth24 '1'

    changing t_mth25.

    perform get_next_few_months

    using t_mth25 '1'

    changing t_mth26.

    perform get_next_few_months

    using t_mth26 '1'

    changing t_mth27.

    perform get_next_few_months

    using t_mth27 '1'

    changing t_mth28.

    perform get_next_few_months

    using t_mth28 '1'

    changing t_mth29.

    perform get_next_few_months

    using t_mth29 '1'

    changing t_mth30.

    perform get_next_few_months

    using t_mth30 '1'

    changing t_mth31.

    perform get_next_few_months

    using t_mth31 '1'

    changing t_mth32.

    perform get_next_few_months

    using t_mth32 '1'

    changing t_mth33.

    perform get_next_few_months

    using t_mth33 '1'

    changing t_mth34.

    perform get_next_few_months

    using t_mth34 '1'

    changing t_mth35.

    perform get_next_few_months

    using t_mth35 '1'

    changing t_mth36.

    endform. "get_months

    &----


    *& Form get_years

    &----


    • text

    ----


    form get_years.

    data : tp_yr_frm(4) type n.

    data : tp_yr_to(4) type n.

    data : yr_diff(4) type n.

    move pa_y_frm to tp_yr_frm.

    move pa_y_to to tp_yr_to.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    yr_diff = tp_yr_to - tp_yr_frm.

    *number of years = 3

    if yr_diff = 2.

    do 2 times.

    tp_yr_frm = tp_yr_frm + 1.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    enddo.

    *number of years = 2

    elseif yr_diff = 1.

    tp_yr_frm = tp_yr_frm + 1.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    else.

    exit.

    endif.

    endform. "get_years

    &----


    *& Form get_next_few_months

    &----


    • text

    ----


    • -->LV_CURR_MONTH text

    • -->LV_MONTHS text

    • -->LV_TARGET_MTH text

    ----


    form get_next_few_months using lv_curr_month lv_months

    changing lv_target_mth.

    data : tp_month_curr like sy-datum,

    tp_month_plus like sy-datum.

    concatenate lv_curr_month '01' into tp_month_curr.

    call function 'SG_PS_ADD_MONTH_TO_DATE'

    EXPORTING

    months = lv_months

    olddate = tp_month_curr

    IMPORTING

    newdate = tp_month_plus.

    move tp_month_plus(6) to lv_target_mth.

    endform. " get_months

    &----


    *& Form months_calculate

    &----


    • text

    ----


    • -->P_DATE1 text

    • -->P_DATE2 text

    • <--P_EMONTHS text

    ----


    form months_calculate using p_date1

    p_date2

    changing p_emonths.

    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

    exporting

    i_date_from = p_date1

    • I_KEY_DAY_FROM =

    i_date_to = p_date2

    • I_KEY_DAY_TO =

    • I_FLG_SEPARATE = ' '

    importing

    • E_DAYS =

    e_months = p_emonths.

    • E_YEARS =

    endform. " months_calculate

    &----


    *& Form retrieve_bom

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form retrieve_bom .

    • retrieve BOM components

    sort ta_header by matnr.

    loop at ta_header where stlan = '1' and stlst = '01'.

    tp_bmeng = '1'.

    perform get_bom tables ta_stpo using

    ta_header-matnr pa_werks ta_header-stlan ta_header-stlal tp_bmeng.

    • requirement quantity calculation for active bom

    perform calculation1.

    • retrieve BOM components for pgm

    sort itab_bom2 by idnrk ascending.

    delete adjacent duplicates from itab_bom2 comparing matnr idnrk.

    • loop at itab_bom2. " commented by weihong

    tp_stlan = '1'.

    tp_stlal = '02'.

    perform get_pgm tables ta_stpo12 using

    itab_bom2-matnr pa_werks tp_stlan tp_stlal.

    • endloop. " endloop for itab_bom2.(commented by weihong)

    • requirement quantity calculation for inactive bom

    perform calculation2.

    refresh : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    clear : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    endloop. " endloop for ta_header.

    **itab_msale itab_ysale

    *break-point.

    perform display_alv.

    endform. "retrieve bom

    &----


    *& Form get_bom

    &----


    • text

    ----


    • -->LV_MATNR text

    • -->LV_WERKS text

    • -->LV_STLAN text

    • -->LV_STLAL text

    ----


    form get_bom tables lt_stpo structure stpox

    using lv_matnr like mast-matnr

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal

    lv_emeng like stko-bmeng .

    data: ta_topmat type cstmat,

    tp_dstst like csdata-xfeld,

    ta_matcat type cscmat occurs 0,

    tp_index like sy-tabix,

    tp_stufe like stpox-stufe,

    tp_diff like stpox-stufe,

    tp_indx like sy-tabix,

    tp_date like sy-datum,

    lv_stufe like stpox-stufe,

    lv_wegxx like stpox-wegxx,

    lv_stprs like stpox-stprs,

    lv_waers like stpox-waers,

    • lv_cuky_new like cdpos-cuky_new,

    • lv_value_new like cdpos-value_new,

    lv_index like sy-tabix,

    lv_datum like sy-datum,"added by pradeep on 02-07-07

    nxt_index like sy-tabix.

    • added by weihong.

    data: tp_mtart like mara-mtart,

    tp_matkl like mara-matkl,

    tp_stprs like stpox-stprs,

    tp_bomlv1 like mast-matnr,

    tp_bomlv2 like mast-matnr,

    tp_bomlv3 like mast-matnr,

    tp_bomlv4 like mast-matnr,

    tp_indln type i.

    write : lv_matnr to itab_bom1-matnr.

    write : lv_matnr to itab_bom2-matnr.

    write : lv_matnr to itab_path-matnr.

    call function 'CS_BOM_EXPL_MAT_V2'

    exporting

    capid = 'PP01'

    datuv = sy-datum

    emeng = lv_emeng

    • ftrel = lv_level

    mktls = 'X'

    mehrs = 'X'

    rndkz = '2'

    mtnrv = lv_matnr

    stlal = lv_stlal

    stlan = lv_stlan

    stpst = '0'

    svwvo = 'X'

    werks = lv_werks

    vrsvo = 'X'

    ehndl = '2'

    importing

    topmat = ta_topmat

    dstst = tp_dstst

    tables

    stb = lt_stpo

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

    loop at lt_stpo.

    move lt_stpo-stufe to itab_path-stufe.

    move lt_stpo-wegxx to itab_path-wegxx.

    move lt_stpo-idnrk to itab_path-idnrk.

    append itab_path.

    endloop.

    *sort itab_path by stufe wegxx.

    loop at lt_stpo into wa_stpo.

    tp_tabix = sy-tabix.

    • check if level 1

    if wa_stpo-stufe = '1'.

    itab_bom1-bom = lv_matnr.

    • check if level 2

    elseif wa_stpo-stufe = '2'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '1'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv1 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '2'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv1..

    endif.

    • check if level 3

    elseif wa_stpo-stufe = '3'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '2'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv2 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '3'

    • wegxx = '1'.

    *

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv2.

    endif.

    • check if level 4

    elseif wa_stpo-stufe = '4'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '3'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv3 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '4'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv3.

    endif.

    elseif wa_stpo-stufe = '5'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '4'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv4 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '5'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv4.

    endif.

    else.

    endif.

    select single maktx into itab_bom1-c_maktx from makt

    where matnr = wa_stpo-idnrk.

    • if wa_stpo-mtart <> 'ZRUH'.

    move-corresponding wa_stpo to itab_bom1.

    append itab_bom1.

    • else.

    if wa_stpo-mtart eq 'ZRUH'.

    move-corresponding wa_stpo to itab_bom2.

    append itab_bom2.

    endif.

    *clear: tp_bomlv.

    endloop.

    refresh: lt_stpo.

    clear:lt_stpo.

    temp_bom1[] = itab_bom1[].

    describe table itab_bom1 lines tp_indln.

    loop at itab_bom1 where matnr = lv_matnr.

    if itab_bom1-mtart = 'ZHLB' and itab_bom1-matkl <> 'WP0100'

    and itab_bom1-matkl <> 'WP0110'

    and itab_bom1-matkl <> 'WP0120'.

    • tp_indx = sy-tabix.

    • lv_stufe = itab_bom1-stufe.

    • lv_wegxx = itab_bom1-wegxx + 1.

    • nxt_index = tp_indx + 1.

    *

    *

    • read table temp_bom1 index nxt_index.

    • if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    *

    • read table temp_bom1 with key stufe = lv_stufe

    • wegxx = lv_wegxx.

    • lv_index = sy-tabix - 1.

    • if lv_index > nxt_index.

    • append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    • endif.

    • clear: tp_indx, nxt_index, lv_index.

    *

    • endif.

    tp_indx = sy-tabix.

    lv_stufe = itab_bom1-stufe.

    lv_wegxx = itab_bom1-wegxx + 1.

    nxt_index = tp_indx + 1.

    read table temp_bom1 index nxt_index.

    if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    read table temp_bom1 with key stufe = lv_stufe

    wegxx = lv_wegxx.

    lv_index = sy-tabix - 1.

    if lv_index > nxt_index.

    append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    elseif lv_index < 0.

    append lines of itab_bom1 from nxt_index to tp_indln to itb_bm1.

    endif.

    clear: tp_indx, nxt_index, lv_index.

    endif.

    endif.

    endloop.

    • clear table

    • loop at itb_bm1 where matnr = ta_header-matnr.

    loop at itb_bm1 where matnr = lv_matnr.

    • loop at itab_bom1 where matnr = itb_bm1-matnr.

    delete itab_bom1 where stufe = itb_bm1-stufe and wegxx = itb_bm1-wegxx.

    • read table itab_bom1 with key stufe = itb_bm1-stufe

    • wegxx = itb_bm1-wegxx

    • matnr = itb_bm1-matnr

    • bom = itb_bm1-bom

    • idnrk = itb_bm1-idnrk.

    • if sy-subrc eq 0.

    • delete itab_bom1 index lv_index.

    • endif.

    • endloop.

    endloop.

    clear: itb_bm1.

    refresh: itb_bm1.

    loop at itab_bom1.

    tp_tabix = sy-tabix.

    if itab_bom1-mtart eq 'ZRUH'.

    delete itab_bom1 index tp_tabix.

    endif.

    endloop.

    *if itab_bom1-stprs = '200702'.

    • write: itab_bom-cuky_new.

    • itab_bom1-stprs = 0.

    • else.

    • read table temp_bom1 with key objectid = itab_bom1-component

    • udate = itab_bom1-stprs.

    *endif.

    endform. "get_bom

    &----


    *& Form calculation1

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form calculation1.

    data : tp_tabix like sy-tabix.

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    clear wa.

    • loop at ta_s076 into wa where matnr = itab_bom11.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-mth1 = wa-mth1 * wa_bom1-mngko.

    wa-mth2 = wa-mth2 * wa_bom1-mngko.

    wa-mth3 = wa-mth3 * wa_bom1-mngko.

    wa-mth4 = wa-mth4 * wa_bom1-mngko.

    wa-mth5 = wa-mth5 * wa_bom1-mngko.

    wa-mth6 = wa-mth6 * wa_bom1-mngko.

    wa-mth7 = wa-mth7 * wa_bom1-mngko.

    wa-mth8 = wa-mth8 * wa_bom1-mngko.

    wa-mth9 = wa-mth9 * wa_bom1-mngko.

    wa-mth10 = wa-mth10 * wa_bom1-mngko.

    wa-mth11 = wa-mth11 * wa_bom1-mngko.

    wa-mth12 = wa-mth12 * wa_bom1-mngko.

    wa-mth13 = wa-mth13 * wa_bom1-mngko.

    wa-mth14 = wa-mth14 * wa_bom1-mngko.

    wa-mth15 = wa-mth15 * wa_bom1-mngko.

    wa-mth16 = wa-mth16 * wa_bom1-mngko.

    wa-mth17 = wa-mth17 * wa_bom1-mngko.

    wa-mth18 = wa-mth18 * wa_bom1-mngko.

    wa-mth19 = wa-mth19 * wa_bom1-mngko.

    wa-mth20 = wa-mth20 * wa_bom1-mngko.

    wa-mth21 = wa-mth21 * wa_bom1-mngko.

    wa-mth22 = wa-mth22 * wa_bom1-mngko.

    wa-mth23 = wa-mth23 * wa_bom1-mngko.

    wa-mth24 = wa-mth24 * wa_bom1-mngko.

    wa-mth25 = wa-mth25 * wa_bom1-mngko.

    wa-mth26 = wa-mth26 * wa_bom1-mngko.

    wa-mth27 = wa-mth27 * wa_bom1-mngko.

    wa-mth28 = wa-mth28 * wa_bom1-mngko.

    wa-mth29 = wa-mth29 * wa_bom1-mngko.

    wa-mth31 = wa-mth31 * wa_bom1-mngko.

    wa-mth32 = wa-mth32 * wa_bom1-mngko.

    wa-mth33 = wa-mth33 * wa_bom1-mngko.

    wa-mth34 = wa-mth34 * wa_bom1-mngko.

    wa-mth35 = wa-mth35 * wa_bom1-mngko.

    wa-mth36 = wa-mth36 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    wa-bom = wa_bom1-bom.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop. " endloop for itab_bom

    • check if the Display yearly report is being selected ****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear wa.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom1-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom1-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-bom = wa_bom1-bom.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop. " endloop for itab_bom

    else.

    endif.

    endform. " calculation1

    &----


    *& Form get_pgm

    &----


    • text

    ----


    • -->P_TA_STPO2 text

    • -->P_ITAB_BOM_MATNR text

    • -->P_PA_WERKS text

    • -->P_TP_STLAN text

    • -->P_TP_STLAL text

    ----


    form get_pgm tables lt_stpo12 structure bom_item_api01

    using lv_matnr like mast-matnr

    • lv_idnrk like stpox-idnrk

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal.

    data: lt_stko12 type stko_api02 occurs 0.

    data: tp_quantity like stpox-menge.

    write : lv_matnr to itab_pgm-matnr.

    • if lt_stpo12 is not initial.

    • refresh: lt_stpo12.

    • clear:lt_stpo12.

    • endif.

    call function 'CSEP_MAT_BOM_READ'

    EXPORTING

    material = lv_matnr

    plant = lv_werks

    bom_usage = lv_stlan

    alternative = lv_stlal

    TABLES

    t_stpo = lt_stpo12

    t_stko = lt_stko12

    EXCEPTIONS

    error = 1.

    • if sy-subrc ne 0.

    • message e066(zwaa001).

    • endif.

    if sy-subrc = 0.

    loop at lt_stpo12 into wa_stpo12.

    replace all occurrences of ',' in wa_stpo12-comp_qty with ''.

    move wa_stpo12-comp_qty to tp_quantity.

    select single maktx into itab_pgm-c_maktx from makt

    where matnr = wa_stpo12-component and

    spras = 'E'.

    move wa_stpo12-comp_qty to itab_pgm-mngko.

    move-corresponding wa_stpo12 to itab_pgm.

    • Added by Soh.

    select single matkl into itab_pgm-matkl

    from mara

    where matnr = itab_pgm-component.

    • Added by pradeep

    select single stprs into itab_pgm-stprs

    from mbew

    where matnr = itab_pgm-reQuantity.

    append itab_pgm.

    endloop.

    refresh: lt_stpo12.

    clear:lt_stpo12.

    endif.

    endform. " get_pgm

    &----


    *& Form calculation2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form calculation2.

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-mth1 = wa-mth1 * wa_bom2-mngko.

    wa-mth2 = wa-mth2 * wa_bom2-mngko.

    wa-mth3 = wa-mth3 * wa_bom2-mngko.

    wa-mth4 = wa-mth4 * wa_bom2-mngko.

    wa-mth5 = wa-mth5 * wa_bom2-mngko.

    wa-mth6 = wa-mth6 * wa_bom2-mngko.

    wa-mth7 = wa-mth7 * wa_bom2-mngko.

    wa-mth8 = wa-mth8 * wa_bom2-mngko.

    wa-mth9 = wa-mth9 * wa_bom2-mngko.

    wa-mth10 = wa-mth10 * wa_bom2-mngko.

    wa-mth11 = wa-mth11 * wa_bom2-mngko.

    wa-mth12 = wa-mth12 * wa_bom2-mngko.

    wa-mth13 = wa-mth13 * wa_bom2-mngko.

    wa-mth14 = wa-mth14 * wa_bom2-mngko.

    wa-mth15 = wa-mth15 * wa_bom2-mngko.

    wa-mth16 = wa-mth16 * wa_bom2-mngko.

    wa-mth17 = wa-mth17 * wa_bom2-mngko.

    wa-mth18 = wa-mth18 * wa_bom2-mngko.

    wa-mth19 = wa-mth19 * wa_bom2-mngko.

    wa-mth20 = wa-mth20 * wa_bom2-mngko.

    wa-mth21 = wa-mth21 * wa_bom2-mngko.

    wa-mth22 = wa-mth22 * wa_bom2-mngko.

    wa-mth23 = wa-mth23 * wa_bom2-mngko.

    wa-mth24 = wa-mth24 * wa_bom2-mngko.

    wa-mth25 = wa-mth25 * wa_bom2-mngko.

    wa-mth26 = wa-mth26 * wa_bom2-mngko.

    wa-mth27 = wa-mth27 * wa_bom2-mngko.

    wa-mth28 = wa-mth28 * wa_bom2-mngko.

    wa-mth29 = wa-mth29 * wa_bom2-mngko.

    wa-mth31 = wa-mth31 * wa_bom2-mngko.

    wa-mth32 = wa-mth32 * wa_bom2-mngko.

    wa-mth33 = wa-mth33 * wa_bom2-mngko.

    wa-mth34 = wa-mth34 * wa_bom2-mngko.

    wa-mth35 = wa-mth35 * wa_bom2-mngko.

    wa-mth36 = wa-mth36 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop.

    • check if the Display yearly report is being selected ****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom2-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom2-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop.

    else.

    endif.

    endform. " calculation_2

    Copa

     
    

    &----


    *& Report ZRPP026

    *&

    &----


    *& Developer : Pradeep

    *& Date : 18/07/2007

    *& Description : Creation of Copa Details

    &----


    report zrpp026 line-count 80 line-size 160 no standard page heading.

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

    • Class

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

    class cl_gui_column_tree definition load.

    class cl_gui_cfw definition load.

    data tree1 type ref to cl_gui_alv_tree.

    data mr_toolbar type ref to cl_gui_toolbar.

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

    • Include

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

    include <icon>.

    include bcalv_toolbar_event_receiver.

    include bcalv_tree_event_receiver.

    include zipp007.

    data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.

    data: ok_code like sy-ucomm.

    data:pa_m_frm(6) type c,

    pa_m_to(6) type c,

    pa_y_frm(4) type c,

    pa_y_to(4) type c.

    selection-screen begin of block selscrb with frame title text-s01.

    parameters: pa_erkrs like t237t-erkrs obligatory.

    parameters:pa_bukrs like ce2asia-bukrs.

    select-options: so_matnr for mara-matnr.

    select-options: so_matkl for mara-matkl.

    parameter: pa_stprs like mbew-stprs.

    *parameter: pa_matnr like mara-matnr.

    parameter: pa_werks like t001l-werks obligatory default 'MY11',

    pa_versi like ce2asia-versi obligatory default 'A00'.

    parameter:ra_mth radiobutton group rapt default 'X',

    ra_yea radiobutton group rapt.

    selection-screen end of block selscrb.

    initialization.

    clear: ta_versi, ta_type.

    refresh: ta_versi, ta_type.

    at selection-screen on value-request for pa_versi.

    call function 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

    retfield = 'VERSI'

    dynprofield = 'PA_VERSI'

    dynpprog = sy-cprog

    dynpnr = sy-dynnr

    value_org = 'S'

    TABLES

    value_tab = ta_versi.

    Start-of-selection.

    if ra_mth eq 'X'.

    submit zrpp024 via selection-screen and return with pa_mth = ra_mth.

    elseif ra_yea eq 'X'.

    submit zrpp025 via selection-screen and return with pa_yea = ra_yea.

    endif.

    Select * into corresponding fields of table ta_versi

    from p44v

    where gstru = 's076'.

    sort ta_versi by versi.

    move 'MONTH' to ta_type-out_type.

    append ta_type.

    move 'YEAR' to ta_type-out_type.

    append ta_type.

    End-of-selection.

    data: r_versi like range of ce2asia-versi with header line.

    perform get_copa.

    perform retrieve_bom.

    &----


    *& Form get_copa

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_copa .

    data: lv_erkrs like bapi1168-op_concern,

    lv_curtyp like bapi1168-curr_type,

    lv_maxrec like bapi1168-num_of_records,

    lv_sel like bapi_copa_selection occurs 0 with header line,

    lv_field like bapi_copa_field occurs 0 with header line,

    lv_result like bapi_copa_data occurs 0 with header line,

    lv_ret like bapiret2 occurs 0 with header line.

    data: vtext type string,

    lv_perbl like ce2asia-perbl,

    tp_tabix like sy-tabix,

    ta_mast like mast.

    data: tp_flag type c, " flag to indicate period is exceeded 12

    tp_perbl like ce2asia-perbl,

    tp_versi like ce2asia-versi,

    lv_perio(7) type n.

    • Initialize parameter.

    lv_erkrs = pa_erkrs.

    lv_curtyp = '10'.

    lv_maxrec = '99999999'.

    lv_sel-fieldname = 'BUKRS'.

    lv_sel-sign = 'I'.

    lv_sel-option = 'EQ'.

    lv_sel-low = pa_bukrs.

    append lv_sel.

    lv_sel-fieldname = 'VERSI'.

    lv_sel-sign = 'I'.

    lv_sel-option = 'EQ'.

    lv_sel-low = ta_versi.

    lv_sel-high = ''.

    append lv_sel.

    lv_sel-fieldname = 'VERSI'.

    lv_sel-sign = 'I'.

    lv_sel-option = 'EQ'.

    lv_sel-low = ta_versi.

    lv_sel-high = ''.

    append lv_sel.

    lv_field-fieldname = 'ARTNR'.

    append lv_field.

    lv_field-fieldname = 'paledger'.

    append lv_field.

    lv_field-fieldname = 'PERBL'.

    append lv_field.

    lv_field-fieldname = 'WERKS'.

    append lv_field.

    lv_field-fieldname = 'ABSMG001'.

    append lv_field.

    lv_field-fieldname = 'PERIO'.

    append lv_field.

    lv_field-fieldname = 'VERSI'.

    append lv_field.

    • end

    • call bapi to get copa

    call function 'BAPI_COPAQUERY_GETCOST_PLANDAT'

    EXPORTING

    operatingconcern = lv_erkrs

    maxrecords = lv_maxrec

    TABLES

    selection = lv_sel

    selectedfields = lv_field

    resultdata = lv_result

    return = lv_ret.

    read table lv_ret with key type = 'E'.

    if sy-subrc = 0.

    message id sy-msgid type sy-msgty number sy-msgno

    into vtext

    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    message vtext type 'E'.

    endif.

    • update lv_result to ta_copa.

    loop at lv_result.

    move lv_result-record_id to wa_copa-rec_id.

    case lv_result-fieldname.

    when 'ARTNR'.

    move lv_result-value to wa_copa-artnr.

    when 'PERbl'.

    move lv_result-value to wa_copa-perbl.

    when 'WERKS'.

    move lv_result-value to wa_copa-werks.

    when 'ABSMG001'.

    move lv_result-value to wa_copa-absmg001.

    when 'VERSI'.

    move lv_result-value to wa_copa-versi.

    • end

    endcase.

    read table ta_copa with key rec_id = wa_copa-rec_id.

    if sy-subrc = 0.

    move-corresponding wa_copa to ta_copa.

    modify ta_copa index sy-tabix.

    else.

    append wa_copa to ta_copa.

    endif.

    endloop.

    • if period is 11

    loop at ta_copa where versi = 'G01'.

    delete ta_copa index sy-tabix.

    endloop.

    • end

    loop at ta_copa.

    tp_tabix = sy-tabix.

    select single * from mast

    into ta_mast

    where matnr = ta_copa-artnr

    and werks = ta_copa-werks

    and stlan = '1'.

    if sy-subrc eq 0.

    select single stlal from stko

    into ta_copa-stlal

    where stlnr = ta_mast-stlnr

    and stlty = 'M'

    and stlst = '1'.

    if sy-subrc eq 0.

    modify ta_copa index tp_tabix transporting stlal.

    else.

    delete ta_copa index tp_tabix.

    endif.

    else.

    delete ta_copa index tp_tabix.

    endif.

    endloop.

    clear: lv_sel, lv_field, lv_result, lv_ret.

    refresh: lv_sel, lv_field, lv_result, lv_ret.

    ENDFORM. " get_copa

    &----


    *& Form retrieve_bom

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM retrieve_bom .

    • retrieve BOM components

    sort ta_header by matnr.

    loop at ta_header where stlan = '1' and stlst = '01'.

    tp_bmeng = '1'.

    perform get_bom tables ta_stpo using

    ta_header-matnr pa_werks ta_header-stlan ta_header-stlal tp_bmeng.

    • requirement quantity calculation for active bom

    perform calculation1.

    • retrieve BOM components for pgm

    sort itab_bom2 by idnrk ascending.

    delete adjacent duplicates from itab_bom2 comparing matnr idnrk.

    • loop at itab_bom2. " commented by weihong

    tp_stlan = '1'.

    tp_stlal = '02'.

    perform get_pgm tables ta_stpo12 using

    itab_bom2-matnr pa_werks tp_stlan tp_stlal.

    • endloop. " endloop for itab_bom2.(commented by weihong)

    • requirement quantity calculation for inactive bom

    perform calculation2.

    refresh : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    clear : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    endloop. " endloop for ta_header.

    **itab_msale itab_ysale

    *break-point.

    perform display_alv.

    ENDFORM. " retrieve_bom

    &----


    *& Form calculation1

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM calculation1 .

    data : tp_tabix like sy-tabix.

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    clear wa.

    • loop at ta_s076 into wa where matnr = itab_bom11.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-mth1 = wa-mth1 * wa_bom1-mngko.

    wa-mth2 = wa-mth2 * wa_bom1-mngko.

    wa-mth3 = wa-mth3 * wa_bom1-mngko.

    wa-mth4 = wa-mth4 * wa_bom1-mngko.

    wa-mth5 = wa-mth5 * wa_bom1-mngko.

    wa-mth6 = wa-mth6 * wa_bom1-mngko.

    wa-mth7 = wa-mth7 * wa_bom1-mngko.

    wa-mth8 = wa-mth8 * wa_bom1-mngko.

    wa-mth9 = wa-mth9 * wa_bom1-mngko.

    wa-mth10 = wa-mth10 * wa_bom1-mngko.

    wa-mth11 = wa-mth11 * wa_bom1-mngko.

    wa-mth12 = wa-mth12 * wa_bom1-mngko.

    wa-mth13 = wa-mth13 * wa_bom1-mngko.

    wa-mth14 = wa-mth14 * wa_bom1-mngko.

    wa-mth15 = wa-mth15 * wa_bom1-mngko.

    wa-mth16 = wa-mth16 * wa_bom1-mngko.

    wa-mth17 = wa-mth17 * wa_bom1-mngko.

    wa-mth18 = wa-mth18 * wa_bom1-mngko.

    wa-mth19 = wa-mth19 * wa_bom1-mngko.

    wa-mth20 = wa-mth20 * wa_bom1-mngko.

    wa-mth21 = wa-mth21 * wa_bom1-mngko.

    wa-mth22 = wa-mth22 * wa_bom1-mngko.

    wa-mth23 = wa-mth23 * wa_bom1-mngko.

    wa-mth24 = wa-mth24 * wa_bom1-mngko.

    wa-mth25 = wa-mth25 * wa_bom1-mngko.

    wa-mth26 = wa-mth26 * wa_bom1-mngko.

    wa-mth27 = wa-mth27 * wa_bom1-mngko.

    wa-mth28 = wa-mth28 * wa_bom1-mngko.

    wa-mth29 = wa-mth29 * wa_bom1-mngko.

    wa-mth31 = wa-mth31 * wa_bom1-mngko.

    wa-mth32 = wa-mth32 * wa_bom1-mngko.

    wa-mth33 = wa-mth33 * wa_bom1-mngko.

    wa-mth34 = wa-mth34 * wa_bom1-mngko.

    wa-mth35 = wa-mth35 * wa_bom1-mngko.

    wa-mth36 = wa-mth36 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    wa-bom = wa_bom1-bom.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop. " endloop for itab_bom

    • check if the Display yearly report is being selected ****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear wa.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom1-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom1-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-bom = wa_bom1-bom.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop. " endloop for itab_bom

    else.

    endif.

    ENDFORM. " calculation1

    &----


    *& Form calculation2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM calculation2 .

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-mth1 = wa-mth1 * wa_bom2-mngko.

    wa-mth2 = wa-mth2 * wa_bom2-mngko.

    wa-mth3 = wa-mth3 * wa_bom2-mngko.

    wa-mth4 = wa-mth4 * wa_bom2-mngko.

    wa-mth5 = wa-mth5 * wa_bom2-mngko.

    wa-mth6 = wa-mth6 * wa_bom2-mngko.

    wa-mth7 = wa-mth7 * wa_bom2-mngko.

    wa-mth8 = wa-mth8 * wa_bom2-mngko.

    wa-mth9 = wa-mth9 * wa_bom2-mngko.

    wa-mth10 = wa-mth10 * wa_bom2-mngko.

    wa-mth11 = wa-mth11 * wa_bom2-mngko.

    wa-mth12 = wa-mth12 * wa_bom2-mngko.

    wa-mth13 = wa-mth13 * wa_bom2-mngko.

    wa-mth14 = wa-mth14 * wa_bom2-mngko.

    wa-mth15 = wa-mth15 * wa_bom2-mngko.

    wa-mth16 = wa-mth16 * wa_bom2-mngko.

    wa-mth17 = wa-mth17 * wa_bom2-mngko.

    wa-mth18 = wa-mth18 * wa_bom2-mngko.

    wa-mth19 = wa-mth19 * wa_bom2-mngko.

    wa-mth20 = wa-mth20 * wa_bom2-mngko.

    wa-mth21 = wa-mth21 * wa_bom2-mngko.

    wa-mth22 = wa-mth22 * wa_bom2-mngko.

    wa-mth23 = wa-mth23 * wa_bom2-mngko.

    wa-mth24 = wa-mth24 * wa_bom2-mngko.

    wa-mth25 = wa-mth25 * wa_bom2-mngko.

    wa-mth26 = wa-mth26 * wa_bom2-mngko.

    wa-mth27 = wa-mth27 * wa_bom2-mngko.

    wa-mth28 = wa-mth28 * wa_bom2-mngko.

    wa-mth29 = wa-mth29 * wa_bom2-mngko.

    wa-mth31 = wa-mth31 * wa_bom2-mngko.

    wa-mth32 = wa-mth32 * wa_bom2-mngko.

    wa-mth33 = wa-mth33 * wa_bom2-mngko.

    wa-mth34 = wa-mth34 * wa_bom2-mngko.

    wa-mth35 = wa-mth35 * wa_bom2-mngko.

    wa-mth36 = wa-mth36 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop.

    • check if the Display yearly report is being selected ****

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom2-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom2-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop.

    else.

    endif.

    ENDFORM. " calculation2

    &----


    *& Form display_alv

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM display_alv .

    • ALV ***

    g_repid = sy-repid.

    perform layout_init using gs_layout.

    perform eventtab_build using gt_events[].

    gs_variant-report = g_repid.

    g_save = 'A'.

    • perform comment_build using gt_list_top_of_page[].

    • Display monthly report

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    perform fieldcat_init_mth using gt_fieldcat[].

    perform printer_setting using print_set.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_background_id = 'ALV_BACKGROUND'

    i_buffer_active = 'X'

    i_callback_program = g_repid

    i_structure_name = 'ITAB_MSALE'

    is_layout = gs_layout

    it_fieldcat = gt_fieldcat[]

    i_save = g_save

    is_variant = gs_variant

    it_events = gt_events[]

    it_sort = gt_it_sort[]

    is_print = print_set

    • I_SCREEN_START_COLUMN = 0 "Use coordinates for

    • I_SCREEN_START_LINE = 0 "display as dialog box

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    importing

    e_exit_caused_by_caller = g_exit_caused_by_caller

    es_exit_caused_by_user = gs_exit_caused_by_user

    tables

    t_outtab = itab_msale

    exceptions

    program_error = 1

    others = 2.

    if sy-subrc = 0.

    if g_exit_caused_by_caller = 'X'.

    *" Forced Exit by calling program

    *" <do_something>.

    else.

    *" User left list via F3, F12 or F15

    if gs_exit_caused_by_user-back = 'X'. "F3

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-exit = 'X'. "F15

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-cancel = 'X'. "F12

    *" <do_something>.

    else.

    *" should not occur!

    *" <do_Abnormal_End>.

    endif.

    endif.

    endif.

    endif.

    else.

    "Fatal error callin ALVAXXX(XY) WITH ...

    endif.

    • Display yearly report

    elseif ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    perform fieldcat_init_yr using gt_fieldcat[].

    perform printer_setting using print_set.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_background_id = 'ALV_BACKGROUND'

    i_buffer_active = 'X'

    i_callback_program = g_repid

    i_structure_name = 'ITAB_YSALE'

    is_layout = gs_layout

    it_fieldcat = gt_fieldcat[]

    i_save = g_save

    is_variant = gs_variant

    it_events = gt_events[]

    it_sort = gt_it_sort[]

    is_print = print_set

    • I_SCREEN_START_COLUMN = 0 "Use coordinates for

    • I_SCREEN_START_LINE = 0 "display as dialog box

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    importing

    e_exit_caused_by_caller = g_exit_caused_by_caller

    es_exit_caused_by_user = gs_exit_caused_by_user

    tables

    t_outtab = itab_ysale

    exceptions

    program_error = 1

    others = 2.

    if sy-subrc = 0.

    if g_exit_caused_by_caller = 'X'.

    *" Forced Exit by calling program

    *" <do_something>.

    else.

    *" User left list via F3, F12 or F15

    if gs_exit_caused_by_user-back = 'X'. "F3

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-exit = 'X'. "F15

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-cancel = 'X'. "F12

    *" <do_something>.

    else.

    *" should not occur!

    *" <do_Abnormal_End>.

    endif.

    endif.

    endif.

    endif.

    else.

    *"Fatal error callin ALV

    • MESSAGE AXXX(XY) WITH ...

    endif.

    else.

    endif.

    ENDFORM. " display_alv

    &----


    *& Form get_bom

    &----


    • text

    ----


    • -->P_TA_STPO text

    • -->P_TA_HEADER_MATNR text

    • -->P_PA_WERKS text

    • -->P_TA_HEADER_STLAN text

    • -->P_TA_HEADER_STLAL text

    • -->P_TP_BMENG text

    ----


    FORM get_bom TABLES lt_STPO STRUCTURE stpox

    USING lv_matnr like mast-matnr

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal

    lv_emeng like stko-bmeng .

    data: ta_topmat type cstmat,

    tp_dstst like csdata-xfeld,

    ta_matcat type cscmat occurs 0,

    tp_index like sy-tabix,

    tp_stufe like stpox-stufe,

    tp_diff like stpox-stufe,

    tp_indx like sy-tabix,

    tp_date like sy-datum,

    lv_stufe like stpox-stufe,

    lv_wegxx like stpox-wegxx,

    lv_stprs like stpox-stprs,

    lv_waers like stpox-waers,

    • lv_cuky_new like cdpos-cuky_new,

    • lv_value_new like cdpos-value_new,

    lv_index like sy-tabix,

    lv_datum like sy-datum,"added by pradeep on 02-07-07

    nxt_index like sy-tabix.

    • added by weihong.

    data: tp_mtart like mara-mtart,

    tp_matkl like mara-matkl,

    tp_stprs like stpox-stprs,

    tp_bomlv1 like mast-matnr,

    tp_bomlv2 like mast-matnr,

    tp_bomlv3 like mast-matnr,

    tp_bomlv4 like mast-matnr,

    tp_indln type i.

    write : lv_matnr to itab_bom1-matnr.

    write : lv_matnr to itab_bom2-matnr.

    write : lv_matnr to itab_path-matnr.

    call function 'CS_BOM_EXPL_MAT_V2'

    exporting

    capid = 'PP01'

    datuv = sy-datum

    emeng = lv_emeng

    • ftrel = lv_level

    mktls = 'X'

    mehrs = 'X'

    rndkz = '2'

    mtnrv = lv_matnr

    stlal = lv_stlal

    stlan = lv_stlan

    stpst = '0'

    svwvo = 'X'

    werks = lv_werks

    vrsvo = 'X'

    ehndl = '2'

    importing

    topmat = ta_topmat

    dstst = tp_dstst

    tables

    stb = lt_stpo

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

    loop at lt_stpo.

    move lt_stpo-stufe to itab_path-stufe.

    move lt_stpo-wegxx to itab_path-wegxx.

    move lt_stpo-idnrk to itab_path-idnrk.

    append itab_path.

    endloop.

    *sort itab_path by stufe wegxx.

    loop at lt_stpo into wa_stpo.

    tp_tabix = sy-tabix.

    • check if level 1

    if wa_stpo-stufe = '1'.

    itab_bom1-bom = lv_matnr.

    • check if level 2

    elseif wa_stpo-stufe = '2'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '1'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv1 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '2'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv1..

    endif.

    • check if level 3

    elseif wa_stpo-stufe = '3'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '2'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv2 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '3'

    • wegxx = '1'.

    *

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv2.

    endif.

    • check if level 4

    elseif wa_stpo-stufe = '4'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '3'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv3 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '4'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv3.

    endif.

    elseif wa_stpo-stufe = '5'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '4'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv4 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '5'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv4.

    endif.

    else.

    endif.

    select single maktx into itab_bom1-c_maktx from makt

    where matnr = wa_stpo-idnrk.

    • if wa_stpo-mtart <> 'ZRUH'.

    move-corresponding wa_stpo to itab_bom1.

    append itab_bom1.

    • else.

    if wa_stpo-mtart eq 'ZRUH'.

    move-corresponding wa_stpo to itab_bom2.

    append itab_bom2.

    endif.

    *clear: tp_bomlv.

    endloop.

    refresh: lt_stpo.

    clear:lt_stpo.

    temp_bom1[] = itab_bom1[].

    describe table itab_bom1 lines tp_indln.

    loop at itab_bom1 where matnr = lv_matnr.

    if itab_bom1-mtart = 'ZHLB' and itab_bom1-matkl <> 'WP0100'

    and itab_bom1-matkl <> 'WP0110'

    and itab_bom1-matkl <> 'WP0120'.

    • tp_indx = sy-tabix.

    • lv_stufe = itab_bom1-stufe.

    • lv_wegxx = itab_bom1-wegxx + 1.

    • nxt_index = tp_indx + 1.

    *

    *

    • read table temp_bom1 index nxt_index.

    • if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    *

    • read table temp_bom1 with key stufe = lv_stufe

    • wegxx = lv_wegxx.

    • lv_index = sy-tabix - 1.

    • if lv_index > nxt_index.

    • append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    • endif.

    • clear: tp_indx, nxt_index, lv_index.

    *

    • endif.

    tp_indx = sy-tabix.

    lv_stufe = itab_bom1-stufe.

    lv_wegxx = itab_bom1-wegxx + 1.

    nxt_index = tp_indx + 1.

    read table temp_bom1 index nxt_index.

    if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    read table temp_bom1 with key stufe = lv_stufe

    wegxx = lv_wegxx.

    lv_index = sy-tabix - 1.

    if lv_index > nxt_index.

    append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    elseif lv_index < 0.

    append lines of itab_bom1 from nxt_index to tp_indln to itb_bm1.

    endif.

    clear: tp_indx, nxt_index, lv_index.

    endif.

    endif.

    endloop.

    • clear table

    • loop at itb_bm1 where matnr = ta_header-matnr.

    loop at itb_bm1 where matnr = lv_matnr.

    • loop at itab_bom1 where matnr = itb_bm1-matnr.

    delete itab_bom1 where stufe = itb_bm1-stufe and wegxx = itb_bm1-wegxx.

    • read table itab_bom1 with key stufe = itb_bm1-stufe

    • wegxx = itb_bm1-wegxx

    • matnr = itb_bm1-matnr

    • bom = itb_bm1-bom

    • idnrk = itb_bm1-idnrk.

    • if sy-subrc eq 0.

    • delete itab_bom1 index lv_index.

    • endif.

    • endloop.

    endloop.

    clear: itb_bm1.

    refresh: itb_bm1.

    loop at itab_bom1.

    tp_tabix = sy-tabix.

    if itab_bom1-mtart eq 'ZRUH'.

    delete itab_bom1 index tp_tabix.

    endif.

    endloop.

    ENDFORM. " get_bom

    &----


    *& Form get_pgm

    &----


    • text

    ----


    • -->P_TA_STPO12 text

    • -->P_ITAB_BOM2_MATNR text

    • -->P_PA_WERKS text

    • -->P_TP_STLAN text

    • -->P_TP_STLAL text

    ----


    FORM get_pgm TABLES lt_stpo12 STRUCTURE bom_item_api01

    USING lv_matnr like mast-matnr

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal.

    data: lt_stko12 type stko_api02 occurs 0.

    data: tp_quantity like stpox-menge.

    write : lv_matnr to itab_pgm-matnr.

    • if lt_stpo12 is not initial.

    • refresh: lt_stpo12.

    • clear:lt_stpo12.

    • endif.

    call function 'CSEP_MAT_BOM_READ'

    EXPORTING

    material = lv_matnr

    plant = lv_werks

    bom_usage = lv_stlan

    alternative = lv_stlal

    TABLES

    t_stpo = lt_stpo12

    t_stko = lt_stko12

    EXCEPTIONS

    error = 1.

    • if sy-subrc ne 0.

    • message e066(zwaa001).

    • endif.

    if sy-subrc = 0.

    loop at lt_stpo12 into wa_stpo12.

    replace all occurrences of ',' in wa_stpo12-comp_qty with ''.

    move wa_stpo12-comp_qty to tp_quantity.

    select single maktx into itab_pgm-c_maktx from makt

    where matnr = wa_stpo12-component and

    spras = 'E'.

    move wa_stpo12-comp_qty to itab_pgm-mngko.

    move-corresponding wa_stpo12 to itab_pgm.

    • Added by Soh.

    select single matkl into itab_pgm-matkl

    from mara

    where matnr = itab_pgm-component.

    • Added by pradeep

    select single stprs into itab_pgm-stprs

    from mbew

    where matnr = itab_pgm-reQuantity.

    append itab_pgm.

    endloop.

    refresh: lt_stpo12.

    clear:lt_stpo12.

    endif.

    ENDFORM. " get_pgm

    Month.

    &----


    *& Report ZRPP024

    *&

    &----


    *& Developer : Pradeep

    *& Date : 16/07/2007

    *& Description : To get MOnthly report

    &----


    REPORT ZRPP024 .

    include zipp007.

    Data:ra_mth.

    data:so_matnr like mara-matnr,

    pa_werks like t001l-werks,

    pa_vrsio like s076-vrsio,

    iseq type i,

    seq type i,

    tp_pmnux like s076-pmnux,

    tp_maktx like makt-maktx.

    selection-screen begin of block BLK with Frame title text-001.

    selection-screen begin of line.

    selection-screen: comment 1(31) text-001.

    parameters:pa_m_frm(6) type c.

    selection-screen: comment 40(30) text-002.

    selection-screen end of line.

    selection-screen begin of line.

    selection-screen: comment 1(31) text-003.

    parameters:pa_m_to(6) type c.

    selection-screen: comment 40(30) text-004.

    selection-screen end of line.

    parameter pa_mth type c no-display.

    selection-screen end of block BLK.

    initialization.

    clear: ta_vrsio, ta_type.

    refresh: ta_vrsio, ta_type.

    at selection-screen output.

    if ra_mth = 'X'.

    loop at screen.

    if screen-name = 'PA_M_FRM'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C001007_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C002009_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = 'PA_M_TO'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C003012_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C004014_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    endloop.

    endif.

    Start-of-selection.

    ra_mth = pa_mth.

    select * into corresponding fields of table ta_vrsio

    from p44v

    where gstru = 'S076'.

    sort ta_vrsio by vrsio.

    delete adjacent duplicates from ta_vrsio.

    move 'MONTH' to ta_type-out_type.

    append ta_type.

    move 'YEAR' to ta_type-out_type.

    append ta_type.

    End-of-selection.

    perform get_header_data.

    perform get_top_page.

    perform display_alv.

    &----


    *& Form display_alv

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM display_alv .

    g_repid = sy-repid.

    perform layout_init using gs_layout.

    perform eventtab_build using gt_events[].

    gs_variant-report = g_repid.

    g_save = 'A'.

    • perform comment_build using gt_list_top_of_page[].

    • Display monthly report

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    perform fieldcat_init_mth using gt_fieldcat[].

    perform printer_setting using print_set.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_background_id = 'ALV_BACKGROUND'

    i_buffer_active = 'X'

    i_callback_program = g_repid

    i_structure_name = 'ITAB_MSALE'

    is_layout = gs_layout

    it_fieldcat = gt_fieldcat[]

    i_save = g_save

    is_variant = gs_variant

    it_events = gt_events[]

    it_sort = gt_it_sort[]

    is_print = print_set

    importing

    e_exit_caused_by_caller = g_exit_caused_by_caller

    es_exit_caused_by_user = gs_exit_caused_by_user

    tables

    t_outtab = itab_msale

    exceptions

    program_error = 1

    others = 2.

    if sy-subrc = 0.

    if g_exit_caused_by_caller = 'X'.

    *" Forced Exit by calling program

    *" <do_something>.

    else.

    *" User left list via F3, F12 or F15

    if gs_exit_caused_by_user-back = 'X'. "F3

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-exit = 'X'. "F15

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-cancel = 'X'. "F12

    *" <do_something>.

    else.

    *" should not occur!

    *" <do_Abnormal_End>.

    endif.

    endif.

    endif.

    endif.

    else.

    "Fatal error callin ALVAXXX(XY) WITH ...

    endif.

    endif.

    ENDFORM. " display_alv

    &----


    *& Form checking

    &----


    • text

    ----


    form checking.

    data : date1 like vtbbewe-dbervon,

    date2 like vtbbewe-dberbis.

    data : emonths like vtbbewe-atage.

    data : lv_m_frm(6) type n,

    lv_m_to(6) type n.

    • check if the Display monthly report is being selected *****

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-XMENG .

    • check for correct input format

    lv_m_frm = pa_m_frm.

    lv_m_to = pa_m_to.

    if lv_m_frm ge '200000' and lv_m_to ge '200000'.

    • calculate the months in between

    clear date1.

    clear date2.

    concatenate pa_m_frm '01' into date1.

    concatenate pa_m_to '01' into date2.

    • concatenate pa_m_to '31' into date2.

    perform months_calculate using date1 date2 changing emonths.

    • check if months <= 36.

    if emonths <= 36.

    else.

    perform get_sales.

    perform retrieve_bom.

    message i000(zwpp001).

    exit. " error message

    endif.

    else.

    message i002(zwpp001).

    endif.

    endif.

    endform. " checking

    &----


    *& Form get_header_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_header_data .

    select pmnux into ta_mat-matnr

    from s076

    where pmnux = so_matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio.

    append ta_mat.

    clear ta_mat.

    endselect.

    if sy-subrc = 0.

    sort ta_mat by matnr .

    delete adjacent duplicates from ta_mat.

    loop at ta_mat.

    select matnr stlnr stlan stlal

    appending corresponding fields of table ta_mat2

    from mast

    where matnr = ta_mat-matnr

    and werks = pa_werks.

    endloop.

    loop at ta_mat2 into wa_ta_mat.

    select stlst bmeng bmein into (tp_stlst,tp_bmeng,tp_bmein)

    from stko

    where stlnr = wa_ta_mat-stlnr

    and stlal = wa_ta_mat-stlal.

    wa_ta_mat-stlst = tp_stlst.

    wa_ta_mat-bmeng = tp_bmeng.

    wa_ta_mat-bmein = tp_bmein.

    append wa_ta_mat to ta_header.

    endselect.

    endloop.

    Endif.

    ENDFORM. " get_header_data

    &----


    *& Form get_top_page

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_top_page .

    move 'Display Monthly Report' to

    gt_list_top_of_page-info.

    gt_list_top_of_page-typ = 'H'.

    append gt_list_top_of_page.

    concatenate 'Plant :' pa_werks

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    select single vetxt into tp_vetxt

    from p44v

    where gstru = 'S076'

    and vrsio = pa_vrsio.

    concatenate 'Version :' pa_vrsio tp_vetxt

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    call function 'DATUMSAUFBEREITUNG'

    EXPORTING

    idate = sy-datum

    IMPORTING

    tdat8 = l_date_string

    EXCEPTIONS

    datfm_ungueltig = 1

    datum_ungueltig = 2

    others = 3.

    concatenate sy-uzeit(2) ':' sy-uzeit2(2) ':' sy-uzeit4(2)

    into l_time.

    concatenate 'Date/Time :' l_date_string l_time

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    ENDFORM. " get_top_page

    &----


    *& Form get_months

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_months .

    move pa_m_frm to t_mth1.

    perform get_next_few_months

    using t_mth1 '1'

    changing t_mth2.

    perform get_next_few_months

    using t_mth2 '1'

    changing t_mth3.

    perform get_next_few_months

    using t_mth3 '1'

    changing t_mth4.

    perform get_next_few_months

    using t_mth4 '1'

    changing t_mth5.

    perform get_next_few_months

    using t_mth5 '1'

    changing t_mth6.

    perform get_next_few_months

    using t_mth6 '1'

    changing t_mth7.

    perform get_next_few_months

    using t_mth7 '1'

    changing t_mth8.

    perform get_next_few_months

    using t_mth8 '1'

    changing t_mth9.

    perform get_next_few_months

    using t_mth9 '1'

    changing t_mth10.

    perform get_next_few_months

    using t_mth10 '1'

    changing t_mth11.

    perform get_next_few_months

    using t_mth11 '1'

    changing t_mth12.

    perform get_next_few_months

    using t_mth12 '1'

    changing t_mth13.

    perform get_next_few_months

    using t_mth13 '1'

    changing t_mth14.

    perform get_next_few_months

    using t_mth14 '1'

    changing t_mth15.

    perform get_next_few_months

    using t_mth15 '1'

    changing t_mth16.

    perform get_next_few_months

    using t_mth16 '1'

    changing t_mth17.

    perform get_next_few_months

    using t_mth17 '1'

    changing t_mth18.

    perform get_next_few_months

    using t_mth18 '1'

    changing t_mth19.

    perform get_next_few_months

    using t_mth19 '1'

    changing t_mth20.

    perform get_next_few_months

    using t_mth20 '1'

    changing t_mth21.

    perform get_next_few_months

    using t_mth21 '1'

    changing t_mth22.

    perform get_next_few_months

    using t_mth22 '1'

    changing t_mth23.

    perform get_next_few_months

    using t_mth23 '1'

    changing t_mth24.

    perform get_next_few_months

    using t_mth24 '1'

    changing t_mth25.

    perform get_next_few_months

    using t_mth25 '1'

    changing t_mth26.

    perform get_next_few_months

    using t_mth26 '1'

    changing t_mth27.

    perform get_next_few_months

    using t_mth27 '1'

    changing t_mth28.

    perform get_next_few_months

    using t_mth28 '1'

    changing t_mth29.

    perform get_next_few_months

    using t_mth29 '1'

    changing t_mth30.

    perform get_next_few_months

    using t_mth30 '1'

    changing t_mth31.

    perform get_next_few_months

    using t_mth31 '1'

    changing t_mth32.

    perform get_next_few_months

    using t_mth32 '1'

    changing t_mth33.

    perform get_next_few_months

    using t_mth33 '1'

    changing t_mth34.

    perform get_next_few_months

    using t_mth34 '1'

    changing t_mth35.

    perform get_next_few_months

    using t_mth35 '1'

    changing t_mth36.

    ENDFORM. " get_months

    &----


    *& Form get_next_few_months

    &----


    • text

    ----


    • -->LV_CURR_MONTH text

    • -->LV_MONTHS text

    • -->LV_TARGET_MTH text

    ----


    FORM get_next_few_months USING lv_curr_month lv_months

    changing lv_target_mth.

    data : tp_month_curr like sy-datum,

    tp_month_plus like sy-datum.

    concatenate lv_curr_month '01' into tp_month_curr.

    call function 'SG_PS_ADD_MONTH_TO_DATE'

    EXPORTING

    months = lv_months

    olddate = tp_month_curr

    IMPORTING

    newdate = tp_month_plus.

    move tp_month_plus(6) to lv_target_mth.

    ENDFORM. " get_next_few_months

    &----


    *& Form months_calculate

    &----


    • text

    ----


    • -->P_DATE1 text

    • -->P_DATE2 text

    • <--P_EMONTHS text

    ----


    form months_calculate using p_date1

    p_date2

    changing p_emonths.

    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

    exporting

    i_date_from = p_date1

    • I_KEY_DAY_FROM =

    i_date_to = p_date2

    • I_KEY_DAY_TO =

    • I_FLG_SEPARATE = ' '

    importing

    • E_DAYS =

    e_months = p_emonths.

    • E_YEARS =

    endform. " months_calculate

    *

    &----


    *& Form get_sales

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_sales .

    data: iseq type i,

    tp_sales type p decimals 2,

    tp_totalprice type p decimals 2,"added by pradeep on 03/07/07

    tp_maktx like makt-maktx,

    tp_tabix like sy-tabix,

    tp_pmnux like s076-pmnux,

    seq type i.

    data: yr_frm(6) type c,

    yr_to(6) type c.

    data: year_frm(4) type c,

    year_to(4) type c.

    data: month1(2) type c,

    month12(4) type c.

    data: totalsales like zspp003-mth1.

    data: yr_index like sy-subrc.

    • check if the Display monthly report is being selected *****

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    • retrieve months

    perform get_months.

    select * into corresponding fields of table lp_s076 from s076

    where pmnux = so_matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio

    and spmon ge pa_m_frm

    and spmon le pa_m_to.

    iseq = 1.

    seq = 0.

    loop at lp_s076.

    if sy-tabix = 1.

    write : lp_s076-pmnux to tp_pmnux.

    endif.

    select single maktx into tp_maktx from makt

    where matnr = lp_s076-pmnux.

    clear wa.

    read table ta_s076 into wa with key

    matnr = lp_s076-pmnux.

    if sy-subrc ne 0.

    wa-seq = iseq.

    wa-matnr = lp_s076-pmnux.

    wa-maktx = tp_maktx.

    endif.

    move lp_s076-absat to tp_sales.

    case lp_s076-spmon.

    when t_mth1.

    move tp_sales to wa-mth1.

    move t_mth1 to wa-sp1.

    ind1 = '1'.

    when t_mth2.

    move tp_sales to wa-mth2.

    move t_mth2 to wa-sp2.

    ind2 = '1'.

    when t_mth3.

    move tp_sales to wa-mth3.

    move t_mth3 to wa-sp3.

    ind3 = '1'.

    when t_mth4.

    move tp_sales to wa-mth4.

    move t_mth4 to wa-sp4.

    ind4 = '1'.

    when t_mth5.

    move tp_sales to wa-mth5.

    move t_mth5 to wa-sp5.

    ind5 = '1'.

    when t_mth6.

    move tp_sales to wa-mth6.

    move t_mth6 to wa-sp6.

    ind6 = '1'.

    when t_mth7.

    move tp_sales to wa-mth7.

    move t_mth7 to wa-sp7.

    ind7 = '1'.

    when t_mth8.

    move tp_sales to wa-mth8.

    move t_mth8 to wa-sp8.

    ind8 = '1'.

    when t_mth9.

    move tp_sales to wa-mth9.

    move t_mth9 to wa-sp9.

    ind9 = '1'.

    when t_mth10.

    move tp_sales to wa-mth10.

    move t_mth10 to wa-sp10.

    ind10 = '1'.

    when t_mth11.

    move tp_sales to wa-mth11.

    move t_mth11 to wa-sp11.

    ind11 = '1'.

    when t_mth12.

    move tp_sales to wa-mth12.

    move t_mth12 to wa-sp12.

    ind12 = '1'.

    when t_mth13.

    move tp_sales to wa-mth13.

    move t_mth13 to wa-sp13.

    ind13 = '1'.

    when t_mth14.

    move tp_sales to wa-mth14.

    move t_mth14 to wa-sp14.

    ind14 = '1'.

    when t_mth15.

    move tp_sales to wa-mth15.

    move t_mth15 to wa-sp15.

    ind15 = '1'.

    when t_mth16.

    move tp_sales to wa-mth16.

    move t_mth16 to wa-sp16.

    ind16 = '1'.

    when t_mth17.

    move tp_sales to wa-mth17.

    move t_mth17 to wa-sp17.

    ind17 = '1'.

    when t_mth18.

    move tp_sales to wa-mth18.

    move t_mth18 to wa-sp18.

    ind18 = '1'.

    when t_mth19.

    move tp_sales to wa-mth19.

    move t_mth19 to wa-sp19.

    ind19 = '1'.

    when t_mth20.

    move tp_sales to wa-mth20.

    move t_mth20 to wa-sp20.

    ind20 = '1'.

    when t_mth21.

    move tp_sales to wa-mth21.

    move t_mth21 to wa-sp21.

    ind21 = '1'.

    when t_mth22.

    move tp_sales to wa-mth22.

    move t_mth22 to wa-sp22.

    ind22 = '1'.

    when t_mth23.

    move tp_sales to wa-mth23.

    move t_mth23 to wa-sp23.

    ind23 = '1'.

    when t_mth24.

    move tp_sales to wa-mth24.

    move t_mth24 to wa-sp24.

    ind24 = '1'.

    when t_mth25.

    move tp_sales to wa-mth25.

    move t_mth25 to wa-sp25.

    ind25 = '1'.

    when t_mth26.

    move tp_sales to wa-mth26.

    move t_mth26 to wa-sp26.

    ind26 = '1'.

    when t_mth27.

    move tp_sales to wa-mth27.

    move t_mth27 to wa-sp27.

    ind27 = '1'.

    when t_mth28.

    move tp_sales to wa-mth28.

    move t_mth28 to wa-sp28.

    ind28 = '1'.

    when t_mth29.

    move tp_sales to wa-mth29.

    move t_mth29 to wa-sp29.

    ind29 = '1'.

    when t_mth30.

    move tp_sales to wa-mth30.

    move t_mth30 to wa-sp30.

    ind30 = '1'.

    when t_mth31.

    move tp_sales to wa-mth31.

    move t_mth31 to wa-sp31.

    ind31 = '1'.

    when t_mth32.

    move tp_sales to wa-mth32.

    move t_mth32 to wa-sp32.

    ind32 = '1'.

    when t_mth33.

    move tp_sales to wa-mth33.

    move t_mth33 to wa-sp33.

    ind33 = '1'.

    when t_mth34.

    move tp_sales to wa-mth34.

    move t_mth34 to wa-sp34.

    ind34 = '1'.

    when t_mth35.

    move tp_sales to wa-mth35.

    move t_mth35 to wa-sp35.

    ind35 = '1'.

    when t_mth36.

    move tp_sales to wa-mth36.

    move t_mth36 to wa-sp36.

    ind36 = '1'.

    endcase.

    • move seq to itab_seq-seq.

    • append itab_seq.

    tp_tabix = sy-tabix.

    if sy-subrc = 0.

    • modify table ta_s076 from wa.

    modify ta_s076 from wa index tp_tabix.

    if lp_s076-pmnux = tp_pmnux.

    seq = seq + 1.

    move seq to itab_seq.

    append itab_seq.

    endif.

    else.

    append wa to ta_s076.

    if lp_s076-pmnux = tp_pmnux.

    seq = seq + 1.

    move seq to itab_seq.

    append itab_seq.

    endif.

    endif.

    iseq = iseq + 1.

    endloop. " endloop for lp_s076.

    itb_sales[] = ta_s076[].

    • itb_sales12[] = ta_s076[].

    endif.

    ENDFORM. " get_sales

    &----


    *& Form retrieve_bom

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM retrieve_bom .

    • retrieve BOM components

    sort ta_header by matnr.

    loop at ta_header where stlan = '1' and stlst = '01'.

    tp_bmeng = '1'.

    perform get_bom tables ta_stpo using

    ta_header-matnr ta_header-werks ta_header-stlan ta_header-stlal tp_bmeng.

    • requirement quantity calculation for active bom

    perform calculation1.

    • retrieve BOM components for pgm

    sort itab_bom2 by idnrk ascending.

    delete adjacent duplicates from itab_bom2 comparing matnr idnrk.

    • loop at itab_bom2. " commented by weihong

    tp_stlan = '1'.

    tp_stlal = '02'.

    perform get_pgm tables ta_stpo12 using

    itab_bom2-matnr ta_header-werks tp_stlan tp_stlal.

    • endloop. " endloop for itab_bom2.(commented by weihong)

    • requirement quantity calculation for inactive bom

    perform calculation2.

    refresh : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    clear : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    endloop. " endloop for ta_header.

    **itab_msale itab_ysale

    *break-point.

    perform display_alv.

    ENDFORM. " retrieve_bom

    &----


    *& Form calculation1

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM calculation1 .

    data : tp_tabix like sy-tabix.

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    clear wa.

    • loop at ta_s076 into wa where matnr = itab_bom11.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-mth1 = wa-mth1 * wa_bom1-mngko.

    wa-mth2 = wa-mth2 * wa_bom1-mngko.

    wa-mth3 = wa-mth3 * wa_bom1-mngko.

    wa-mth4 = wa-mth4 * wa_bom1-mngko.

    wa-mth5 = wa-mth5 * wa_bom1-mngko.

    wa-mth6 = wa-mth6 * wa_bom1-mngko.

    wa-mth7 = wa-mth7 * wa_bom1-mngko.

    wa-mth8 = wa-mth8 * wa_bom1-mngko.

    wa-mth9 = wa-mth9 * wa_bom1-mngko.

    wa-mth10 = wa-mth10 * wa_bom1-mngko.

    wa-mth11 = wa-mth11 * wa_bom1-mngko.

    wa-mth12 = wa-mth12 * wa_bom1-mngko.

    wa-mth13 = wa-mth13 * wa_bom1-mngko.

    wa-mth14 = wa-mth14 * wa_bom1-mngko.

    wa-mth15 = wa-mth15 * wa_bom1-mngko.

    wa-mth16 = wa-mth16 * wa_bom1-mngko.

    wa-mth17 = wa-mth17 * wa_bom1-mngko.

    wa-mth18 = wa-mth18 * wa_bom1-mngko.

    wa-mth19 = wa-mth19 * wa_bom1-mngko.

    wa-mth20 = wa-mth20 * wa_bom1-mngko.

    wa-mth21 = wa-mth21 * wa_bom1-mngko.

    wa-mth22 = wa-mth22 * wa_bom1-mngko.

    wa-mth23 = wa-mth23 * wa_bom1-mngko.

    wa-mth24 = wa-mth24 * wa_bom1-mngko.

    wa-mth25 = wa-mth25 * wa_bom1-mngko.

    wa-mth26 = wa-mth26 * wa_bom1-mngko.

    wa-mth27 = wa-mth27 * wa_bom1-mngko.

    wa-mth28 = wa-mth28 * wa_bom1-mngko.

    wa-mth29 = wa-mth29 * wa_bom1-mngko.

    wa-mth31 = wa-mth31 * wa_bom1-mngko.

    wa-mth32 = wa-mth32 * wa_bom1-mngko.

    wa-mth33 = wa-mth33 * wa_bom1-mngko.

    wa-mth34 = wa-mth34 * wa_bom1-mngko.

    wa-mth35 = wa-mth35 * wa_bom1-mngko.

    wa-mth36 = wa-mth36 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    wa-bom = wa_bom1-bom.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop. " endloop for itab_bom

    endif.

    ENDFORM. " calculation1

    &----


    *& Form calculation2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM calculation2 .

    • check if the Display monthly report is being selected

    if ra_mth = 'X' and

    pa_m_frm <> 0 and

    pa_m_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-mth1 = wa-mth1 * wa_bom2-mngko.

    wa-mth2 = wa-mth2 * wa_bom2-mngko.

    wa-mth3 = wa-mth3 * wa_bom2-mngko.

    wa-mth4 = wa-mth4 * wa_bom2-mngko.

    wa-mth5 = wa-mth5 * wa_bom2-mngko.

    wa-mth6 = wa-mth6 * wa_bom2-mngko.

    wa-mth7 = wa-mth7 * wa_bom2-mngko.

    wa-mth8 = wa-mth8 * wa_bom2-mngko.

    wa-mth9 = wa-mth9 * wa_bom2-mngko.

    wa-mth10 = wa-mth10 * wa_bom2-mngko.

    wa-mth11 = wa-mth11 * wa_bom2-mngko.

    wa-mth12 = wa-mth12 * wa_bom2-mngko.

    wa-mth13 = wa-mth13 * wa_bom2-mngko.

    wa-mth14 = wa-mth14 * wa_bom2-mngko.

    wa-mth15 = wa-mth15 * wa_bom2-mngko.

    wa-mth16 = wa-mth16 * wa_bom2-mngko.

    wa-mth17 = wa-mth17 * wa_bom2-mngko.

    wa-mth18 = wa-mth18 * wa_bom2-mngko.

    wa-mth19 = wa-mth19 * wa_bom2-mngko.

    wa-mth20 = wa-mth20 * wa_bom2-mngko.

    wa-mth21 = wa-mth21 * wa_bom2-mngko.

    wa-mth22 = wa-mth22 * wa_bom2-mngko.

    wa-mth23 = wa-mth23 * wa_bom2-mngko.

    wa-mth24 = wa-mth24 * wa_bom2-mngko.

    wa-mth25 = wa-mth25 * wa_bom2-mngko.

    wa-mth26 = wa-mth26 * wa_bom2-mngko.

    wa-mth27 = wa-mth27 * wa_bom2-mngko.

    wa-mth28 = wa-mth28 * wa_bom2-mngko.

    wa-mth29 = wa-mth29 * wa_bom2-mngko.

    wa-mth31 = wa-mth31 * wa_bom2-mngko.

    wa-mth32 = wa-mth32 * wa_bom2-mngko.

    wa-mth33 = wa-mth33 * wa_bom2-mngko.

    wa-mth34 = wa-mth34 * wa_bom2-mngko.

    wa-mth35 = wa-mth35 * wa_bom2-mngko.

    wa-mth36 = wa-mth36 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_msale.

    append itab_msale.

    clear itab_msale.

    clear wa.

    endloop.

    endif.

    ENDFORM. " calculation2

    &----


    *& Form get_bom

    &----


    • text

    ----


    • -->LV_MATNR text

    • -->LV_WERKS text

    • -->LV_STLAN text

    • -->LV_STLAL text

    ----


    FORM get_bom TABLES lt_STPO STRUCTURE stpox

    using lv_matnr like mast-matnr

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal

    lv_emeng like stko-bmeng .

    data: ta_topmat type cstmat,

    tp_dstst like csdata-xfeld,

    ta_matcat type cscmat occurs 0,

    tp_index like sy-tabix,

    tp_stufe like stpox-stufe,

    tp_diff like stpox-stufe,

    tp_indx like sy-tabix,

    tp_date like sy-datum,

    lv_stufe like stpox-stufe,

    lv_wegxx like stpox-wegxx,

    lv_stprs like stpox-stprs,

    lv_waers like stpox-waers,

    • lv_cuky_new like cdpos-cuky_new,

    • lv_value_new like cdpos-value_new,

    lv_index like sy-tabix,

    lv_datum like sy-datum,"added by pradeep on 02-07-07

    nxt_index like sy-tabix.

    • added by weihong.

    data: tp_mtart like mara-mtart,

    tp_matkl like mara-matkl,

    tp_stprs like stpox-stprs,

    tp_bomlv1 like mast-matnr,

    tp_bomlv2 like mast-matnr,

    tp_bomlv3 like mast-matnr,

    tp_bomlv4 like mast-matnr,

    tp_indln type i.

    write : lv_matnr to itab_bom1-matnr.

    write : lv_matnr to itab_bom2-matnr.

    write : lv_matnr to itab_path-matnr.

    call function 'CS_BOM_EXPL_MAT_V2'

    exporting

    capid = 'PP01'

    datuv = sy-datum

    emeng = lv_emeng

    • ftrel = lv_level

    mktls = 'X'

    mehrs = 'X'

    rndkz = '2'

    mtnrv = lv_matnr

    stlal = lv_stlal

    stlan = lv_stlan

    stpst = '0'

    svwvo = 'X'

    werks = lv_werks

    vrsvo = 'X'

    ehndl = '2'

    importing

    topmat = ta_topmat

    dstst = tp_dstst

    tables

    stb = lt_stpo

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

    loop at lt_stpo.

    move lt_stpo-stufe to itab_path-stufe.

    move lt_stpo-wegxx to itab_path-wegxx.

    move lt_stpo-idnrk to itab_path-idnrk.

    append itab_path.

    endloop.

    *sort itab_path by stufe wegxx.

    loop at lt_stpo into wa_stpo.

    tp_tabix = sy-tabix.

    • check if level 1

    if wa_stpo-stufe = '1'.

    itab_bom1-bom = lv_matnr.

    • check if level 2

    elseif wa_stpo-stufe = '2'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '1'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv1 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '2'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv1..

    endif.

    • check if level 3

    elseif wa_stpo-stufe = '3'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '2'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv2 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '3'

    • wegxx = '1'.

    *

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv2.

    endif.

    • check if level 4

    elseif wa_stpo-stufe = '4'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '3'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv3 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '4'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv3.

    endif.

    elseif wa_stpo-stufe = '5'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '4'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv4 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '5'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv4.

    endif.

    else.

    endif.

    select single maktx into itab_bom1-c_maktx from makt

    where matnr = wa_stpo-idnrk.

    • if wa_stpo-mtart <> 'ZRUH'.

    move-corresponding wa_stpo to itab_bom1.

    append itab_bom1.

    • else.

    if wa_stpo-mtart eq 'ZRUH'.

    move-corresponding wa_stpo to itab_bom2.

    append itab_bom2.

    endif.

    *clear: tp_bomlv.

    endloop.

    refresh: lt_stpo.

    clear:lt_stpo.

    temp_bom1[] = itab_bom1[].

    describe table itab_bom1 lines tp_indln.

    loop at itab_bom1 where matnr = lv_matnr.

    if itab_bom1-mtart = 'ZHLB' and itab_bom1-matkl <> 'WP0100'

    and itab_bom1-matkl <> 'WP0110'

    and itab_bom1-matkl <> 'WP0120'.

    • tp_indx = sy-tabix.

    • lv_stufe = itab_bom1-stufe.

    • lv_wegxx = itab_bom1-wegxx + 1.

    • nxt_index = tp_indx + 1.

    *

    *

    • read table temp_bom1 index nxt_index.

    • if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    *

    • read table temp_bom1 with key stufe = lv_stufe

    • wegxx = lv_wegxx.

    • lv_index = sy-tabix - 1.

    • if lv_index > nxt_index.

    • append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    • endif.

    • clear: tp_indx, nxt_index, lv_index.

    *

    • endif.

    tp_indx = sy-tabix.

    lv_stufe = itab_bom1-stufe.

    lv_wegxx = itab_bom1-wegxx + 1.

    nxt_index = tp_indx + 1.

    read table temp_bom1 index nxt_index.

    if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    read table temp_bom1 with key stufe = lv_stufe

    wegxx = lv_wegxx.

    lv_index = sy-tabix - 1.

    if lv_index > nxt_index.

    append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    elseif lv_index < 0.

    append lines of itab_bom1 from nxt_index to tp_indln to itb_bm1.

    endif.

    clear: tp_indx, nxt_index, lv_index.

    endif.

    endif.

    endloop.

    • clear table

    • loop at itb_bm1 where matnr = ta_header-matnr.

    loop at itb_bm1 where matnr = lv_matnr.

    • loop at itab_bom1 where matnr = itb_bm1-matnr.

    delete itab_bom1 where stufe = itb_bm1-stufe and wegxx = itb_bm1-wegxx.

    • read table itab_bom1 with key stufe = itb_bm1-stufe

    • wegxx = itb_bm1-wegxx

    • matnr = itb_bm1-matnr

    • bom = itb_bm1-bom

    • idnrk = itb_bm1-idnrk.

    • if sy-subrc eq 0.

    • delete itab_bom1 index lv_index.

    • endif.

    • endloop.

    endloop.

    clear: itb_bm1.

    refresh: itb_bm1.

    loop at itab_bom1.

    tp_tabix = sy-tabix.

    if itab_bom1-mtart eq 'ZRUH'.

    delete itab_bom1 index tp_tabix.

    endif.

    endloop.

    ENDFORM. " get_bom

    &----


    *& Form get_pgm

    &----


    • text

    ----


    • -->P_TA_STPO12 text

    • -->P_ITAB_BOM2_MATNR text

    • -->P_TA_HEADER_WERKS text

    • -->P_TP_STLAN text

    • -->P_TP_STLAL text

    ----


    FORM get_pgm TABLES lt_stpo12 STRUCTURE bom_item_api01

    using lv_matnr like mast-matnr

    • lv_idnrk like stpox-idnrk

    pa_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal.

    data: lt_stko12 type stko_api02 occurs 0.

    data: tp_quantity like stpox-menge.

    write : lv_matnr to itab_pgm-matnr.

    • if lt_stpo12 is not initial.

    • refresh: lt_stpo12.

    • clear:lt_stpo12.

    • endif.

    call function 'CSEP_MAT_BOM_READ'

    EXPORTING

    material = lv_matnr

    plant = pa_werks

    bom_usage = lv_stlan

    alternative = lv_stlal

    TABLES

    t_stpo = lt_stpo12

    t_stko = lt_stko12

    EXCEPTIONS

    error = 1.

    • if sy-subrc ne 0.

    • message e066(zwaa001).

    • endif.

    if sy-subrc = 0.

    loop at lt_stpo12 into wa_stpo12.

    replace all occurrences of ',' in wa_stpo12-comp_qty with ''.

    move wa_stpo12-comp_qty to tp_quantity.

    select single maktx into itab_pgm-c_maktx from makt

    where matnr = wa_stpo12-component and

    spras = 'E'.

    move wa_stpo12-comp_qty to itab_pgm-mngko.

    move-corresponding wa_stpo12 to itab_pgm.

    • Added by Soh.

    select single matkl into itab_pgm-matkl

    from mara

    where matnr = itab_pgm-component.

    • Added by pradeep

    select single stprs into itab_pgm-stprs

    from mbew

    where matnr = itab_pgm-reQuantity.

    append itab_pgm.

    endloop.

    refresh: lt_stpo12.

    clear:lt_stpo12.

    endif.

    ENDFORM. " get_pgm

    Year

    &----


    *& Report ZRPP025

    &----


    &----


    *& Developer : Pradeep

    *& Date : 16/07/2007

    *& Description : To get yearly report

    &----


    REPORT ZRPP025.

    include zipp007.

    selection-screen begin of block BLK with Frame title text-001.

    data:ra_yea.

    data:so_matnr like mara-matnr,

    pa_werks like t001l-werks,

    pa_vrsio like s076-vrsio,

    yr_index like sy-subrc,

    yr_frm(6) type c,

    yr_to(6) type c,

    year_frm(4) type c,

    year_to(4) type c,

    month1(2) type c,

    month12(4) type c,

    totalsales like zspp003-mth1,

    tp_maktx like makt-maktx,

    tp_pmnux like s076-pmnux.

    selection-screen skip 1.

    selection-screen begin of line.

    selection-screen: comment 1(31) text-001.

    parameters:pa_y_frm(6) type c.

    selection-screen: comment 40(30) text-002.

    selection-screen end of line.

    selection-screen begin of line.

    selection-screen: comment 1(31) text-003.

    parameters:pa_y_to(6) type c.

    selection-screen: comment 40(30) text-004.

    selection-screen end of line..

    parameter pa_yea type c no-display.

    selection-screen end of block BLK.

    initialization.

    clear: ta_versi, ta_type.

    refresh: ta_versi, ta_type.

    at selection-screen output.

    if ra_yea = 'X'.

    loop at screen.

    if screen-name = 'PA_Y_FRM'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C005017_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C006019_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = 'PA_Y_TO'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C007022_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    if screen-name = '%C008024_1000'.

    screen-active = '1'.

    modify screen.

    endif.

    endloop.

    endif.

    Start-of-selection.

    ra_yea = pa_yea.

    select * into corresponding fields of table ta_vrsio

    from p44v

    where gstru = 'S076'.

    sort ta_vrsio by vrsio.

    delete adjacent duplicates from ta_vrsio.

    move 'YEAR' to ta_type-out_type.

    append ta_type.

    End-of-selection.

    perform get_header_data.

    perform get_top_page.

    perform display_alv.

    &----


    *& Form display_alv

    &----


    • text

    ----


    form display_alv.

    • ALV ***

    g_repid = sy-repid.

    perform layout_init using gs_layout.

    perform eventtab_build using gt_events[].

    gs_variant-report = g_repid.

    g_save = 'A'.

    • Display yearly report

    if ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    perform fieldcat_init_yr using gt_fieldcat[].

    perform printer_setting using print_set.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_background_id = 'ALV_BACKGROUND'

    i_buffer_active = 'X'

    i_callback_program = g_repid

    i_structure_name = 'ITAB_YSALE'

    is_layout = gs_layout

    it_fieldcat = gt_fieldcat[]

    i_save = g_save

    is_variant = gs_variant

    it_events = gt_events[]

    it_sort = gt_it_sort[]

    is_print = print_set

    • I_SCREEN_START_COLUMN = 0 "Use coordinates for

    • I_SCREEN_START_LINE = 0 "display as dialog box

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    importing

    e_exit_caused_by_caller = g_exit_caused_by_caller

    es_exit_caused_by_user = gs_exit_caused_by_user

    tables

    t_outtab = itab_ysale

    exceptions

    program_error = 1

    others = 2.

    if sy-subrc = 0.

    if g_exit_caused_by_caller = 'X'.

    *" Forced Exit by calling program

    *" <do_something>.

    else.

    *" User left list via F3, F12 or F15

    if gs_exit_caused_by_user-back = 'X'. "F3

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-exit = 'X'. "F15

    *" <do_something>.

    else.

    if gs_exit_caused_by_user-cancel = 'X'. "F12

    *" <do_something>.

    else.

    *" should not occur!

    *" <do_Abnormal_End>.

    endif.

    endif.

    endif.

    endif.

    else.

    *"Fatal error callin ALV

    • MESSAGE AXXX(XY) WITH ...

    endif.

    endif.

    endform. "display_al

    &----


    *& Form get_header_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_header_data .

    select pmnux into ta_mat-matnr

    from s076

    where pmnux = so_matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio.

    append ta_mat.

    clear ta_mat.

    endselect.

    if sy-subrc = 0.

    sort ta_mat by matnr .

    delete adjacent duplicates from ta_mat.

    loop at ta_mat.

    select matnr stlnr stlan stlal

    appending corresponding fields of table ta_mat2

    from mast

    where matnr = ta_mat-matnr

    and werks = pa_werks.

    endloop.

    loop at ta_mat2 into wa_ta_mat.

    select stlst bmeng bmein into (tp_stlst,tp_bmeng,tp_bmein)

    from stko

    where stlnr = wa_ta_mat-stlnr

    and stlal = wa_ta_mat-stlal.

    wa_ta_mat-stlst = tp_stlst.

    wa_ta_mat-bmeng = tp_bmeng.

    wa_ta_mat-bmein = tp_bmein.

    append wa_ta_mat to ta_header.

    endselect.

    endloop.

    perform checking. "checking if monthly or yearly report is being selected

    endif.

    ENDFORM. " get_header_data

    &----


    *& Form checking

    &----


    • text

    ----


    form checking.

    data : date1 like vtbbewe-dbervon,

    date2 like vtbbewe-dberbis.

    data : emonths like vtbbewe-atage.

    data : lv_y_frm(4) type n,

    lv_y_to(4) type n.

    • check if the Display yearly report is being selected *****

    if ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    itab_bom-requantity = lp_s076-absat. "for current year 2006 ."added by pradeep on 4/07/07

    itab_bom-requantity = lp_s076-absat + 1. "ie 2007.

    itab_bom-requantity = lp_s076-absat + 2. "ie 2008.

    • check for correct input format

    lv_y_frm = pa_y_frm.

    lv_y_to = pa_y_to.

    if lv_y_frm ge '2000' and lv_y_to ge '2000'.

    • calculate the months in between

    clear date1.

    clear date2.

    concatenate pa_y_frm '0101' into date1.

    concatenate pa_y_to '1201' into date2.

    • concatenate pa_y_to '1231' into date2.

    perform months_calculate using date1 date2 changing emonths.

    • check if months <= 36.

    if emonths <= 36.

    perform get_sales.

    perform retrieve_bom.

    else.

    message i001(zwpp001).

    exit. " error message

    endif.

    else.

    message i002(zwpp001).

    endif.

    exit.

    • added by pradeep on 04/07/07

  • if emonths = 4.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • if emonths = 5.

  • tp_totalprice = lp_s076-absat * ta_mat-stprs.

  • endif.

  • if emonths = 6.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • if emonths = 7.

  • tp_totalprice = lp_s076-absat * ta_mat-stprs.

  • endif.

  • if emonths = 8.

  • itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

  • endif.

  • endif.

    endform. " checking

    &----


    *& Form months_calculate

    &----


    • text

    ----


    • -->P_DATE1 text

    • -->P_DATE2 text

    • <--P_EMONTHS text

    ----


    FORM months_calculate USING P_DATE1

    P_DATE2

    CHANGING P_EMONTHS.

    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

    exporting

    i_date_from = p_date1

    • I_KEY_DAY_FROM =

    i_date_to = p_date2

    • I_KEY_DAY_TO =

    • I_FLG_SEPARATE = ' '

    importing

    • E_DAYS =

    e_months = p_emonths.

    • E_YEARS =

    ENDFORM. " months_calculate

    &----


    *& Form get_top_page

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_top_page .

    move 'Display Yearly report' to

    gt_list_top_of_page-info.

    gt_list_top_of_page-typ = 'H'.

    append gt_list_top_of_page.

    concatenate 'Plant :' pa_werks

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    select single vetxt into tp_vetxt

    from p44v

    where gstru = 'S076'

    and vrsio = pa_vrsio.

    concatenate 'Version :' pa_vrsio tp_vetxt

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    call function 'DATUMSAUFBEREITUNG'

    EXPORTING

    idate = sy-datum

    IMPORTING

    tdat8 = l_date_string

    EXCEPTIONS

    datfm_ungueltig = 1

    datum_ungueltig = 2

    others = 3.

    concatenate sy-uzeit(2) ':' sy-uzeit2(2) ':' sy-uzeit4(2)

    into l_time.

    concatenate 'Date/Time :' l_date_string l_time

    into gt_list_top_of_page-info separated by space.

    gt_list_top_of_page-typ = 'S'.

    append gt_list_top_of_page.

    ENDFORM. " get_top_page

    &----


    *& Form get_years

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_years .

    Data : tp_yr_frm(4) type n.

    data : tp_yr_to(4) type n.

    data : yr_diff(4) type n.

    move pa_y_frm to tp_yr_frm.

    move pa_y_to to tp_yr_to.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    yr_diff = tp_yr_to - tp_yr_frm.

    *number of years = 3

    if yr_diff = 2.

    do 2 times.

    tp_yr_frm = tp_yr_frm + 1.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    enddo.

    *number of years = 2

    elseif yr_diff = 1.

    tp_yr_frm = tp_yr_frm + 1.

    move tp_yr_frm to ta_yr-year.

    append ta_yr.

    else.

    exit.

    endif.

    ENDFORM. " get_years

    &----


    *& Form get_sales

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_sales .

    data: iseq type i,

    tp_sales type p decimals 2,

    tp_totalprice type p decimals 2,"added by pradeep on 03/07/07

    tp_maktx like makt-maktx,

    tp_tabix like sy-tabix,

    tp_pmnux like s076-pmnux,

    seq type i.

    data: yr_frm(6) type c,

    yr_to(6) type c.

    data: year_frm(4) type c,

    year_to(4) type c.

    data: month1(2) type c,

    month12(4) type c.

    data: totalsales like zspp003-mth1.

    data: yr_index like sy-subrc.

    • check if the Display yearly report is being selected *****

    if ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear year1.

    clear year2.

    clear year3.

    perform get_years.

    loop at ta_mat.

    loop at ta_yr.

    clear yr_index.

    yr_index = sy-tabix.

    case yr_index.

    when '1'.

    year1 = ta_yr-year.

    when '2'.

    year2 = ta_yr-year.

    when '3'.

    year3 = ta_yr-year.

    endcase.

    clear yr_frm.

    clear yr_to.

    year_frm = ta_yr-year.

    year_to = ta_yr-year.

    month1 = '01'.

    month12 = '12'.

    concatenate year_frm month1 into yr_frm.

    concatenate year_to month12 into yr_to.

    select * into corresponding fields of table lp_s076 from s076

    where pmnux = ta_mat-matnr

    and wenux = pa_werks

    and vrsio = pa_vrsio

    and spmon ge yr_frm

    and spmon le yr_to.

    • calculate total sales.

    totalsales = 0.

    loop at lp_s076.

    at first.

    sum.

    totalsales = lp_s076-absat.

    endat.

    at end of absat."added by pradeep on 4/07/07

    sum.

    tp_totalprice = lp_s076-absat * ta_mat-stprs.

    itab_bom-requantity = lp_s076-absat * itab_bom-comp_qty / itab_bom-xmeng.

    endat.

    endloop. "endloop for lp_s076

    select single maktx into tp_maktx from makt

    where matnr = ta_mat-matnr.

    read table ta_s076 into wa with key

    matnr = ta_mat-matnr.

    if sy-subrc ne 0.

    wa-matnr = lp_s076-pmnux.

    wa-maktx = tp_maktx.

    endif.

    case yr_index.

    when '1'.

    move totalsales to wa-sales_y1.

    move tp_totalprice to wa-sales_y1."added by pradeep

    move ta_yr-year to wa-year1.

    ind1 = '1'.

    when '2'.

    move totalsales to wa-sales_y2.

    move tp_totalprice to wa-sales_y2.

    move ta_yr-year to wa-year2.

    ind2 = '1'.

    when '3'.

    move totalsales to wa-sales_y3.

    move tp_totalprice to wa-sales_y3.

    move ta_yr-year to wa-year3.

    ind3 = '1'.

    endcase.

    tp_tabix = sy-tabix.

    if sy-subrc = 0.

    • modify table ta_s076 from wa.

    modify ta_s076 from wa index tp_tabix.

    else.

    append wa to ta_s076.

    endif.

    endloop. "endloop for ta_yr

    endloop. "endloop for ta_mat

    itb_sales[] = ta_s076[].

    else.

    exit.

    endif.

    ENDFORM. " get_sales

    &----


    *& Form retrieve_bom

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM retrieve_bom .

    • retrieve BOM components

    sort ta_header by matnr.

    loop at ta_header where stlan = '1' and stlst = '01'.

    tp_bmeng = '1'.

    perform get_bom tables ta_stpo using

    ta_header-matnr ta_header-werks ta_header-stlan ta_header-stlal tp_bmeng.

    • requirement quantity calculation for active bom

    perform calculation1.

    • retrieve BOM components for pgm

    sort itab_bom2 by idnrk ascending.

    delete adjacent duplicates from itab_bom2 comparing matnr idnrk.

    • loop at itab_bom2. " commented by weihong

    tp_stlan = '1'.

    tp_stlal = '02'.

    perform get_pgm tables ta_stpo12 using

    itab_bom2-matnr ta_header-werks tp_stlan tp_stlal.

    • endloop. " endloop for itab_bom2.(commented by weihong)

    • requirement quantity calculation for inactive bom

    perform calculation2.

    refresh : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    clear : itab_bom1, itab_bom2, itab_pgm, temp_bom1,itab_path.

    endloop. " endloop for ta_header.

    **itab_msale itab_ysale

    *break-point.

    perform display_alv.

    ENDFORM. " retrieve_bom

    &----


    *& Form calculation1

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM calculation1 .

    data : tp_tabix like sy-tabix.

    • check if the Display yearly report is being selected ****

    if ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    clear wa.

    loop at itab_bom1 into wa_bom1 where matnr = ta_header-matnr.

    read table itb_sales into wa with key

    matnr = wa_bom1-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom1-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom1-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom1-mngko.

    wa-idnrk = wa_bom1-idnrk.

    wa-c_maktx = wa_bom1-c_maktx.

    wa-meins = wa_bom1-meins.

    wa-stlnr = wa_bom1-stlnr.

    wa-bom = wa_bom1-bom.

    wa-mtart = wa_bom1-mtart.

    wa-matkl = wa_bom1-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop. " endloop for itab_bom

    endif.

    ENDFORM. " calculation1

    &----


    *& Form calculation2

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM calculation2 .

    • check if the Display yearly report is being selected ****

    if ra_yea = 'X' and

    pa_y_frm <> 0 and

    pa_y_to <> 0.

    loop at itab_pgm into wa_bom2 where matnr = ta_header-matnr.

    clear wa.

    read table itb_sales into wa with key

    matnr = wa_bom2-matnr.

    wa-sales_y1 = wa-sales_y1 * wa_bom2-mngko.

    wa-sales_y2 = wa-sales_y2 * wa_bom2-mngko.

    wa-sales_y3 = wa-sales_y3 * wa_bom2-mngko.

    wa-idnrk = wa_bom2-component.

    wa-c_maktx = wa_bom2-ktext.

    wa-meins = wa_bom2-comp_unit.

    wa-stlnr = wa_bom2-stlnr.

    wa-bom = wa_bom2-matnr.

    wa-mtart = wa_bom2-mtart.

    wa-matkl = wa_bom2-matkl.

    move-corresponding wa to itab_ysale.

    append itab_ysale.

    clear itab_ysale.

    endloop.

    endif.

    ENDFORM. " calculation2

    &----


    *& Form get_bom

    &----


    • text

    ----


    • -->LV_MATNR text

    • -->LV_WERKS text

    • -->LV_STLAN text

    • -->LV_STLAL text

    ----


    FORM get_bom TABLES lt_stpo structure stpox

    using lv_matnr like mast-matnr

    lv_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal

    lv_emeng like stko-bmeng .

    data: ta_topmat type cstmat,

    tp_dstst like csdata-xfeld,

    ta_matcat type cscmat occurs 0,

    tp_index like sy-tabix,

    tp_stufe like stpox-stufe,

    tp_diff like stpox-stufe,

    tp_indx like sy-tabix,

    tp_date like sy-datum,

    lv_stufe like stpox-stufe,

    lv_wegxx like stpox-wegxx,

    lv_stprs like stpox-stprs,

    lv_waers like stpox-waers,

    • lv_cuky_new like cdpos-cuky_new,

    • lv_value_new like cdpos-value_new,

    lv_index like sy-tabix,

    lv_datum like sy-datum,"added by pradeep on 02-07-07

    nxt_index like sy-tabix.

    • added by weihong.

    data: tp_mtart like mara-mtart,

    tp_matkl like mara-matkl,

    tp_stprs like stpox-stprs,

    tp_bomlv1 like mast-matnr,

    tp_bomlv2 like mast-matnr,

    tp_bomlv3 like mast-matnr,

    tp_bomlv4 like mast-matnr,

    tp_indln type i.

    write : lv_matnr to itab_bom1-matnr.

    write : lv_matnr to itab_bom2-matnr.

    write : lv_matnr to itab_path-matnr.

    call function 'CS_BOM_EXPL_MAT_V2'

    exporting

    capid = 'PP01'

    datuv = sy-datum

    emeng = lv_emeng

    • ftrel = lv_level

    mktls = 'X'

    mehrs = 'X'

    rndkz = '2'

    mtnrv = lv_matnr

    stlal = lv_stlal

    stlan = lv_stlan

    stpst = '0'

    svwvo = 'X'

    werks = lv_werks

    vrsvo = 'X'

    ehndl = '2'

    importing

    topmat = ta_topmat

    dstst = tp_dstst

    tables

    stb = lt_stpo

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

    loop at lt_stpo.

    move lt_stpo-stufe to itab_path-stufe.

    move lt_stpo-wegxx to itab_path-wegxx.

    move lt_stpo-idnrk to itab_path-idnrk.

    append itab_path.

    endloop.

    *sort itab_path by stufe wegxx.

    loop at lt_stpo into wa_stpo.

    tp_tabix = sy-tabix.

    • check if level 1

    if wa_stpo-stufe = '1'.

    itab_bom1-bom = lv_matnr.

    • check if level 2

    elseif wa_stpo-stufe = '2'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '1'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv1 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '2'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv1..

    endif.

    • check if level 3

    elseif wa_stpo-stufe = '3'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '2'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv2 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '3'

    • wegxx = '1'.

    *

    • itab_bom1-bom = itab_path-bom..

    itab_bom1-bom = tp_bomlv2.

    endif.

    • check if level 4

    elseif wa_stpo-stufe = '4'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '3'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv3 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '4'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv3.

    endif.

    elseif wa_stpo-stufe = '5'.

    tp_index = tp_tabix - 1.

    read table itab_path index tp_index.

    if itab_path-stufe = '4'.

    itab_bom1-bom = itab_path-idnrk.

    read table itab_path into wa_path index tp_tabix.

    wa_path-bom = itab_bom1-bom.

    tp_bomlv4 = itab_bom1-bom.

    modify itab_path from wa_path index tp_tabix.

    clear wa_path.

    else.

    • read table itab_path with key stufe = '5'

    • wegxx = '1'.

    • itab_bom1-bom = itab_path-bom.

    itab_bom1-bom = tp_bomlv4.

    endif.

    else.

    endif.

    select single maktx into itab_bom1-c_maktx from makt

    where matnr = wa_stpo-idnrk.

    • if wa_stpo-mtart <> 'ZRUH'.

    move-corresponding wa_stpo to itab_bom1.

    append itab_bom1.

    • else.

    if wa_stpo-mtart eq 'ZRUH'.

    move-corresponding wa_stpo to itab_bom2.

    append itab_bom2.

    endif.

    *clear: tp_bomlv.

    endloop.

    refresh: lt_stpo.

    clear:lt_stpo.

    temp_bom1[] = itab_bom1[].

    describe table itab_bom1 lines tp_indln.

    loop at itab_bom1 where matnr = lv_matnr.

    if itab_bom1-mtart = 'ZHLB' and itab_bom1-matkl <> 'WP0100'

    and itab_bom1-matkl <> 'WP0110'

    and itab_bom1-matkl <> 'WP0120'.

    • tp_indx = sy-tabix.

    • lv_stufe = itab_bom1-stufe.

    • lv_wegxx = itab_bom1-wegxx + 1.

    • nxt_index = tp_indx + 1.

    *

    *

    • read table temp_bom1 index nxt_index.

    • if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    *

    • read table temp_bom1 with key stufe = lv_stufe

    • wegxx = lv_wegxx.

    • lv_index = sy-tabix - 1.

    • if lv_index > nxt_index.

    • append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    • endif.

    • clear: tp_indx, nxt_index, lv_index.

    *

    • endif.

    tp_indx = sy-tabix.

    lv_stufe = itab_bom1-stufe.

    lv_wegxx = itab_bom1-wegxx + 1.

    nxt_index = tp_indx + 1.

    read table temp_bom1 index nxt_index.

    if temp_bom1-stufe ne lv_stufe and temp_bom1-wegxx ne lv_wegxx.

    read table temp_bom1 with key stufe = lv_stufe

    wegxx = lv_wegxx.

    lv_index = sy-tabix - 1.

    if lv_index > nxt_index.

    append lines of itab_bom1 from nxt_index to lv_index to itb_bm1.

    elseif lv_index < 0.

    append lines of itab_bom1 from nxt_index to tp_indln to itb_bm1.

    endif.

    clear: tp_indx, nxt_index, lv_index.

    endif.

    endif.

    endloop.

    • clear table

    • loop at itb_bm1 where matnr = ta_header-matnr.

    loop at itb_bm1 where matnr = lv_matnr.

    • loop at itab_bom1 where matnr = itb_bm1-matnr.

    delete itab_bom1 where stufe = itb_bm1-stufe and wegxx = itb_bm1-wegxx.

    • read table itab_bom1 with key stufe = itb_bm1-stufe

    • wegxx = itb_bm1-wegxx

    • matnr = itb_bm1-matnr

    • bom = itb_bm1-bom

    • idnrk = itb_bm1-idnrk.

    • if sy-subrc eq 0.

    • delete itab_bom1 index lv_index.

    • endif.

    • endloop.

    endloop.

    clear: itb_bm1.

    refresh: itb_bm1.

    loop at itab_bom1.

    tp_tabix = sy-tabix.

    if itab_bom1-mtart eq 'ZRUH'.

    delete itab_bom1 index tp_tabix.

    endif.

    endloop.

    ENDFORM. " get_bom

    &----


    *& Form get_pgm

    &----


    • text

    ----


    • -->P_TA_STPO12 text

    • -->P_ITAB_BOM2_MATNR text

    • -->P_TA_HEADER_WERKS text

    • -->P_TP_STLAN text

    • -->P_TP_STLAL text

    ----


    FORM get_pgm TABLES lt_stpo12 structure bom_item_api01

    using lv_matnr like mast-matnr

    • lv_idnrk like stpox-idnrk

    pa_werks like mast-werks

    lv_stlan like mast-stlan

    lv_stlal like stko-stlal.

    data: lt_stko12 type stko_api02 occurs 0.

    data: tp_quantity like stpox-menge.

    write : lv_matnr to itab_pgm-matnr.

    • if lt_stpo12 is not initial.

    • refresh: lt_stpo12.

    • clear:lt_stpo12.

    • endif.

    call function 'CSEP_MAT_BOM_READ'

    EXPORTING

    material = lv_matnr

    plant = pa_werks

    bom_usage = lv_stlan

    alternative = lv_stlal

    TABLES

    t_stpo = lt_stpo12

    t_stko = lt_stko12

    EXCEPTIONS

    error = 1.

    • if sy-subrc ne 0.

    • message e066(zwaa001).

    • endif.

    if sy-subrc = 0.

    loop at lt_stpo12 into wa_stpo12.

    replace all occurrences of ',' in wa_stpo12-comp_qty with ''.

    move wa_stpo12-comp_qty to tp_quantity.

    select single maktx into itab_pgm-c_maktx from makt

    where matnr = wa_stpo12-component and

    spras = 'E'.

    move wa_stpo12-comp_qty to itab_pgm-mngko.

    move-corresponding wa_stpo12 to itab_pgm.

    • Added by Soh.

    select single matkl into itab_pgm-matkl

    from mara

    where matnr = itab_pgm-component.

    • Added by pradeep

    select single stprs into itab_pgm-stprs

    from mbew

    where matnr = itab_pgm-reQuantity.

    append itab_pgm.

    endloop.

    refresh: lt_stpo12.

    clear:lt_stpo12.

    endif.

    ENDFORM. " get_pgm