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

Select in Loop .

SG141
Active Participant
0 Likes
463

I have a internal table which contains material numbers. I need additional internal to hold material number and material description.

So is this a correct statement

loop at t_out.
select mtart from mara 
          into t_mara 
         where matnr = t_out-matnr.
endloop.

5 REPLIES 5
Read only

Former Member
0 Likes
444

Hi Kartik,

Please Use Select Single Instead of Select Query

loop at t_out.
select single mtart from mara 
          into t_mara 
         where matnr = t_out-matnr.
endloop.

This will work more faster

Read only

SG141
Active Participant
0 Likes
444

Getting a error Statement Not Accessible

Read only

Former Member
0 Likes
444

You better do it like this...


DATA: W_TABIX TYPE SY-TABIX.
FIELD-SYMBOLS: <OUT> LIKE LINE OF T_OUT.

IF NOT T_OUT[] IS INITIAL.
SELECT MTART
INTO T_MTART
FROM MARA
FOR ALL ENTRIES IN T_OUT
WHERE MATNR EQ T_OUT-MATNR.

LOOP AT T_OUT ASSIGNING <OUT>.
W_TABIX = SY-TABIX.
READ TABLE T_MTART WITH KEY MATNR = <OUT>-MATNR.
IF SY-SUBRC EQ 0.
MOVE T_MTART-MTART TO <OUT>-MTART.
MODIFY T_OUT FROM <OUT> INDEX W_TABIX.
ENDIF.
ENDLOOP.
ENDIF.

Greetings,

Blag.

Read only

Former Member
0 Likes
444

If you use select in loop, it may leads to performance issues, so it will be better if you use 'For all entries' .

Regards,

  • Dj

reward for all useful answers.

Read only

Former Member
0 Likes
444

better make your initial query with material desc also ie mtart. into ITAB1

select matnr mtart from mara into table ITAB1.

*copy Itab1 into itab2

itab2 = itab1.

I think performance wise this is good.

thanks

vinsee