‎2006 Oct 12 7:28 AM
hi SDNs,
the following stmts giving performance issue.
SELECT LGORT
WERKS
FROM T001L
INTO TABLE LT_LGORT
FOR ALL ENTRIES IN LT_FLAT
WHERE WERKS = LT_FLAT-WERKS.
LOOP AT LT_FLAT INTO LW_FLAT.
LOOP AT LT_LGORT INTO LW_LGORT WHERE WERKS = LW_FLAT-WERKS.
LW_TEMP-MATNR = LW_FLAT-MATNR.
LW_TEMP-LGORT = LW_LGORT-LGORT.
LW_TEMP-WERKS = LW_FLAT-WERKS.
APPEND LW_TEMP TO LT_LGORT_TEMP.
CLEAR LW_TEMP.
CLEAR LW_LGORT.
ENDLOOP.
CLEAR LW_FLAT.
ENDLOOP.
REFRESH LT_LGORT.
LT_LGORT[] = LT_LGORT_TEMP.
REFRESH LT_LGORT_TEMP.
could any tell me how to make these feasible.
Thanking you.,
Rama krishna S
‎2006 Oct 12 7:38 AM
Hi Rama,
Take a look at this code which should be better ( better than "loop where"
data : w_index_lgort like sy-index.
SELECT LGORT
WERKS
FROM T001L
INTO TABLE LT_LGORT
FOR ALL ENTRIES IN LT_FLAT
WHERE WERKS = LT_FLAT-WERKS.
sort lt_flat by werks.
sort lt_lgort by werks.
LOOP AT LT_FLAT INTO LW_FLAT.
LOOP AT LT_LGORT INTO LW_LGORT from w_index_lgort.
if lw_lgort-werks gt lw_flat-werks.
exit.
else.
w_index_lgort = w_index_lgort + 1.
check lw_lgort-werks eq lw_flat-werks.
LW_TEMP-MATNR = LW_FLAT-MATNR.
LW_TEMP-LGORT = LW_LGORT-LGORT.
LW_TEMP-WERKS = LW_FLAT-WERKS.
APPEND LW_TEMP TO LT_LGORT_TEMP.
CLEAR LW_TEMP.
CLEAR LW_LGORT.
endif.
ENDLOOP.
CLEAR LW_FLAT.
ENDLOOP.
REFRESH LT_LGORT.
LT_LGORT[] = LT_LGORT_TEMP.
REFRESH LT_LGORT_TEMP.
Best Regards,
Erwan
‎2006 Oct 12 7:40 AM
hi,
instead of looping within a loop, try using the read table statement.
read table LT_LGORT INTO LW_LGORT with key WERKS = LW_FLAT-WERKS.
Also, after the statement "for all entries", use : if itab[] is not initial.
regards,
Sandeep.
Message was edited by: sandeep kumar
‎2006 Oct 12 7:46 AM
hi,
Inner join can retrieve fields from both the tables at a time with improved performance. I need the table from which u r fetching data into it_flat to give u the inner join syntax.
Regards,
Rajesh
‎2006 Oct 12 7:49 AM
Please try out :
SELECT LGORT
WERKS
FROM T001L
INTO TABLE LT_LGORT
FOR ALL ENTRIES IN LT_FLAT
WHERE WERKS = LT_FLAT-WERKS.
Now if there is single record corresponding to every entry(means LT_FLAT has WERKS as primary key identifier) of LT_LGORT-WERKS efficiency can be improved using READ statement.
LOOP AT LT_LGORT INTO LW_LGORT.
READ TABLE LT_FLAT INTO LW_FLAT WHERE WERKS = LW_LGORT-WERKS.
if sy-subrc eq 0
LW_TEMP-MATNR = LW_FLAT-MATNR.
LW_TEMP-LGORT = LW_LGORT-LGORT.
LW_TEMP-WERKS = LW_FLAT-WERKS.
APPEND LW_TEMP TO LT_LGORT_TEMP.
CLEAR LW_TEMP.
CLEAR LW_LGORT.
ENDIF.
CLEAR LW_FLAT.
ENDLOOP.
REFRESH LT_LGORT.
LT_LGORT[] = LT_LGORT_TEMP.
REFRESH LT_LGORT_TEMP.