Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Material Consumption Report all expert requested to check my code

Hi all guru

Plz

I am creating Material Consumption Report

so all expert are requested to check my code

bcz its giving me wrong value change if nessary

&----


*& Report Z_MATERIAL_CONSUPTION

*&

&----


*&IEDK901096

*&

&----


REPORT Z_MATERIAL_CONSUPTION

  • LINE-COUNT 65(2)

LINE-SIZE 345

MESSAGE-ID zate_msg

NO STANDARD PAGE HEADING.

----


*T A B L E S

----


TABLES:MARC,

mara,

makt,

mard,

mbew,

mseg,

mkpf.

----


  • T Y P E S

----


  • Types for MARC

TYPES: begin of ty_marc,

matnr LIKE marc-matnr,

werks LIKE marc-werks,

end of ty_marc.

********Types for T001W*****

TYPES:BEGIN OF ty_t001w,

werks LIKE t001w-werks,

name1 LIKE t001w-name1,

END OF ty_t001w.

********Types for MARA*****

TYPES:BEGIN OF TY_MARA,

matnr LIKE mara-matnr,

mtart LIKE mara-mtart,

matkl LIKE mara-mtart,

END OF ty_mara.

********Types for MAKT*****

TYPES:BEGIN OF ty_makt,

matnr LIKE makt-matnr,

spras LIKE makt-spras,

maktx LIKE makt-maktx,

END OF ty_makt.

********Types for MKPF*****

TYPES:BEGIN OF ty_mkpf,

mblnr LIKE mkpf-mblnr,

budat LIKE mkpf-budat,

END OF ty_mkpf.

********Types for MSEG*****

TYPES:BEGIN OF ty_mseg,

mblnr LIKE mseg-mblnr,

mjahr LIKE mseg-mjahr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

END OF ty_mseg.

              • Types for main **************

TYPES: begin of ty_main,

matkl LIKE mara-mtart,

mtart LIKE mara-mtart,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

name1 LIKE t001w-name1,

maktx LIKE makt-maktx,

budat LIKE mkpf-budat,

mblnr LIKE mseg-mblnr,

mjahr LIKE mseg-mjahr,

menge LIKE mseg-menge,

menge1 LIKE mseg-menge,

bwart LIKE mseg-bwart,

ret_qty LIKE mseg-menge,

ret_cum LIKE mseg-menge,

unit_qty LIKE mseg-menge,

unit_cum LIKE mseg-menge,

wip_qty LIKE mseg-menge,

wip_cum LIKE mseg-menge,

sub_qty LIKE mseg-menge,

sub_cum LIKE mseg-menge,

oth_qty LIKE mseg-menge,

oth_cum LIKE mseg-menge,

end of ty_main.

              • Types for main2 **************

TYPES: begin of ty_main2,

mblnr LIKE mseg-mblnr,

werks LIKE marc-werks,

mjahr LIKE mseg-mjahr,

menge LIKE mseg-menge,

bwart LIKE mseg-bwart,

matnr LIKE mara-matnr,

mtart LIKE mara-mtart,

matkl LIKE mara-mtart,

end of ty_main2.

----


*I N T E R N A L T A B L E S

----


DATA:it_mara TYPE ty_mara OCCURS 0 WITH HEADER LINE,

it_marc TYPE ty_marc OCCURS 0 WITH HEADER LINE,

it_t001w TYPE ty_t001w OCCURS 0 WITH HEADER LINE,

it_makt TYPE ty_makt OCCURS 0 WITH HEADER LINE,

it_main TYPE ty_main OCCURS 0 WITH HEADER LINE,

it_main2 TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_mkpf TYPE ty_mkpf OCCURS 0 WITH HEADER LINE,

  • it_mseg TYPE ty_mseg OCCURS 0 WITH HEADER LINE,

it_mseg TYPE ty_main OCCURS 0 WITH HEADER LINE,

it_dept TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_unit TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_WIP TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_subcon TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_others TYPE ty_main2 OCCURS 0 WITH HEADER LINE.

**********I N T E R N A L T A B L E S for Cumulative Calculation**********

DATA:it_mseg1 TYPE ty_main OCCURS 0 WITH HEADER LINE,

it_dept1 TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_unit1 TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_WIP1 TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_subcon1 TYPE ty_main2 OCCURS 0 WITH HEADER LINE,

it_others1 TYPE ty_main2 OCCURS 0 WITH HEADER LINE.

----


  • W O R K A R E A

----


DATA:wa_mara TYPE ty_mara,

wa_marc TYPE ty_marc,

wa_t001w TYPE ty_t001w,

wa_makt TYPE ty_makt,

wa_main TYPE ty_main,

wa_main2 TYPE ty_main2,

wa_mkpf TYPE ty_mkpf,

wa_mseg TYPE ty_mseg,

wa_mseg1 TYPE ty_mseg,

wa_dept TYPE ty_main2,

wa_ret_qty TYPE ty_main2,

wa_ret_cum TYPE ty_main2.

----


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

----


DATA: MYDATE TYPE SY-DATUM,

per_qty TYPE p,

cum_qty TYPE p ,

final_total TYPE p DECIMALS 2.

----


  • S E L E C T I O N S C R E E N

----


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

PARAMETERS:Plant LIKE marc-werks DEFAULT '1023'.

select-options:Mat_Grp FOR mara-matkl,

Mat_Type FOR mara-mtart,

MATERIAL FOR MARC-MATNR,

Period FOR mydate.

PARAMETERS:Year LIKE mseg-mjahr DEFAULT '2007'.

SELECTION-SCREEN:END OF BLOCK B1.

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

  • I N I T I A L I Z A T I O N

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

INITIALIZATION.

MATERIAL-LOW = '100'.

MATERIAL-HIGH = '200'.

APPEND MATERIAL.

*MAT_TYPE-LOW = 'ABF'.

*MAT_TYPE-HIGH = 'FERT'.

*APPEND MAT_TYPE.

*

*MAT_GRP-LOW = '100'.

*MAT_GRP-HIGH = '200'.

*APPEND MAT_GRP.

*

*PERIOD-LOW = '20071001'.

*PERIOD-HIGH = '20071031'.

*APPEND PERIOD.

----


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

----


start-of-selection.

PERFORM it_mara_data.

PERFORM it_marc_data.

PERFORM it_t001w_data.

PERFORM it_makt_data.

PERFORM it_mseg_data.

PERFORM it_mseg1_data. "CUMULATIVE CALCULATION

PERFORM it_mkpf_data.

PERFORM it_dept_data.

PERFORM it_dept1_data. "CUMULATIVE CALCULATION

PERFORM it_unit_data.

PERFORM it_unit_data1. "CUMULATIVE CALCULATION

PERFORM it_wip_data.

PERFORM it_wip_data1. "CUMULATIVE CALCULATION

PERFORM it_sub_contract.

PERFORM it_sub_contract1. "CUMULATIVE CALCULATION

PERFORM it_main_data.

----


  • T O P O F P A G E

----


TOP-OF-PAGE.

WRITE: /1 'INOX AIR PRODUCTS LTD',plant,it_t001w-name1,

/1 'TOTAL CONSUMPTION FOR THE PERIODE:',Period-low,'To',period-high.

skip 2.

FORMAT COLOR 1.

ULINE.

WRITE: /1'|','CODE ' ,

15 'MATERIAL' ,

30 'DESCRIPTION',

90'CONSUMPTION' ,

135'RETURN FROM DEPT.' ,

170'INTER UNIT' ,

210'W.I.P' ,

240'SUB-CONTRACTOR' ,

275'OTHERS' ,

310'TOTAL',345'|' ,

/1'|',15 'TYPE',

85'FOR PERIOD' ,

100 ' CUMULATIVE' ,

130'FOR PERIOD' ,

145 'CUMULATIVE' ,

165'FOR PERIOD' ,

180 'CUMULATIVE' ,

200'FOR PERIOD' ,

215'CUMULATIVE' ,

235'FOR PERIOD' ,

250'CUMULATIVE' ,

265'FOR PERIOD' ,

280 'CUMULATIVE' ,

300'FOR PERIOD' ,

315' CUMULATIVE' ,

345'|' .

ULINE.

----


  • E N D O F S E L E C T I O N

----


end-OF-SELECTION.

PERFORM display_data.

FORM it_mara_data.

SELECT matnr

mtart

matkl

FROM mara INTO CORRESPONDING FIELDS OF TABLE it_mara

WHERE matnr IN material AND

mtart IN mat_type AND

matkl IN mat_grp.

ENDFORM. " it_mara_data

FORM it_marc_data .

select matnr

werks

from marc

into CORRESPONDING FIELDS OF TABLE it_marc

FOR ALL ENTRIES IN it_mara

WHERE MATNR eq it_mara-matnr AND

werks eq plant.

ENDFORM. " it_marc_data

FORM it_makt_data .

SELECT

matnr

maktx

FROM makt INTO

CORRESPONDING FIELDS OF TABLE it_makt

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr.

ENDFORM. " it_makt_data

FORM it_main_data .

*BREAK-POINT.

loop at it_mara.

wa_main-matnr = it_mara-matnr.

wa_main-mtart = it_mara-mtart.

wa_main-matkl = it_mara-matkl.

READ TABLE it_marc WITH KEY matnr = it_mara-matnr.

wa_main-werks = it_marc-werks.

READ TABLE it_t001w WITH KEY werks = it_marc-werks.

wa_main-name1 = it_t001w-name1.

READ TABLE it_makt WITH KEY matnr = it_mara-matnr.

wa_main-maktx = it_makt-maktx.

*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

READ TABLE it_mseg1 INDEX sy-tabix.

wa_main-mjahr = it_mseg1-mjahr.

wa_main-menge1 = it_mseg1-menge.

READ TABLE it_mseg WITH KEY matnr = it_mara-matnr.

  • READ TABLE it_mseg INDEX sy-tabix.

wa_main-mblnr = it_mseg-mblnr.

wa_main-menge = it_mseg-menge.

READ TABLE it_dept WITH KEY mblnr = it_mseg-mblnr.

wa_main-ret_qty = it_dept-menge.

  • READ TABLE it_dept1 WITH KEY werks = it_marc-werks.

READ TABLE it_dept1 INDEX sy-tabix.

wa_main-ret_cum = it_dept1-menge.

READ TABLE it_mkpf WITH KEY mblnr = it_mseg-mblnr.

wa_main-budat = it_mkpf-budat.

  • READ TABLE it_unit1 WITH KEY werks = it_marc-werks.

READ TABLE it_unit1 INDEX sy-tabix. "BINARY SEARCH.

wa_main-unit_cum = it_unit1-menge.

READ TABLE it_unit WITH KEY mblnr = it_mseg-mblnr.

wa_main-unit_qty = it_unit-menge.

READ TABLE it_wip WITH KEY mblnr = it_mseg-mblnr.

wa_main-wip_qty = it_wip-menge.

  • READ TABLE it_wip1 WITH KEY werks = it_marc-werks.

READ TABLE it_wip1 INDEX sy-tabix.

wa_main-wip_qty = it_wip1-menge.

READ TABLE it_subcon WITH KEY mblnr = it_mseg-mblnr.

wa_main-sub_qty = it_subcon-menge.

  • READ TABLE it_subcon1 WITH KEY werks = it_marc-werks.

READ TABLE it_subcon1 INDEX sy-tabix.

wa_main-sub_cum = it_subcon1-menge.

READ TABLE it_others WITH KEY mblnr = it_mseg-mblnr.

wa_main-oth_qty = it_others-menge.

  • READ TABLE it_others1 WITH KEY werks = it_marc-werks.

READ TABLE it_others1 INDEX sy-tabix.

wa_main-oth_cum = it_others1-menge.

APPEND wa_main to it_main.

CLEAR : wa_main,

it_mseg1,

it_main.

ENDLOOP.

  • LOOP at it_mseg1.

  • READ TABLE it_mseg INDEX sy-index.

  • MOVE-CORRESPONDING it_mseg1 to it_main.

  • append LINES OF it_mseg1 TO it_main.

  • IF sy-subrc <> 0.

  • exit.

  • ENDIF.

  • ENDLOOP.

ENDFORM. " it_main_data

FORM display_data .

SORT it_main by matkl mtart maktx.

LOOP AT it_main ."WHERE menge eq it_mseg1-menge.

at NEW matkl.

FORMAT COLOR 2 INTENSIFIED ON.

WRITE:/5 it_main-matkl." COLOR 2.

ENDAT.

at NEW mtart.

FORMAT COLOR 3 INTENSIFIED ON.

WRITE:/15 it_main-mtart." COLOR 3.

ENDAT.

at NEW maktx.

FORMAT COLOR 4 INTENSIFIED OFF.

WRITE:/ it_main-maktx UNDER 'DESCRIPTION'.

ENDAT.

FORMAT COLOR 2 INTENSIFIED ON.

WRITE:/75 it_main-menge, "it_main-maktx UNDER 'DESCRIPTION',

95 it_main-menge1,

125 it_main-ret_qty,

140 it_main-ret_cum,

160 it_main-unit_qty,

175 it_main-unit_cum,

195 it_main-wip_qty,

210 it_main-wip_cum,

225 it_main-sub_qty,

240 it_main-sub_cum,

255 it_main-oth_qty,

270 it_main-oth_cum.

FORMAT COLOR 2 INTENSIFIED OFF.

at END OF mtart.

sum.

uline.

WRITE:/30 'MAT. TYPE WISE SUB TOTAL' COLOR COL_GROUP,

60 IT_MAIN-MTART COLOR 2,

75 '*',it_main-menge,'*' COLOR 4,

95 it_main-menge1,

125 it_main-ret_qty,

140 it_main-ret_cum,

160 it_main-unit_qty,

175 it_main-unit_cum,

195 it_main-wip_qty,

210 it_main-wip_cum,

225 it_main-sub_qty,

240 it_main-sub_cum,

260 it_main-oth_qty,

270 it_main-oth_cum.

uline.

ENDAT.

at END OF matkl.

sum.

uline.

WRITE:/30 'GROUPWISE SUB TOTAL ' COLOR 5,

60 IT_MAIN-MATKL COLOR 2,

75 '*',it_main-menge,'*' COLOR 4,

95 it_main-menge1,

125 it_main-ret_qty,

140 it_main-ret_cum,

160 it_main-unit_qty,

175 it_main-unit_cum,

195 it_main-wip_qty,

210 it_main-wip_cum,

225 it_main-sub_qty,

240 it_main-sub_cum,

260 it_main-oth_qty,

270 it_main-oth_cum.

uline.

ENDAT.

at LAST.

sum.

uline.

WRITE:/30 'GROSS TOTAL' COLOR 6,

60 IT_MAIN-MATKL COLOR 2,

75 '*',it_main-menge,'*' COLOR 4,

95 it_main-menge1,

125 it_main-ret_qty,

140 it_main-ret_cum,

160 it_main-unit_qty,

175 it_main-unit_cum,

195 it_main-wip_qty,

210 it_main-wip_cum,

225 it_main-sub_qty,

240 it_main-sub_cum,

260 it_main-oth_qty,

270 it_main-oth_cum.

uline.

  • ENDAT.

per_qty = it_main-menge.

cum_qty = it_main-menge1.

final_total = per_qty + cum_qty.

  • at last.

WRITE:/95 sy-uline(30).

write:/65 'Final Cumulative Qty >>>>>>>>>',final_total color 6.

WRITE:/95 sy-uline(30).

ENDAT.

FORMAT INTENSIFIED off.

ENDLOOP.

ENDFORM. " display_data

" it_mkpf_data

FORM it_mseg_data .

SELECT

mblnr

matnr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_mseg

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr AND

werks eq plant AND

bwart eq 261." AND bwart eq 262.

CLEAR it_mseg.

ENDFORM. " it_mseg_data

FORM it_mkpf_data .

SELECT

mblnr

budat

FROM mkpf INTO CORRESPONDING FIELDS OF TABLE it_mkpf

FOR ALL ENTRIES IN it_mseg

WHERE mblnr eq it_mseg-mblnr." AND

  • budat BETWEEN Period-low AND period-high.

ENDFORM.

FORM it_t001w_data .

SELECT werks name1 FROM t001w INTO CORRESPONDING FIELDS OF TABLE it_t001w

FOR ALL ENTRIES IN it_marc

WHERE werks eq it_marc-werks.

ENDFORM. " it_t001w_data

FORM it_mseg1_data .

SELECT

mblnr

mjahr

ZEILE

matnr

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_mseg1

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr AND

werks eq plant AND

mjahr eq Year AND

bwart eq 261." AND bwart eq 262.

CLEAR it_mseg1.

ENDFORM. " it_mseg1_data

FORM it_dept_data .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_dept

FOR ALL ENTRIES IN it_mseg

WHERE mblnr eq it_mseg-mblnr AND

werks eq it_mseg-WERKS AND

bwart ge 291 AND bwart le 292.

ENDFORM.

" it_dept_data

FORM it_dept1_data .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_dept1

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr AND

werks eq plant AND

mjahr eq YEAR AND

bwart ge 291 and bwart le 292.

ENDFORM. " it_dept1_data

FORM it_unit_data .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_unit

FOR ALL ENTRIES IN it_mseg

WHERE mblnr eq it_mseg-mblnr AND

werks eq it_mseg-WERKS AND

bwart ge 301 AND bwart le 302.

ENDFORM. " it_unit_data

FORM it_unit_data1 .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_unit1

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr AND

werks eq plant AND

mjahr eq YEAR AND

bwart ge 301 AND bwart le 302.

ENDFORM. " it_unit_data1

FORM it_wip_data .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_wip

FOR ALL ENTRIES IN it_mseg

WHERE mblnr eq it_mseg-mblnr AND

werks eq it_mseg-WERKS AND

bwart ge 301 AND bwart le 302.

ENDFORM. " it_wip_data

FORM it_wip_data1 .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_wip1

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr AND

werks eq plant AND

mjahr eq YEAR AND

bwart ge 301 AND bwart le 302.

ENDFORM. " it_wip_data1

FORM it_sub_contract .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_subcon

FOR ALL ENTRIES IN it_mseg

WHERE mblnr eq it_mseg-mblnr AND

werks eq it_mseg-WERKS AND

bwart eq 541." AND bwart eq 542.

ENDFORM. " it_sub_contract

FORM it_sub_contract1 .

SELECT

mblnr

mjahr

ZEILE

werks

menge

bwart

FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_subcon1

FOR ALL ENTRIES IN it_mara

WHERE matnr eq it_mara-matnr AND

werks eq plant AND

mjahr eq YEAR AND

bwart eq 541." AND bwart eq 542.

ENDFORM. " it_sub_contract1

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question