‎2008 Jul 23 11:32 AM
Hi all,
I am facing performance issue as i am using select statement inside a loop .I need to move select statement out of the loop .thanx in advance .what all changes need to be made in the code .
LOOP at itab_mseg1.
*-- To get 1633 Code for Material from MARA Table
SELECT SINGLE zzinvtp zzlstnr zzlblcd zzinvsz
FROM mara
INTO CORRESPONDING FIELDS OF wa_mara
WHERE matnr = itab_mseg1-matnr.
IF sy-subrc = 0.
CONCATENATE wa_mara-zzinvtp wa_mara-zzlstnr
wa_mara-zzlblcd wa_mara-zzinvsz
INTO itab_output-z1633code.
ENDIF.
CLEAR wa_mara.
endloop.
‎2008 Jul 23 11:35 AM
Hi,
Use FOR ALL ENTRIES IN.
SELECT zzinvtp zzlstnr zzlblcd zzinvsz
FROM mara
INTO CORRESPONDING FIELDS OF TABLE IT_MARA
FOR ALL ENTRIES IN ITAB_MSEG1
WHERE matnr = itab_mseg1-matnr.Regards
Adil
‎2008 Jul 23 11:33 AM
Hi,
Use for all entries inplace of select inside loop.
Assumption: ITAB_MSEG1 should have unique MATNR. if not delete the duplicate entries of MATNR.
IF NOT ITAB_MSEG1[] IS INITIAL.
SELECT zzinvtp zzlstnr zzlblcd zzinvsz
FROM mara
INTO CORRESPONDING FIELDS OF TABLE IT_MARA
FOR ALL ENTRIES IN ITAB_MSEG1
WHERE matnr = itab_mseg1-matnr.
IF sy-subrc = 0.
LOOP AT IT_MARA.
---> do the processing here
ENDLOOP.
ENDIF.
regards,
madhu
‎2008 Jul 23 11:34 AM
Change your select from MARA to use a FOR ALL ENTRIES based on your ITAB_MSEG1 table. Be careful to check the number of entries in this table though as you could still have performance issues.
Search for more info and read the F1 help if you don't know how to use FOR ALL ENTRIES - there are thousands of posts on here explaining it.
‎2008 Jul 23 11:35 AM
Hi,
Use FOR ALL ENTRIES IN.
SELECT zzinvtp zzlstnr zzlblcd zzinvsz
FROM mara
INTO CORRESPONDING FIELDS OF TABLE IT_MARA
FOR ALL ENTRIES IN ITAB_MSEG1
WHERE matnr = itab_mseg1-matnr.Regards
Adil
‎2008 Jul 23 11:36 AM
do this way
if not itab_mseg1[] is initial..
SELECT matnr zzinvtp zzlstnr zzlblcd zzinvsz
FROM mara
into it_mara
for all entries of itab_mseg1
WHERE matnr = itab_mseg1-matnr.
if sy-subrc = 0.
endif.
endif.
LOOP at itab_mseg1.
read table it_mara with key matnr = itab_mseg1-matnr into wa_mara.
IF sy-subrc = 0.
CONCATENATE wa_mara-zzinvtp wa_mara-zzlstnr
wa_mara-zzlblcd wa_mara-zzinvsz
INTO itab_output-z1633code.
ENDIF.
CLEAR wa_mara.
endloop.
‎2008 Jul 23 11:38 AM
My Proposal would be NOT to use for all entries.
I would do a full mara array-fetch into an internal table BEFORE your loop, and then inside the loop just use read-table statements.
at least it´s worth a try.
‎2008 Jul 23 11:38 AM
Hi,
Try this way...
clear wa_mara.
SELECT SINGLE zzinvtp
zzlstnr
zzlblcd
zzinvsz
INTO CORRESPONDING FIELDS OF wa_mara
FROM mara
FOR ALL ENTRIES IN TABLE ITAB_MSEG1
WHERE matnr = itab_mseg1-matnr.
IF sy-subrc = 0.
CONCATENATE wa_mara-zzinvtp wa_mara-zzlstnr
wa_mara-zzlblcd wa_mara-zzinvsz
INTO itab_output-z1633code.
ENDIF.
clear wa_mara.Depending on no of times you need to change the logic.... if you want to use the above one time then go as stated above or else put all the details in to internal table T_MARA instead of WA_MARA and then Loop your table with which the value has to be compared and read the table T_MARA with key of that compared internal table and concatenate to the your destination internal table.
Hope this would help you.
Regards
Narin Nandivada.