Skip to Content
0
Former Member
Apr 21, 2008 at 10:17 AM

pls help me to improve performance(any more modification)

14 Views

TABLES : tvarv,mara,makt,mvke,zmaterialmaster.

DATA : i_materialmaster TYPE TABLE OF zmaterialmaster WITH HEADER LINE

.

DATA : BEGIN OF i_mara OCCURS 0 ,

matnr LIKE mara-matnr, "Material No

mbrsh LIKE mara-mbrsh, " Industry sector

matkl LIKE mara-matkl, " Material Group

spart LIKE mara-spart, " Division

mtart LIKE mara-mtart, " Material Type

meins LIKE mara-meins, " Basic unit of measure

END OF i_mara.

DATA : BEGIN OF i_mvke OCCURS 0,

matnr LIKE mvke-matnr,

vkorg LIKE mvke-vkorg, "Sales Organisation

vtweg LIKE mvke-vtweg, "Distribution Channel

mvgr1 LIKE mvke-mvgr1, " Material Group1

mvgr2 LIKE mvke-mvgr2, " Material Group2

mvgr3 LIKE mvke-mvgr3, " Material Group3

mvgr4 LIKE mvke-mvgr4, " Material Group4

mvgr5 LIKE mvke-mvgr5, " Material Group5

END OF i_mvke.

DATA : BEGIN OF i_makt OCCURS 0,

matnr LIKE makt-matnr,

maktx LIKE makt-maktx, "Material Description

END OF i_makt.

DATA : BEGIN OF i_cdhdr OCCURS 0, "internal table for delta material no:

matnr TYPE matnr,

END OF i_cdhdr.

DATA : BEGIN OF i_cdhdra OCCURS 0,

matnr TYPE matnr,

END OF i_cdhdra.

DATA : BEGIN OF i_failedmaterial OCCURS 0,

matnr TYPE matnr,

END OF i_failedmaterial.

DATA : v_objekt LIKE cdhdr-objectclas

VALUE 'MATERIAL',

v_datum TYPE sy-datum,

v_time TYPE sy-uzeit,

v_low TYPE tvarv-low,

v_high TYPE tvarv-high.

START-OF-SELECTION.

"Selecting the last run date and time from tvarv table

SELECT SINGLE low high INTO (v_low, v_high)

FROM tvarv

WHERE name = 'Zmaterialmaster'.

IF v_low IS INITIAL.

  • v_datum = sy-datum.

v_datum = '20080104'." .Change this date to initial download date

ELSE.

v_datum = v_low. "Last date the program was run.

ENDIF.

IF v_high IS INITIAL.

  • v_time = '210657'." Initial download time.

ELSE.

v_time = v_high. "Last time the program was run.

ENDIF.

IF v_datum = sy-datum. " Ïf the program is again run on the same day.

SELECT objectid FROM cdhdr INTO TABLE i_cdhdr

WHERE objectclas = v_objekt

AND udate >= v_datum

AND utime >= v_time.

select matnr from zmaterialmaster into table i_failedmaterial where upd_flag = 'E' .

if sy-subrc = 0.

append lines of i_failedmaterial to i_cdhdr.

endif.

ELSE. " If the program is again run on any other day

SELECT objectid FROM cdhdr INTO TABLE i_cdhdr

WHERE objectclas = v_objekt

AND udate = v_datum

AND utime >= v_time.

SELECT objectid FROM cdhdr INTO TABLE i_cdhdra

WHERE objectclas = v_objekt

AND udate > v_datum.

APPEND LINES OF i_cdhdra TO i_cdhdr.

select matnr from zmaterialmaster into table i_failedmaterial where upd_flag = 'E' .

if sy-subrc = 0.

append lines of i_failedmaterial to i_cdhdr.

endif.

ENDIF.

"Selecting all the mandatory fields for the delta material nos :

sort i_cdhdr by matnr."Jaya

IF i_cdhdr[] IS NOT INITIAL.

SELECT matnr mbrsh

matkl spart

mtart meins

FROM mara INTO TABLE i_mara

for all entries in i_cdhdr where matnr = i_cdhdr-matnr.

IF i_mara[] IS NOT INITIAL.

"Selecting material description for English language alone

SELECT matnr maktx FROM makt INTO table i_makt FOR ALL ENTRIES IN

i_mara

WHERE matnr = i_mara-matnr AND spras = 'E'.

"Selecting single entry for sales organisation 1000 alone

SELECT MATNR VKORG

VTWEG MVGR1

MVGR2 MBGR3

MVGR4 MVGR5

FROM MVKE INTO TABLE I_MVKE

FOR ALL ENTRIES IN I_MARA

WHERE MATNR EQ I_MARA-MATNR

AND VKORG EQ '1000'.

  • LOOP at i_mara.

  • SELECT single matnr vkorg vtweg mvgr1 mvgr2 mvgr3 mvgr4 mvgr5 FROM mvke INTO

  • i_mvke WHERE

  • matnr = i_mara-matnr AND vkorg = '1000' .

  • append i_mvke.

  • endloop.

*

ENDIF.

SORT:i_mara by matnr,

i_mvke by matnr."Jaya

LOOP AT i_mara.

READ TABLE i_makt WITH KEY matnr = i_mara-matnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE-CORRESPONDING i_mara TO i_materialmaster.

MOVE-CORRESPONDING i_makt TO i_materialmaster.

ENDIF.

READ TABLE i_mvke WITH KEY matnr = i_mara-matnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE-CORRESPONDING i_mvke TO i_materialmaster.

ENDIF.

APPEND i_materialmaster.

ENDLOOP.

DELETE ADJACENT DUPLICATES FROM i_materialmaster.

LOOP AT i_materialmaster.

WRITE:/ i_materialmaster.

i_materialmaster-update_date = sy-datum.

i_materialmaster-update_time = sy-uzeit.

i_materialmaster-flag = 'X'. "To indicate the records to be transferred.

zmaterialmaster = i_materialmaster. "To update the Z-Table.

MODIFY zmaterialmaster.

MODIFY i_materialmaster.

ENDLOOP.

ENDIF.

CLEAR tvarv.

tvarv-name = 'Zmaterialmaster'.

tvarv-type = 'P'.

tvarv-sign = 'I'.

tvarv-opti = 'EQ'.

tvarv-low = sy-datum. "Setting the last run date in the tvarv table

tvarv-high = sy-uzeit. " Setting the last run time in the tvarv table

MODIFY tvarv.