Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

regarding performance tunnning

Former Member
0 Likes
931

hi experts,

i have developed a report but while execution it is taking some extra time ,i already checked the extended program check and the code inspector,,i made it to zero for error ,warning etc.what extra sud i do to improve the performance,plz help me ,here i m giving my codes the complete pogram......

program:::::

REPORT ZRAWPRACTICE.

*______________________________________________________________________

----


*Person:

*Program For:Mr.

*Module:MM & PP.

*Description :

*ALV GRID DISPLAY AND FORM WITH THE HELP OF SAP-SCRIPT TOOLS:

----


*_______________________________________________________________________

*type groups:

type-pools:slis.

*tables workarea:

tables:mard,t001w,mkpf,mseg,makt,T750E,t001l.

*internal table for final display:

data:begin of itab_final occurs 0,

werks like mard-werks, "for plant id

matnr like mard-matnr, "for material number

maktx like makt-maktx, "for material description

name1 like t001w-name1, "plant name

lifnr like mseg-lifnr, "vendors number

name2 like lfa1-name1, "vendors name

labst_tm like mard-labst, "target monthly

labst like mard-labst, "opening stock

labst_cl like mard-labst, "closing stock

labst_rt like mard-labst, "receive today

labst_rtld like mard-labst, "receive till date

labst_rty like mard-labst, "receive till year

labst_it like mard-labst, "issued today

labst_itld like mard-labst, "issued till date

labst_ity like mard-labst, "issued till year

bwart like mseg-bwart, "movement type

mblnr like mseg-mblnr, "material doc number

eisbe_cl like marc-eisbe , "closing balance

eisbe like marc-eisbe, "safety stock

insme like mard-insme, "Stock in quality inspection

speme like mard-speme, "Blocked stock

einme like mard-einme, "Totl Stck of All Restricted Batches

retme like mard-retme, "Blocked Stock Returns

lgort like mard-lgort, "Storage location

lgobe like t001l-lgobe, "Description of storage location

P_DATE like sy-datum, "for previous date

gptxt like t750e-gptxt, "for remarks

end of itab_final.

*internal table for mseg.:

data:begin of itab_mseg occurs 0,

mblnr like mseg-mblnr, "Number of Material Document

matnr like mseg-matnr, "Material Number

werks like mseg-werks, "Plant

lgort like mseg-lgort, "Storage location

bwart like mseg-bwart, "Movement Type

erfmg like mseg-erfmg, "Quantity in unit of entry

shkzg like mseg-shkzg, "Debit/Credit Indicator

menge like mseg-menge, "quantity

menge1 like mseg-menge, "for passing sum

mjahr like mseg-mjahr, "Material Document Year

name1 like lfa1-name1, "Name 1

lifnr like mseg-lifnr, "Vendor's account number

end of itab_mseg.

*internal table for movement type:

data:itab1 like itab_mseg occurs 0 with header line.

data:itab2 like itab_mseg occurs 0 with header line.

*internal table for mkpf:

data:begin of itab_mkpf occurs 0,

mblnr like mkpf-mblnr, "Number of Material Document

mjahr like mkpf-mjahr, "Material Document Year

budat like mkpf-budat, "Posting Date in the Document

blart like mkpf-blart, "Document type

p_date1 like sy-datum, "for psting date

end of itab_mkpf.

*internal table for rcving date:

data:begin of itab_mkpf_rcvdate occurs 0,

mblnr like mkpf-mblnr, "Number of Material Document

mjahr like mkpf-mjahr, "Material Document Year

budat like mkpf-budat, "Posting Date in the Document

blart like mkpf-blart, "Document type

P_DATE2 like sy-datum, "for previous date(rcv qty)

end of itab_mkpf_rcvdate.

*internal table for quantity received:

data:begin of itab_101 occurs 0,

matnr like mseg-matnr, "Material Number

erfmg like mseg-erfmg, "Quantity in unit of entry

mblnr like mseg-mblnr, "Number of Material Document

ebeln like mseg-ebeln, "Purchase order number

werks like mseg-werks, "Plant

erfmg_rt(13) type c, "Quantity received today

lgort like mseg-lgort, "Storage location

bwart like mseg-bwart, "Movement Type

lfbnr like mseg-lfbnr, "Doc No. of a Reference Document

smbln like mseg-smbln, "Number of Material Document

end of itab_101.

*internal table for deleting the docno.

data:itab3 like itab_101 occurs 0 with header line.

*internal table for plant name:

data:begin of itab_t001w occurs 0,

werks like t001w-werks, "plant id

name1 like t001w-name1, "plant name

end of itab_t001w.

*internal table for VENDOR name:

data:begin of itab_lfa1 occurs 0,

lifnr like lfa1-lifnr, "vendor number

name1 like lfa1-name1, "vendor name

end of itab_lfa1.

*internal table for Opening stock:

data:begin of itab_mard occurs 0,

matnr like mard-matnr, "material number

labst like mard-labst, "opening stock

werks like mard-werks, "plant id

end of itab_mard.

*internal table for material description:

data:begin of itab_makt occurs 0,

matnr like makt-matnr, "material number

maktx like makt-maktx, "material description

end of itab_makt.

*internal table for safety stock:

data:begin of itab_marc occurs 0,

matnr like marc-matnr, "materail number

werks like marc-werks, "plant id

eisbe like marc-eisbe, "safety stock

end of itab_marc.

*internal table for mkpf and mseg inner join

data:begin of itab_mkpf_mseg occurs 0,

mblnr like mkpf-mblnr,

mjahr like mkpf-mjahr,

budat like mkpf-budat,

blart like mkpf-blart,

matnr like mseg-matnr,

werks like mseg-werks,

lgort like mseg-lgort,

bwart like mseg-bwart,

erfmg like mseg-erfmg,

shkzg like mseg-shkzg,

menge like mseg-menge,

menge1 like mseg-menge,

end of itab_mkpf_mseg.

*internal table for mkpf for current date:

data:itab_mkpf1 like itab_mkpf_mseg occurs 0 with header line.

*internal table for collection

DATA: BEGIN OF WEG_MAT OCCURS 100,

WERKS LIKE MSEG-WERKS,

LGORT LIKE MSEG-LGORT,

MATNR LIKE MSEG-MATNR,

SHKZG LIKE MSEG-SHKZG,

MENGE(09) TYPE P DECIMALS 3,

END OF WEG_MAT.

*for closing stock & opening stock

DATA: BEGIN OF BESTAND OCCURS 100,

BWKEY LIKE MBEW-BWKEY,

WERKS LIKE MSEG-WERKS,

lgort like mseg-lgort,

MATNR LIKE MSEG-MATNR,

CHARG LIKE MSEG-CHARG,

ENDMENGE(09) TYPE P DECIMALS 3,

ANFMENGE(09) TYPE P DECIMALS 3,

MEINS LIKE MARA-MEINS,

SOLL(09) TYPE P DECIMALS 3,

HABEN(09) TYPE P DECIMALS 3,

WAERS LIKE T001-WAERS,

END OF BESTAND.

*for current date movement type

DATA: BEGIN OF SUM_MAT OCCURS 100,

lgort like mseg-lgort,

WERKS LIKE MSEG-WERKS,

MATNR LIKE MSEG-MATNR,

SHKZG LIKE MSEG-SHKZG,

MENGE(09) TYPE P DECIMALS 3, "XJD

END OF SUM_MAT.

*for sotrage location description

data:begin of itab_t001l occurs 0,

lgort like t001l-lgort,

lgobe like t001l-lgobe,

end of itab_t001l.

*WORK AREAS DEFINED FOR ALV'S:

DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "field catalog

IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "field catalog ITAB

WA_SORT TYPE SLIS_SORTINFO_ALV, "SORT work area

IT_SORT TYPE SLIS_T_SORTINFO_ALV, "SORT ITAB

LAYOUT TYPE SLIS_LAYOUT_ALV, "LAYOUT

WA_FCODE TYPE SLIS_EXTAB, "FUN CODE

I_FCODE_EXTAB TYPE SLIS_T_EXTAB,

WA_EVENTS TYPE SLIS_ALV_EVENT,

IT_EVENTS TYPE SLIS_T_EVENT.

*for selection screen:

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

PARAMETERS: s_werks like mseg-werks obligatory,

s_date like mkpf-budat obligatory.

select-options:matnr for mard-matnr no intervals obligatory.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME title text-002.

PARAMETERS: LIST RADIOBUTTON GROUP G1,

FORM RADIOBUTTON GROUP G1.

SELECTION-SCREEN END OF BLOCK B2.

*for start of selection event:

start-of-selection.

perform get_data.

perform get_mkpf_data.

perform get_mseg_data.

perform get_opening_stock.

perform alv_display. ""for opening and closing stcok

perform get_mseg_cancellation.

perform get_mseg_recvtoday_quantity .

perform get_refresh_alltable.

perform get_mseg_recvtilldate_quantity .

perform get_mseg_recvtillyear_quantity .

perform get_refresh_alltable.

perform get_mseg_issuedtoday_quantity .

perform get_mseg_issdtilldate_quantity .

perform get_mseg_issdtillyear_quantity .

perform refresh_mseg_mkpf.

perform define_fieldcatalog.

*perform sort_field.

perform check_options.

&----


*& Form define_fieldcatalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM define_fieldcatalog .

WA_FIELDCAT-COL_POS = 1.

WA_FIELDCAT-FIELDNAME = 'WERKS'.

WA_FIELDCAT-SELTEXT_L = 'Plant id'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 2.

WA_FIELDCAT-FIELDNAME = 'NAME1'.

WA_FIELDCAT-SELTEXT_L = 'Plant name'.

WA_FIELDCAT-OUTPUTLEN = 30.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 3.

WA_FIELDCAT-FIELDNAME = 'MAKTX'.

WA_FIELDCAT-SELTEXT_L = 'Material Description'.

WA_FIELDCAT-OUTPUTLEN = 40.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 4.

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-SELTEXT_L = 'Material Number'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

  • WA_FIELDCAT-COL_POS = 5.

  • WA_FIELDCAT-FIELDNAME = 'MBLNR'.

  • WA_FIELDCAT-SELTEXT_L = 'Material Doc.No.'.

  • WA_FIELDCAT-OUTPUTLEN = 15.

  • WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

  • APPEND WA_FIELDCAT TO IT_FIELDCAT.

  • CLEAR WA_FIELDCAT.

*

WA_FIELDCAT-COL_POS = 5.

WA_FIELDCAT-FIELDNAME = 'LGORT'.

WA_FIELDCAT-SELTEXT_L = 'Storage Location'.

WA_FIELDCAT-OUTPUTLEN = 17.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

*

WA_FIELDCAT-COL_POS = 6.

WA_FIELDCAT-FIELDNAME = 'LGOBE'.

WA_FIELDCAT-SELTEXT_L = 'Storage Location Descriptions'.

WA_FIELDCAT-OUTPUTLEN = 28.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 7.

WA_FIELDCAT-FIELDNAME = 'NAME2'.

WA_FIELDCAT-SELTEXT_L = 'Source/Vendor'.

WA_FIELDCAT-OUTPUTLEN = 33.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 8.

WA_FIELDCAT-FIELDNAME = 'LABST_TM'.

WA_FIELDCAT-SELTEXT_L = 'Target Monthly'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 9.

WA_FIELDCAT-FIELDNAME = 'LABST'.

WA_FIELDCAT-SELTEXT_L = 'Opening Stock'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 10.

WA_FIELDCAT-FIELDNAME = 'LABST_RT'.

WA_FIELDCAT-SELTEXT_L = 'Receive today'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 11.

WA_FIELDCAT-FIELDNAME = 'LABST_RTLD'.

WA_FIELDCAT-SELTEXT_L = 'Receive till date'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 12.

WA_FIELDCAT-FIELDNAME = 'LABST_RTY'.

WA_FIELDCAT-SELTEXT_L = 'Receive till year'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 13.

WA_FIELDCAT-FIELDNAME = 'LABST_IT'.

WA_FIELDCAT-SELTEXT_L = 'Issued today'.

WA_FIELDCAT-OUTPUTLEN = 13.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 14.

WA_FIELDCAT-FIELDNAME = 'LABST_ITLD'.

WA_FIELDCAT-SELTEXT_L = 'Issued till date'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 15.

WA_FIELDCAT-FIELDNAME = 'LABST_ITY'.

WA_FIELDCAT-SELTEXT_L = 'Issued till year'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 16.

WA_FIELDCAT-FIELDNAME = 'EISBE_CL'.

WA_FIELDCAT-SELTEXT_L = 'Closing Balance'.

WA_FIELDCAT-OUTPUTLEN = 16.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 17.

WA_FIELDCAT-FIELDNAME = 'LABST_CL'.

WA_FIELDCAT-SELTEXT_L = 'Closing Stock'.

WA_FIELDCAT-OUTPUTLEN = 16.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 18.

WA_FIELDCAT-FIELDNAME = 'EISBE'.

WA_FIELDCAT-SELTEXT_L = 'Safety stock'.

WA_FIELDCAT-OUTPUTLEN = 14.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 19.

WA_FIELDCAT-FIELDNAME = 'GPTXT'.

WA_FIELDCAT-SELTEXT_L = 'Remarks'.

WA_FIELDCAT-OUTPUTLEN = 100.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-INPUT = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

ENDFORM. " define_fieldcatalog

&----


*& Form check_options

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_options .

WA_EVENTS-NAME = 'TOP_OF_PAGE'.

WA_EVENTS-FORM = 'TOP'.

APPEND WA_EVENTS TO IT_EVENTS.

CLEAR WA_EVENTS.

WA_EVENTS-NAME = 'END_OF_LIST'.

WA_EVENTS-FORM = 'END_LIST'.

APPEND WA_EVENTS TO IT_EVENTS.

CLEAR WA_EVENTS.

IF LIST = 'X'.

PERFORM LIST_DISP.

ENDIF.

IF FORM = 'X'.

PERFORM FORM_DISP.

ENDIF.

ENDFORM. " check_options

&----


*& Form LIST_DISP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM LIST_DISP .

PERFORM DEFINE_LAYOUT.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = IT_FIELDCAT

IS_LAYOUT = LAYOUT

IT_SORT = IT_SORT

  • I_CALLBACK_PF_STATUS_SET = 'STATUS'

  • IT_EXCLUDING = I_FCODE_EXTAB

  • I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IT_EVENTS = IT_EVENTS[]

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = itab_final

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " LIST_DISP

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

*for different types of stock with material number.

select mard~matnr

mard~werks

mard~lgort

mard~labst

mard~insme

mard~speme

mard~einme

mard~retme

mseg~lifnr into corresponding

fields of table itab_final from mard inner join mseg on

mard~matnr =

msegmatnr where mardmatnr in matnr and mard~werks = s_werks.

*for vendor name:

select lifnr

name1

from lfa1 into corresponding fields of table

itab_lfa1 for all entries in itab_final where lifnr =

itab_final-lifnr.

*for plant name:

select werks

name1 from t001w into corresponding fields of table

itab_t001w for all entries in itab_final where werks =

itab_final-werks.

*for opening stock:

select werks

matnr

labst from mard into corresponding fields of table

itab_mard for all entries in itab_final where matnr = itab_final-matnr.

*for material description:

select matnr

maktx from makt into corresponding fields of table

itab_makt for all entries in itab_final where matnr = itab_final-matnr.

*for safety stock:

select matnr

werks

eisbe from marc into corresponding fields of table

itab_marc for all entries in itab_final where matnr = itab_final-matnr.

*for storage location description

select lgort

lgobe from t001l into corresponding fields of table

itab_t001l for all entries in itab_final where lgort = itab_final-lgort

.

sort itab_final by matnr lgort.

loop at itab_final.

read table itab_t001w with key werks = itab_final-werks.

if sy-subrc = 0.

itab_final-name1 = itab_t001w-name1.

endif.

read table itab_lfa1 with key lifnr = itab_final-lifnr.

if sy-subrc = 0.

itab_final-name2 = itab_lfa1-name1.

endif.

read table itab_makt with key matnr = itab_final-matnr.

if sy-subrc = 0.

itab_final-maktx = itab_makt-maktx.

endif.

read table itab_marc with key matnr = itab_final-matnr

werks = itab_final-werks.

if sy-subrc = 0.

itab_final-eisbe = itab_marc-eisbe.

endif.

read table itab_t001l with key lgort = itab_final-lgort.

if sy-subrc = 0.

itab_final-lgobe = itab_t001l-lgobe.

endif.

itab_final-labst = itab_final-labst + itab_final-insme +

itab_final-speme.

modify itab_final.

delete adjacent duplicates from itab_final comparing matnr lgort.

endloop.

*loop and case for the quantity of the field " target monthly.

loop at itab_final.

case itab_final-matnr.

when '000000001000000008'.

itab_final-labst_tm = '3000.000'.

when '000000001000000007'.

itab_final-labst_tm = '500.000'.

when '000000001000000006'.

itab_final-labst_tm = '400.000'.

when '000000001000000005'.

itab_final-labst_tm = '3000.000'.

when '000000003000000011'.

itab_final-labst_tm = '18000.000'.

when '000000001000000000'.

itab_final-labst_tm = '20000.000'.

when '000000001000000001'.

itab_final-labst_tm = '20000.000'.

endcase.

modify itab_final.

endloop.

ENDFORM. " get_data

form top.

clear itab_final-p_date.

WRITE:/ SY-ULINE.

WRITE:/ 'REPORT DATE:', SY-DATUM, 60 'VISA STEEL LTD.' color 5,

100'Report Developed By Ravi kumar Gupta.' .

WRITE:/ 'TIME:', SY-UZEIT.

*for previous date

clear itab_final-p_date.

itab_final-p_date = S_date - 1.

WRITE:/ 'USER NAME:', SY-UNAME,55'STOCK REPORT FOR:',73

ITAB_FINAL-P_DATE,100'Application:MM & PP.'.

WRITE:/ 'PAGE', SY-PAGNO.

  • write:/ 'Unit of Measure =','MT.'.

translate itab_final-name1 to upper case.

WRITE:/54 itab_final-name1 color 6.

WRITE:/ SY-ULINE.

skip 1.

endform.

form end_list.

skip 1.

write:/ sy-uline.

write:/ 'Cc:S.B.Singh Executive Director.'.

write:/04'K.M.Lal Executive Director Raw Material.'.

write:/04'A.K.Lamba President Project.'.

write:/04'A.K.Agarwal VP Commercial.'.

write:/04'Murli Dhar Manager Blast Furnace.'.

write:/04'S.N.Sarangi DGM Commercial.'.

WRITE:/ SY-ULINE. .

SKIP 2.

WRITE:/60 'END OF PAGE'.

endform.

&----


*& Form FORM_DISP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FORM_DISP .

ENDFORM. " FORM_DISP

&----


*& Form DEFINE_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DEFINE_LAYOUT .

LAYOUT-ZEBRA = 'X'.

  • LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL SUM'.

LAYOUT-WINDOW_TITLEBAR = 'STOCK REPORT'.

LAYOUT-TOTALS_TEXT = 'TOTAL'.

ENDFORM. " DEFINE_LAYOUT

&----


*& Form get_mkpf_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mkpf_data .

itab_mkpf-p_date1 = s_date.

itab_mkpf-p_date1+6 = '01'.

**for the current date

select mkpf~mblnr

mkpf~budat

mseg~matnr

mseg~werks

mseg~lgort

mseg~bwart

mseg~shkzg

mseg~menge into corresponding fields of

table itab_mkpf1 from mkpf inner join mseg on mkpf~mblnr =

mseg~mblnr where

budat eq itab_mkpf-p_date1

.

*for the whole year

select mkpf~mblnr

mkpf~mjahr

mkpf~budat

mkpf~blart

mseg~matnr

mseg~werks

mseg~lgort

mseg~bwart

mseg~erfmg

mseg~shkzg

mseg~menge into corresponding fields of

table itab_mkpf_mseg from mkpf inner join mseg on mkpf~mblnr =

mseg~mblnr where

budat gt itab_mkpf-p_date1

and budat le sy-datum.

ENDFORM. " get_mkpf_data

&----


*& Form get_mseg_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_data .

sort itab_mkpf_mseg by werks lgort matnr .

*for the deletion of material from mseg.

sort itab_mkpf_mseg by matnr lgort.

loop at itab_mkpf_mseg.

read table itab_final with key matnr = itab_mkpf_mseg-matnr.

if sy-subrc eq 4.

delete itab_mkpf_mseg.

endif.

endloop.

*for material deletion of itab_mkpf1

loop at itab_mkpf1.

read table itab_mkpf_mseg with key matnr = itab_mkpf1-matnr.

if sy-subrc eq 4.

delete itab_mkpf1.

endif.

endloop.

sort itab_mkpf_mseg by matnr werks lgort shkzg.

delete itab_mkpf_mseg where lgort is initial.

*for closing stock i.e,all mvmnt type summation

loop at itab_final.

loop at itab_mkpf_mseg.

IF itab_final-werks = itab_mkpf_mseg-werks AND

itab_final-lgort = itab_mkpf_mseg-lgort and

itab_final-matnr = itab_mkpf_mseg-matnr.

MOVE-CORRESPONDING itab_mkpf_mseg TO weg_mat.

COLLECT weg_mat.

ENDIF.

ENDLOOP.

ENDLOOP.

*for current date movement type

loop at itab_final.

loop at itab_mkpf1.

IF itab_final-werks = itab_mkpf1-werks AND

itab_final-lgort = itab_mkpf1-lgort and

itab_final-matnr = itab_mkpf1-matnr.

MOVE-CORRESPONDING itab_mkpf1 TO sum_mat.

COLLECT sum_mat.

ENDIF.

ENDLOOP.

ENDLOOP.

*for closing stock

loop at itab_final.

CLEAR weg_mat-menge.

MOVE-CORRESPONDING itab_final TO bestand.

READ TABLE weg_mat WITH KEY werks = itab_final-werks

lgort = itab_final-lgort

matnr = itab_final-matnr

shkzg = 'S'.

bestand-endmenge = itab_final-labst + itab_final-insme +

itab_final-speme + itab_final-einme +

itab_final-retme - weg_mat-menge.

CLEAR weg_mat-menge.

READ TABLE weg_mat WITH KEY werks = itab_final-werks

lgort = itab_final-lgort

matnr = itab_final-matnr

shkzg = 'H'.

bestand-endmenge = bestand-endmenge + weg_mat-menge. "closing stock

COLLECT bestand.

endloop.

ENDFORM. " get_mseg_data

&----


*& Form refresh_mseg_mkpf

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM refresh_mseg_mkpf .

REFRESH itab_mkpf.

REFRESH itab_mseg.

REFRESH itab1.

REFRESH itab2.

ENDFORM. " refresh_mseg_mkpf

&----


*& Form get_mseg_cancellation

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_cancellation .

itab_mkpf_rcvdate-p_date2 = s_date - 1.

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat eq itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

if not itab_mkpf_rcvdate[] is initial.

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('101','531') and werks = s_werks.

endif.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified into corresponding fields of

table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart in ('102','532') and mandt = sy-mandt .

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

ENDFORM. " get_mseg_cancellation

&----


*& Form get_mseg_recvtoday_quantity .

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_recvtoday_quantity .

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_rt = itab_101-erfmg_rt .

endat.

endif.

endloop.

modify itab_final.

endloop.

clear itab_final-labst_rt.

ENDFORM. " get_mseg_recvtoday_quantity .

&----


*& Form get_mseg_recvtilldate_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_recvtilldate_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat between itab_mkpf-p_date1 and itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('101','531') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart in ('102','532') and mandt = sy-mandt

.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_rtld = itab_101-erfmg_rt.

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_recvtilldate_quantity

&----


*& Form get_refresh_alltable

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_refresh_alltable .

refresh itab_mkpf_rcvdate.

refresh itab_101.

refresh itab3.

refresh itab_mkpf.

ENDFORM. " get_refresh_alltable

&----


*& Form get_mseg_recvtillyear_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_recvtillyear_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat le itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('101','531') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart in ('102','532') and mandt = sy-mandt

.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_rty = itab_101-erfmg_rt.

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_recvtillyear_quantity

&----


*& Form get_mseg_issuedtoday_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_issuedtoday_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat eq itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

if not itab_mkpf_rcvdate[] is initial.

select

matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg

into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('261') and werks = s_werks.

endif.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart = 262 and mandt = sy-mandt.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_it = itab_101-erfmg_rt.

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_issuedtoday_quantity

&----


*& Form get_mseg_issdtilldate_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_issdtilldate_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat between itab_mkpf-p_date1 and itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('261') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart = 262 and mandt = sy-mandt.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_itld = itab_101-erfmg_rt.

endat.

endif.

endloop.

itab_final-eisbe_cl = itab_final-labst + itab_final-labst_rtld

- itab_final-labst_itld.

modify itab_final.

endloop.

ENDFORM. " get_mseg_issdtilldate_quantity

&----


*& Form get_mseg_issdtillyear_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_issdtillyear_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat le itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('261') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart = 262 and mandt = sy-mandt.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_ity = itab_101-erfmg_rt .

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_issdtillyear_quantity

&----


*& Form for_closing_balance

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM for_closing_balance .

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

itab_final-eisbe_cl = itab_final-labst + itab_final-labst_rtld

- itab_final-labst_itld.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " for_closing_balance

&----


*& Form sort_field

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sort_field .

WA_SORT-FIELDNAME = 'MATNR'.

WA_SORT-TABNAME = 'ITAB_FINAL'.

WA_SORT-SPOS = 1.

WA_SORT-UP = 'X'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

  • WA_SORT-FIELDNAME = 'LABST1'.

  • WA_SORT-TABNAME = 'ITAB_FINAL'.

  • WA_SORT-UP = 'X'.

  • WA_SORT-SPOS = 2.

  • WA_SORT-SUBTOT = 'X'.

  • APPEND WA_SORT TO IT_SORT.

  • CLEAR WA_SORT.

*

ENDFORM. " sort_field

&----


*& Form get_opening_stock

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_opening_stock .

LOOP AT bestand.

CLEAR sum_mat-menge.

READ TABLE sum_mat WITH KEY werks = bestand-werks

matnr = bestand-matnr

lgort = bestand-lgort

shkzg = 'S'.

MOVE sum_mat-menge TO bestand-soll.

CLEAR sum_mat-menge.

READ TABLE sum_mat WITH KEY werks = bestand-werks

matnr = bestand-matnr

lgort = bestand-lgort

shkzg = 'H'.

MOVE sum_mat-menge TO bestand-haben.

bestand-anfmenge = bestand-endmenge - bestand-soll

+ bestand-haben.

MODIFY bestand.

ENDLOOP.

ENDFORM. " get_opening_stock

&----


*& Form alv_display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM alv_display . "for opening and closing stcok

loop at itab_final.

loop at bestand.

IF itab_final-werks = bestand-werks AND

itab_final-lgort = bestand-lgort and

itab_final-matnr = bestand-matnr.

if sy-subrc = 0.

itab_final-labst = bestand-anfmenge.

itab_final-labst_cl = bestand-endmenge.

endif.

endif.

modify itab_final.

endloop.

endloop.

ENDFORM. " alv_display

Message was edited by:

ravi gupta

hi experts,

i have developed a report but while execution it is taking some extra time ,i already checked the extended program check and the code inspector,,i made it to zero for error ,warning etc.what extra sud i do to improve the performance,plz help me ,here i m giving my codes the complete pogram......

program:::::

REPORT ZRAWPRACTICE.

*______________________________________________________________________

----


*Person:

*Program For:Mr.

*Module:MM & PP.

*Description :

*ALV GRID DISPLAY AND FORM WITH THE HELP OF SAP-SCRIPT TOOLS:

----


*_______________________________________________________________________

*type groups:

type-pools:slis.

*tables workarea:

tables:mard,t001w,mkpf,mseg,makt,T750E,t001l.

*internal table for final display:

data:begin of itab_final occurs 0,

werks like mard-werks, "for plant id

matnr like mard-matnr, "for material number

maktx like makt-maktx, "for material description

name1 like t001w-name1, "plant name

lifnr like mseg-lifnr, "vendors number

name2 like lfa1-name1, "vendors name

labst_tm like mard-labst, "target monthly

labst like mard-labst, "opening stock

labst_cl like mard-labst, "closing stock

labst_rt like mard-labst, "receive today

labst_rtld like mard-labst, "receive till date

labst_rty like mard-labst, "receive till year

labst_it like mard-labst, "issued today

labst_itld like mard-labst, "issued till date

labst_ity like mard-labst, "issued till year

bwart like mseg-bwart, "movement type

mblnr like mseg-mblnr, "material doc number

eisbe_cl like marc-eisbe , "closing balance

eisbe like marc-eisbe, "safety stock

insme like mard-insme, "Stock in quality inspection

speme like mard-speme, "Blocked stock

einme like mard-einme, "Totl Stck of All Restricted Batches

retme like mard-retme, "Blocked Stock Returns

lgort like mard-lgort, "Storage location

lgobe like t001l-lgobe, "Description of storage location

P_DATE like sy-datum, "for previous date

gptxt like t750e-gptxt, "for remarks

end of itab_final.

*internal table for mseg.:

data:begin of itab_mseg occurs 0,

mblnr like mseg-mblnr, "Number of Material Document

matnr like mseg-matnr, "Material Number

werks like mseg-werks, "Plant

lgort like mseg-lgort, "Storage location

bwart like mseg-bwart, "Movement Type

erfmg like mseg-erfmg, "Quantity in unit of entry

shkzg like mseg-shkzg, "Debit/Credit Indicator

menge like mseg-menge, "quantity

menge1 like mseg-menge, "for passing sum

mjahr like mseg-mjahr, "Material Document Year

name1 like lfa1-name1, "Name 1

lifnr like mseg-lifnr, "Vendor's account number

end of itab_mseg.

*internal table for movement type:

data:itab1 like itab_mseg occurs 0 with header line.

data:itab2 like itab_mseg occurs 0 with header line.

*internal table for mkpf:

data:begin of itab_mkpf occurs 0,

mblnr like mkpf-mblnr, "Number of Material Document

mjahr like mkpf-mjahr, "Material Document Year

budat like mkpf-budat, "Posting Date in the Document

blart like mkpf-blart, "Document type

p_date1 like sy-datum, "for psting date

end of itab_mkpf.

*internal table for rcving date:

data:begin of itab_mkpf_rcvdate occurs 0,

mblnr like mkpf-mblnr, "Number of Material Document

mjahr like mkpf-mjahr, "Material Document Year

budat like mkpf-budat, "Posting Date in the Document

blart like mkpf-blart, "Document type

P_DATE2 like sy-datum, "for previous date(rcv qty)

end of itab_mkpf_rcvdate.

*internal table for quantity received:

data:begin of itab_101 occurs 0,

matnr like mseg-matnr, "Material Number

erfmg like mseg-erfmg, "Quantity in unit of entry

mblnr like mseg-mblnr, "Number of Material Document

ebeln like mseg-ebeln, "Purchase order number

werks like mseg-werks, "Plant

erfmg_rt(13) type c, "Quantity received today

lgort like mseg-lgort, "Storage location

bwart like mseg-bwart, "Movement Type

lfbnr like mseg-lfbnr, "Doc No. of a Reference Document

smbln like mseg-smbln, "Number of Material Document

end of itab_101.

*internal table for deleting the docno.

data:itab3 like itab_101 occurs 0 with header line.

*internal table for plant name:

data:begin of itab_t001w occurs 0,

werks like t001w-werks, "plant id

name1 like t001w-name1, "plant name

end of itab_t001w.

*internal table for VENDOR name:

data:begin of itab_lfa1 occurs 0,

lifnr like lfa1-lifnr, "vendor number

name1 like lfa1-name1, "vendor name

end of itab_lfa1.

*internal table for Opening stock:

data:begin of itab_mard occurs 0,

matnr like mard-matnr, "material number

labst like mard-labst, "opening stock

werks like mard-werks, "plant id

end of itab_mard.

*internal table for material description:

data:begin of itab_makt occurs 0,

matnr like makt-matnr, "material number

maktx like makt-maktx, "material description

end of itab_makt.

*internal table for safety stock:

data:begin of itab_marc occurs 0,

matnr like marc-matnr, "materail number

werks like marc-werks, "plant id

eisbe like marc-eisbe, "safety stock

end of itab_marc.

*internal table for mkpf and mseg inner join

data:begin of itab_mkpf_mseg occurs 0,

mblnr like mkpf-mblnr,

mjahr like mkpf-mjahr,

budat like mkpf-budat,

blart like mkpf-blart,

matnr like mseg-matnr,

werks like mseg-werks,

lgort like mseg-lgort,

bwart like mseg-bwart,

erfmg like mseg-erfmg,

shkzg like mseg-shkzg,

menge like mseg-menge,

menge1 like mseg-menge,

end of itab_mkpf_mseg.

*internal table for mkpf for current date:

data:itab_mkpf1 like itab_mkpf_mseg occurs 0 with header line.

*internal table for collection

DATA: BEGIN OF WEG_MAT OCCURS 100,

WERKS LIKE MSEG-WERKS,

LGORT LIKE MSEG-LGORT,

MATNR LIKE MSEG-MATNR,

SHKZG LIKE MSEG-SHKZG,

MENGE(09) TYPE P DECIMALS 3,

END OF WEG_MAT.

*for closing stock & opening stock

DATA: BEGIN OF BESTAND OCCURS 100,

BWKEY LIKE MBEW-BWKEY,

WERKS LIKE MSEG-WERKS,

lgort like mseg-lgort,

MATNR LIKE MSEG-MATNR,

CHARG LIKE MSEG-CHARG,

ENDMENGE(09) TYPE P DECIMALS 3,

ANFMENGE(09) TYPE P DECIMALS 3,

MEINS LIKE MARA-MEINS,

SOLL(09) TYPE P DECIMALS 3,

HABEN(09) TYPE P DECIMALS 3,

WAERS LIKE T001-WAERS,

END OF BESTAND.

*for current date movement type

DATA: BEGIN OF SUM_MAT OCCURS 100,

lgort like mseg-lgort,

WERKS LIKE MSEG-WERKS,

MATNR LIKE MSEG-MATNR,

SHKZG LIKE MSEG-SHKZG,

MENGE(09) TYPE P DECIMALS 3, "XJD

END OF SUM_MAT.

*for sotrage location description

data:begin of itab_t001l occurs 0,

lgort like t001l-lgort,

lgobe like t001l-lgobe,

end of itab_t001l.

*WORK AREAS DEFINED FOR ALV'S:

DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "field catalog

IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "field catalog ITAB

WA_SORT TYPE SLIS_SORTINFO_ALV, "SORT work area

IT_SORT TYPE SLIS_T_SORTINFO_ALV, "SORT ITAB

LAYOUT TYPE SLIS_LAYOUT_ALV, "LAYOUT

WA_FCODE TYPE SLIS_EXTAB, "FUN CODE

I_FCODE_EXTAB TYPE SLIS_T_EXTAB,

WA_EVENTS TYPE SLIS_ALV_EVENT,

IT_EVENTS TYPE SLIS_T_EVENT.

*for selection screen:

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

PARAMETERS: s_werks like mseg-werks obligatory,

s_date like mkpf-budat obligatory.

select-options:matnr for mard-matnr no intervals obligatory.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME title text-002.

PARAMETERS: LIST RADIOBUTTON GROUP G1,

FORM RADIOBUTTON GROUP G1.

SELECTION-SCREEN END OF BLOCK B2.

*for start of selection event:

start-of-selection.

perform get_data.

perform get_mkpf_data.

perform get_mseg_data.

perform get_opening_stock.

perform alv_display. ""for opening and closing stcok

perform get_mseg_cancellation.

perform get_mseg_recvtoday_quantity .

perform get_refresh_alltable.

perform get_mseg_recvtilldate_quantity .

perform get_mseg_recvtillyear_quantity .

perform get_refresh_alltable.

perform get_mseg_issuedtoday_quantity .

perform get_mseg_issdtilldate_quantity .

perform get_mseg_issdtillyear_quantity .

perform refresh_mseg_mkpf.

perform define_fieldcatalog.

*perform sort_field.

perform check_options.

&----


*& Form define_fieldcatalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM define_fieldcatalog .

WA_FIELDCAT-COL_POS = 1.

WA_FIELDCAT-FIELDNAME = 'WERKS'.

WA_FIELDCAT-SELTEXT_L = 'Plant id'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 2.

WA_FIELDCAT-FIELDNAME = 'NAME1'.

WA_FIELDCAT-SELTEXT_L = 'Plant name'.

WA_FIELDCAT-OUTPUTLEN = 30.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 3.

WA_FIELDCAT-FIELDNAME = 'MAKTX'.

WA_FIELDCAT-SELTEXT_L = 'Material Description'.

WA_FIELDCAT-OUTPUTLEN = 40.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 4.

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-SELTEXT_L = 'Material Number'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

  • WA_FIELDCAT-COL_POS = 5.

  • WA_FIELDCAT-FIELDNAME = 'MBLNR'.

  • WA_FIELDCAT-SELTEXT_L = 'Material Doc.No.'.

  • WA_FIELDCAT-OUTPUTLEN = 15.

  • WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

  • APPEND WA_FIELDCAT TO IT_FIELDCAT.

  • CLEAR WA_FIELDCAT.

*

WA_FIELDCAT-COL_POS = 5.

WA_FIELDCAT-FIELDNAME = 'LGORT'.

WA_FIELDCAT-SELTEXT_L = 'Storage Location'.

WA_FIELDCAT-OUTPUTLEN = 17.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

*

WA_FIELDCAT-COL_POS = 6.

WA_FIELDCAT-FIELDNAME = 'LGOBE'.

WA_FIELDCAT-SELTEXT_L = 'Storage Location Descriptions'.

WA_FIELDCAT-OUTPUTLEN = 28.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 7.

WA_FIELDCAT-FIELDNAME = 'NAME2'.

WA_FIELDCAT-SELTEXT_L = 'Source/Vendor'.

WA_FIELDCAT-OUTPUTLEN = 33.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 8.

WA_FIELDCAT-FIELDNAME = 'LABST_TM'.

WA_FIELDCAT-SELTEXT_L = 'Target Monthly'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 9.

WA_FIELDCAT-FIELDNAME = 'LABST'.

WA_FIELDCAT-SELTEXT_L = 'Opening Stock'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 10.

WA_FIELDCAT-FIELDNAME = 'LABST_RT'.

WA_FIELDCAT-SELTEXT_L = 'Receive today'.

WA_FIELDCAT-OUTPUTLEN = 15.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 11.

WA_FIELDCAT-FIELDNAME = 'LABST_RTLD'.

WA_FIELDCAT-SELTEXT_L = 'Receive till date'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 12.

WA_FIELDCAT-FIELDNAME = 'LABST_RTY'.

WA_FIELDCAT-SELTEXT_L = 'Receive till year'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 13.

WA_FIELDCAT-FIELDNAME = 'LABST_IT'.

WA_FIELDCAT-SELTEXT_L = 'Issued today'.

WA_FIELDCAT-OUTPUTLEN = 13.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 14.

WA_FIELDCAT-FIELDNAME = 'LABST_ITLD'.

WA_FIELDCAT-SELTEXT_L = 'Issued till date'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 15.

WA_FIELDCAT-FIELDNAME = 'LABST_ITY'.

WA_FIELDCAT-SELTEXT_L = 'Issued till year'.

WA_FIELDCAT-OUTPUTLEN = 20.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 16.

WA_FIELDCAT-FIELDNAME = 'EISBE_CL'.

WA_FIELDCAT-SELTEXT_L = 'Closing Balance'.

WA_FIELDCAT-OUTPUTLEN = 16.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 17.

WA_FIELDCAT-FIELDNAME = 'LABST_CL'.

WA_FIELDCAT-SELTEXT_L = 'Closing Stock'.

WA_FIELDCAT-OUTPUTLEN = 16.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 18.

WA_FIELDCAT-FIELDNAME = 'EISBE'.

WA_FIELDCAT-SELTEXT_L = 'Safety stock'.

WA_FIELDCAT-OUTPUTLEN = 14.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = 19.

WA_FIELDCAT-FIELDNAME = 'GPTXT'.

WA_FIELDCAT-SELTEXT_L = 'Remarks'.

WA_FIELDCAT-OUTPUTLEN = 100.

WA_FIELDCAT-TABNAME = 'ITAB_FINAL'.

WA_FIELDCAT-INPUT = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

ENDFORM. " define_fieldcatalog

&----


*& Form check_options

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_options .

WA_EVENTS-NAME = 'TOP_OF_PAGE'.

WA_EVENTS-FORM = 'TOP'.

APPEND WA_EVENTS TO IT_EVENTS.

CLEAR WA_EVENTS.

WA_EVENTS-NAME = 'END_OF_LIST'.

WA_EVENTS-FORM = 'END_LIST'.

APPEND WA_EVENTS TO IT_EVENTS.

CLEAR WA_EVENTS.

IF LIST = 'X'.

PERFORM LIST_DISP.

ENDIF.

IF FORM = 'X'.

PERFORM FORM_DISP.

ENDIF.

ENDFORM. " check_options

&----


*& Form LIST_DISP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM LIST_DISP .

PERFORM DEFINE_LAYOUT.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = IT_FIELDCAT

IS_LAYOUT = LAYOUT

IT_SORT = IT_SORT

  • I_CALLBACK_PF_STATUS_SET = 'STATUS'

  • IT_EXCLUDING = I_FCODE_EXTAB

  • I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IT_EVENTS = IT_EVENTS[]

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = itab_final

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " LIST_DISP

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

*for different types of stock with material number.

select mard~matnr

mard~werks

mard~lgort

mard~labst

mard~insme

mard~speme

mard~einme

mard~retme

mseg~lifnr into corresponding

fields of table itab_final from mard inner join mseg on

mard~matnr =

msegmatnr where mardmatnr in matnr and mard~werks = s_werks.

*for vendor name:

select lifnr

name1

from lfa1 into corresponding fields of table

itab_lfa1 for all entries in itab_final where lifnr =

itab_final-lifnr.

*for plant name:

select werks

name1 from t001w into corresponding fields of table

itab_t001w for all entries in itab_final where werks =

itab_final-werks.

*for opening stock:

select werks

matnr

labst from mard into corresponding fields of table

itab_mard for all entries in itab_final where matnr = itab_final-matnr.

*for material description:

select matnr

maktx from makt into corresponding fields of table

itab_makt for all entries in itab_final where matnr = itab_final-matnr.

*for safety stock:

select matnr

werks

eisbe from marc into corresponding fields of table

itab_marc for all entries in itab_final where matnr = itab_final-matnr.

*for storage location description

select lgort

lgobe from t001l into corresponding fields of table

itab_t001l for all entries in itab_final where lgort = itab_final-lgort

.

sort itab_final by matnr lgort.

loop at itab_final.

read table itab_t001w with key werks = itab_final-werks.

if sy-subrc = 0.

itab_final-name1 = itab_t001w-name1.

endif.

read table itab_lfa1 with key lifnr = itab_final-lifnr.

if sy-subrc = 0.

itab_final-name2 = itab_lfa1-name1.

endif.

read table itab_makt with key matnr = itab_final-matnr.

if sy-subrc = 0.

itab_final-maktx = itab_makt-maktx.

endif.

read table itab_marc with key matnr = itab_final-matnr

werks = itab_final-werks.

if sy-subrc = 0.

itab_final-eisbe = itab_marc-eisbe.

endif.

read table itab_t001l with key lgort = itab_final-lgort.

if sy-subrc = 0.

itab_final-lgobe = itab_t001l-lgobe.

endif.

itab_final-labst = itab_final-labst + itab_final-insme +

itab_final-speme.

modify itab_final.

delete adjacent duplicates from itab_final comparing matnr lgort.

endloop.

*loop and case for the quantity of the field " target monthly.

loop at itab_final.

case itab_final-matnr.

when '000000001000000008'.

itab_final-labst_tm = '3000.000'.

when '000000001000000007'.

itab_final-labst_tm = '500.000'.

when '000000001000000006'.

itab_final-labst_tm = '400.000'.

when '000000001000000005'.

itab_final-labst_tm = '3000.000'.

when '000000003000000011'.

itab_final-labst_tm = '18000.000'.

when '000000001000000000'.

itab_final-labst_tm = '20000.000'.

when '000000001000000001'.

itab_final-labst_tm = '20000.000'.

endcase.

modify itab_final.

endloop.

ENDFORM. " get_data

form top.

clear itab_final-p_date.

WRITE:/ SY-ULINE.

WRITE:/ 'REPORT DATE:', SY-DATUM, 60 'VISA STEEL LTD.' color 5,

100'Report Developed By Ravi kumar Gupta.' .

WRITE:/ 'TIME:', SY-UZEIT.

*for previous date

clear itab_final-p_date.

itab_final-p_date = S_date - 1.

WRITE:/ 'USER NAME:', SY-UNAME,55'STOCK REPORT FOR:',73

ITAB_FINAL-P_DATE,100'Application:MM & PP.'.

WRITE:/ 'PAGE', SY-PAGNO.

  • write:/ 'Unit of Measure =','MT.'.

translate itab_final-name1 to upper case.

WRITE:/54 itab_final-name1 color 6.

WRITE:/ SY-ULINE.

skip 1.

endform.

form end_list.

skip 1.

write:/ sy-uline.

write:/ 'Cc:S.B.Singh Executive Director.'.

write:/04'K.M.Lal Executive Director Raw Material.'.

write:/04'A.K.Lamba President Project.'.

write:/04'A.K.Agarwal VP Commercial.'.

write:/04'Murli Dhar Manager Blast Furnace.'.

write:/04'S.N.Sarangi DGM Commercial.'.

WRITE:/ SY-ULINE. .

SKIP 2.

WRITE:/60 'END OF PAGE'.

endform.

&----


*& Form FORM_DISP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FORM_DISP .

ENDFORM. " FORM_DISP

&----


*& Form DEFINE_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DEFINE_LAYOUT .

LAYOUT-ZEBRA = 'X'.

  • LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL SUM'.

LAYOUT-WINDOW_TITLEBAR = 'STOCK REPORT'.

LAYOUT-TOTALS_TEXT = 'TOTAL'.

ENDFORM. " DEFINE_LAYOUT

&----


*& Form get_mkpf_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mkpf_data .

itab_mkpf-p_date1 = s_date.

itab_mkpf-p_date1+6 = '01'.

**for the current date

select mkpf~mblnr

mkpf~budat

mseg~matnr

mseg~werks

mseg~lgort

mseg~bwart

mseg~shkzg

mseg~menge into corresponding fields of

table itab_mkpf1 from mkpf inner join mseg on mkpf~mblnr =

mseg~mblnr where

budat eq itab_mkpf-p_date1

.

*for the whole year

select mkpf~mblnr

mkpf~mjahr

mkpf~budat

mkpf~blart

mseg~matnr

mseg~werks

mseg~lgort

mseg~bwart

mseg~erfmg

mseg~shkzg

mseg~menge into corresponding fields of

table itab_mkpf_mseg from mkpf inner join mseg on mkpf~mblnr =

mseg~mblnr where

budat gt itab_mkpf-p_date1

and budat le sy-datum.

ENDFORM. " get_mkpf_data

&----


*& Form get_mseg_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_data .

sort itab_mkpf_mseg by werks lgort matnr .

*for the deletion of material from mseg.

sort itab_mkpf_mseg by matnr lgort.

loop at itab_mkpf_mseg.

read table itab_final with key matnr = itab_mkpf_mseg-matnr.

if sy-subrc eq 4.

delete itab_mkpf_mseg.

endif.

endloop.

*for material deletion of itab_mkpf1

loop at itab_mkpf1.

read table itab_mkpf_mseg with key matnr = itab_mkpf1-matnr.

if sy-subrc eq 4.

delete itab_mkpf1.

endif.

endloop.

sort itab_mkpf_mseg by matnr werks lgort shkzg.

delete itab_mkpf_mseg where lgort is initial.

*for closing stock i.e,all mvmnt type summation

loop at itab_final.

loop at itab_mkpf_mseg.

IF itab_final-werks = itab_mkpf_mseg-werks AND

itab_final-lgort = itab_mkpf_mseg-lgort and

itab_final-matnr = itab_mkpf_mseg-matnr.

MOVE-CORRESPONDING itab_mkpf_mseg TO weg_mat.

COLLECT weg_mat.

ENDIF.

ENDLOOP.

ENDLOOP.

*for current date movement type

loop at itab_final.

loop at itab_mkpf1.

IF itab_final-werks = itab_mkpf1-werks AND

itab_final-lgort = itab_mkpf1-lgort and

itab_final-matnr = itab_mkpf1-matnr.

MOVE-CORRESPONDING itab_mkpf1 TO sum_mat.

COLLECT sum_mat.

ENDIF.

ENDLOOP.

ENDLOOP.

*for closing stock

loop at itab_final.

CLEAR weg_mat-menge.

MOVE-CORRESPONDING itab_final TO bestand.

READ TABLE weg_mat WITH KEY werks = itab_final-werks

lgort = itab_final-lgort

matnr = itab_final-matnr

shkzg = 'S'.

bestand-endmenge = itab_final-labst + itab_final-insme +

itab_final-speme + itab_final-einme +

itab_final-retme - weg_mat-menge.

CLEAR weg_mat-menge.

READ TABLE weg_mat WITH KEY werks = itab_final-werks

lgort = itab_final-lgort

matnr = itab_final-matnr

shkzg = 'H'.

bestand-endmenge = bestand-endmenge + weg_mat-menge. "closing stock

COLLECT bestand.

endloop.

ENDFORM. " get_mseg_data

&----


*& Form refresh_mseg_mkpf

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM refresh_mseg_mkpf .

REFRESH itab_mkpf.

REFRESH itab_mseg.

REFRESH itab1.

REFRESH itab2.

ENDFORM. " refresh_mseg_mkpf

&----


*& Form get_mseg_cancellation

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_cancellation .

itab_mkpf_rcvdate-p_date2 = s_date - 1.

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat eq itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

if not itab_mkpf_rcvdate[] is initial.

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('101','531') and werks = s_werks.

endif.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified into corresponding fields of

table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart in ('102','532') and mandt = sy-mandt .

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

ENDFORM. " get_mseg_cancellation

&----


*& Form get_mseg_recvtoday_quantity .

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_recvtoday_quantity .

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_rt = itab_101-erfmg_rt .

endat.

endif.

endloop.

modify itab_final.

endloop.

clear itab_final-labst_rt.

ENDFORM. " get_mseg_recvtoday_quantity .

&----


*& Form get_mseg_recvtilldate_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_recvtilldate_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat between itab_mkpf-p_date1 and itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('101','531') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart in ('102','532') and mandt = sy-mandt

.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_rtld = itab_101-erfmg_rt.

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_recvtilldate_quantity

&----


*& Form get_refresh_alltable

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_refresh_alltable .

refresh itab_mkpf_rcvdate.

refresh itab_101.

refresh itab3.

refresh itab_mkpf.

ENDFORM. " get_refresh_alltable

&----


*& Form get_mseg_recvtillyear_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_recvtillyear_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat le itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('101','531') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart in ('102','532') and mandt = sy-mandt

.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_rty = itab_101-erfmg_rt.

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_recvtillyear_quantity

&----


*& Form get_mseg_issuedtoday_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_issuedtoday_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat eq itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

if not itab_mkpf_rcvdate[] is initial.

select

matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg

into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('261') and werks = s_werks.

endif.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart = 262 and mandt = sy-mandt.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_it = itab_101-erfmg_rt.

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_issuedtoday_quantity

&----


*& Form get_mseg_issdtilldate_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_issdtilldate_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat between itab_mkpf-p_date1 and itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('261') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart = 262 and mandt = sy-mandt.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_itld = itab_101-erfmg_rt.

endat.

endif.

endloop.

itab_final-eisbe_cl = itab_final-labst + itab_final-labst_rtld

- itab_final-labst_itld.

modify itab_final.

endloop.

ENDFORM. " get_mseg_issdtilldate_quantity

&----


*& Form get_mseg_issdtillyear_quantity

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mseg_issdtillyear_quantity .

select mblnr

mjahr

budat

blart from mkpf into corresponding fields of

table itab_mkpf_rcvdate where

budat le itab_mkpf_rcvdate-p_date2

and blart in

('WA','WE','WL').

select matnr

erfmg

mblnr

ebeln

werks

lgort

bwart

lfbnr

erfmg

smbln from mseg into corresponding fields of table itab_101

for

all entries in itab_mkpf_rcvdate

where mblnr = itab_mkpf_rcvdate-mblnr and

bwart in ('261') and werks = s_werks.

select mandt

ebeln

matnr

bwart

lfbnr

smbln from mseg client specified

into corresponding fields of table itab3 for

all entries in itab_101 where ebeln =

itab_101-ebeln and bwart = 262 and mandt = sy-mandt.

loop at itab_101.

read table itab3 with key lfbnr = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

read table itab3 with key smbln = itab_101-mblnr.

if sy-subrc = 0.

delete itab_101.

continue.

endif.

endloop.

sort itab_101 by matnr.

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

at end of matnr.

sum.

itab_101-erfmg_rt = itab_101-erfmg.

itab_final-labst_ity = itab_101-erfmg_rt .

endat.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " get_mseg_issdtillyear_quantity

&----


*& Form for_closing_balance

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM for_closing_balance .

loop at itab_final.

loop at itab_101.

IF itab_final-werks = itab_101-werks AND

itab_final-lgort = itab_101-lgort and

itab_final-matnr = itab_101-matnr.

itab_final-eisbe_cl = itab_final-labst + itab_final-labst_rtld

- itab_final-labst_itld.

endif.

endloop.

modify itab_final.

endloop.

ENDFORM. " for_closing_balance

&----


*& Form sort_field

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sort_field .

WA_SORT-FIELDNAME = 'MATNR'.

WA_SORT-TABNAME = 'ITAB_FINAL'.

WA_SORT-SPOS = 1.

WA_SORT-UP = 'X'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

  • WA_SORT-FIELDNAME = 'LABST1'.

  • WA_SORT-TABNAME = 'ITAB_FINAL'.

  • WA_SORT-UP = 'X'.

  • WA_SORT-SPOS = 2.

  • WA_SORT-SUBTOT = 'X'.

  • APPEND WA_SORT TO IT_SORT.

  • CLEAR WA_SORT.

*

ENDFORM. " sort_field

&----


*& Form get_opening_stock

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_opening_stock .

LOOP AT bestand.

CLEAR sum_mat-menge.

READ TABLE sum_mat WITH KEY werks = bestand-werks

matnr = bestand-matnr

lgort = bestand-lgort

shkzg = 'S'.

MOVE sum_mat-menge TO bestand-soll.

CLEAR sum_mat-menge.

READ TABLE sum_mat WITH KEY werks = bestand-werks

matnr = bestand-matnr

lgort = bestand-lgort

shkzg = 'H'.

MOVE sum_mat-menge TO bestand-haben.

bestand-anfmenge = bestand-endmenge - bestand-soll

+ bestand-haben.

MODIFY bestand.

ENDLOOP.

ENDFORM. " get_opening_stock

&----


*& Form alv_display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM alv_display . "for opening and closing stcok

loop at itab_final.

loop at bestand.

IF itab_final-werks = bestand-werks AND

itab_final-lgort = bestand-lgort and

itab_final-matnr = bestand-matnr.

if sy-subrc = 0.

itab_final-labst = bestand-anfmenge.

itab_final-labst_cl = bestand-endmenge.

endif.

endif.

modify itab_final.

endloop.

endloop.

ENDFORM. " alv_display

Message was edited by:

ravi gupta

6 REPLIES 6
Read only

Former Member
0 Likes
828

hi

try to remove the tables option.

so that you can improve the performance.

thanks

shyam.

Read only

Former Member
0 Likes
828

Hi man,

quite a big report with lot many select queries. some suggestions:

1) Dont fire select query on same DB more than one time.

2) Check if itab is not initial when using FOR ALL ENTRIES.

3) Avoid two if condition for the radiobuttons having common radiobutton group like LIST & FORM in this case.

4) before creating field ALV stuff check output itab is not inital.

Thanks

Sandeep

Reward if helpful

Read only

Former Member
0 Likes
828

Hello ,

Move corresponding and join statements takes more time . check is it possible eliminate these staements .

Regards,

Rk

Read only

Former Member
0 Likes
828

Hi,

1. Before selecting sort the internal tables by the key fields.

2. Might be the internal table data is more use BINARY SEARCH when reading a table with key.

3. Use workareas instead getting data into internal table header.

4. For MODIFY statement give the row no. to modify with the values.

e.g: INDEX row_no TRANSPORTING FROM wa.

5. Clear fields, workareas whenever there is no use. FREE the tables which u don't require for further processing.

6. Give as many conditions while selecting data from database tables in WHERE conditions.

7. Don't use System variables directly like SY-INDEX while modifying or any process instead assign this value to ur local variable and use it.

8. Before selecting data from database tables using FOR ALL ENTRIES OF TABLE itab check whether the internal table u r using contains any data.

9. Instead of MOVE-CORRESPONDING assign the values directly to the fields of internal table and append.

Thanks & Regards

Santhosh

Read only

Former Member
0 Likes
828

hi

good

use move corresponding statement in all the select statements and check the difference.

thanks

mrutyun^

Read only

Former Member
0 Likes
828

hi,

1.first remove occurs 0 and occurs 0,

use types and delcare structure.

then declare internal table.

ex-

types : begin of ty_lfa1,

kunnr like kna1-kunnr,'end of ty_kna1.

data : i_kna1 type standard table of ty_kna1 with header line.

2.instead of inner join use forallentries.

3. into corresponding fields of will decrease performance.

4. delete adjacent duplicates from itab_final comparing matnr lgort.

place it outside the loop.

5.before every select statenet check sy-subrc = 0.if sucessful the write another one.

6.dont' loop an internal table more than once.

and for better performane follow below points

Always check the driver internal tables is not empty, while using FOR ALL ENTRIES

Avoid for all entries in JOINS

Try to avoid joins and use FOR ALL ENTRIES.

Try to restrict the joins to 1 level only ie only for tables

Avoid using Select *.

Avoid having multiple Selects from the same table in the same object.

Try to minimize the number of variables to save memory.

The sequence of fields in 'where clause' must be as per primary/secondary index ( if any)

Avoid creation of index as far as possible

Avoid operators like <>, > , < & like % in where clause conditions

Avoid select/select single statements in loops.

Try to use 'binary search' in READ internal table. Ensure table is sorted before using BINARY SEARCH.

Avoid using aggregate functions (SUM, MAX etc) in selects ( GROUP BY , HAVING,)

Avoid using ORDER BY in selects

Avoid Nested Selects

Avoid Nested Loops of Internal Tables

Try to use FIELD SYMBOLS.

Try to avoid into Corresponding Fields of

Avoid using Select Distinct, Use DELETE ADJACENT

Go through the following Document

Check the following Links

http://www.sapgenie.com/abap/performance.htm

http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp

check the below link

http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm

See the following link if it's any help:

http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp

Check also http://service.sap.com/performance