Application Development 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: 

loop at internal table

Former Member
0 Kudos

Hi. I am fairly new to ABAP. I have a small doubt which requires your help. I wan to know if the following statement is correct.

loop at g_t_data where matnr in so_matnr.

so_matnr is a select option for mara-matnr.

I want to know if it is correct to use a select option after the where clause. I tried using it, and I didnt get any syntax error. I want to know if it is a right programming practice to do so.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

If it is needed, yes it is ok to use it. But typically you use the select option to select from the database table and then all your entries in the internal table will satisfy that condition, so you don't need to use it in the where clause of the loop statement again.

SELECT * FROM maraA INTO TABLE itab WHERE matnr IN so_matnr.

Here all the records will satisfy the condition for the select option already.

But if you have code like this for some reason,

SELECT * FROM mara INTO TABLE itab.

Then you need to use the select option in your loop statement as you did in your example.

3 REPLIES 3

Former Member
0 Kudos

If it is needed, yes it is ok to use it. But typically you use the select option to select from the database table and then all your entries in the internal table will satisfy that condition, so you don't need to use it in the where clause of the loop statement again.

SELECT * FROM maraA INTO TABLE itab WHERE matnr IN so_matnr.

Here all the records will satisfy the condition for the select option already.

But if you have code like this for some reason,

SELECT * FROM mara INTO TABLE itab.

Then you need to use the select option in your loop statement as you did in your example.

0 Kudos

Thanks a lot Srinivas. As you have mentioned, I was unable to use the where clause on so_matnr in my select statement because I had used an outer join to join tables, and so I couldnt use any fields from the table on the right hand side of the outer join in my select statement. That is the reason I had to use it in the loop at <itab> statement.

0 Kudos

As I said, in such cases, you can use it in the where clause. But another better way to do may be

DELETE itab WHERE matnr in so_matnr.

This way you can delete all the unwanted material records from your itab and then simply use the loop statement without the where clause.

Please close the post if answered,

Srinivas