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

peformance Issue

former_member206396
Active Participant
0 Likes
483

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

4 REPLIES 4
Read only

Former Member
0 Likes
458

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

Read only

Former Member
0 Likes
458

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

Read only

rajeshkumar_kaveti
Participant
0 Likes
458

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

Read only

Former Member
0 Likes
458

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.