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

How to use Read table to avoid loops in program

Former Member
0 Likes
766

To avoid select statements in loop.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
733

Hi,

You can use For all entries insted of using a select statement inside a loop.

If itab[] is not initial.

Select * from mara into L_MARA for all entries in itab where matnr = itab-matnr.

endif.

Reward if helpful.

5 REPLIES 5
Read only

Former Member
0 Likes
733

Hi,

Collect data using select statement in itab.

Collect data using select statement in jtab for corresponding itab entries.

loop at itab.

read table jtab key = itab-key.

append to ktab.

endloop.

Reward if useful!

Read only

Former Member
0 Likes
734

Hi,

You can use For all entries insted of using a select statement inside a loop.

If itab[] is not initial.

Select * from mara into L_MARA for all entries in itab where matnr = itab-matnr.

endif.

Reward if helpful.

Read only

Former Member
0 Likes
733

u can use Inner joins or for all entries in select statement,.

or esle.

u have one itab which has department details.

one more itab as Employee details.

u have to matehc these two to gte final output.

Loop at emp.

Clear dept.

Read table dept with key dept_no = emp-deptno.

if sy-subrc = 0.

itab-empno = emp-empno.

itab-deptno = dept-deptno.

itab-name = emp-name.

itab-deptname = dept-deptname.

append itab.

clear itab.

endif.

endloop.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
733

Hi,

You need to get the data into an internal table.

Suppose you have to loop ITAB1.

And you want data from ITAB2.

Then use

SELECT *FROM <dbtab> INTO TABLE ITAB2 FOR ALL ENTRIES IN ITAB1

WHERE FIELD1 = ITAB1-FIELD1.

Use it this way.

Then use

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY FIELD1 = ITAB1-FIELD1.

ENDLOOP.

Regards,

Sesh

Read only

Former Member
0 Likes
733

hi,

u can go for READ TABLE STATEMENT instead of select statement in loops as

LOOP AT ITAB.

READ TABLE ITAB WITH KEY MATNR = ' value ' or INDEX = SY-TABIX

OR KWY FIELD = MATNR.

ENDLOOP.

IF HELPFUL REWARD SOME POINTS.

WITH REGARDS,

SURESH.A