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: 

Read and Loop

Former Member
0 Kudos

Hi,All

Can anyone tell me the differences between READ loop and LOOP loop?

And in which condition I should use READ ?

In which condition I should use LOOP?

In which condition I should use both?

Thank you very much!

Best Regards,

Fiona

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Use the READ statement to read the particular record of the table based on a key parameter or based on index.

READ alwaye returns only one record.

To process/access multiple records use the LOOP statemnt.

Look at the below example:

IF internal table ITAB Has two fields CARRID and CONNID.

It contains the following records

CARRID CONNID

AA 01

AA 02

AA 03

AB 10

AB 11

If you want a record with carrid = 'AA' and connid = '03', use the READ stament as READ TABLE ITAB WITH KEY CARRID = 'AA' CONNID = '03'.

If you want to access the records with carrid 'AA', use loop statement.

Thanks,

Rajinikanth

4 REPLIES 4

Former Member
0 Kudos

Use the READ statement to read the particular record of the table based on a key parameter or based on index.

READ alwaye returns only one record.

To process/access multiple records use the LOOP statemnt.

Look at the below example:

IF internal table ITAB Has two fields CARRID and CONNID.

It contains the following records

CARRID CONNID

AA 01

AA 02

AA 03

AB 10

AB 11

If you want a record with carrid = 'AA' and connid = '03', use the READ stament as READ TABLE ITAB WITH KEY CARRID = 'AA' CONNID = '03'.

If you want to access the records with carrid 'AA', use loop statement.

Thanks,

Rajinikanth

former_member195383
Active Contributor
0 Kudos

Hi..

Read will fetch u a single record of an internal table where as Loop will make u able to access all the rows of the internal table....

suppose u have a table itab.

then

read table itab into wa_itab index 1.

will make u having the value of the first row of the interanl table in wa_itab, wa_itab is a work area of the type same as itab.

or u can use

read table itab into wa_itab with key field1 = co_value1.

here u can get a perticular record where field1 is having a value of co_value1.

loop at itab into wa_itab.

:

:

endloop.

here inside loop...endloop u will have all the recods one by one in wa_itab.

put a break point inside loop....endloop then u can see how values are coming in to wa_itab. in the loop.

Edited by: Rudra Prasanna Mohapatra on Jul 16, 2008 11:00 AM

Former Member
0 Kudos

Hi,

In programming practice, we do come across some situations where in we need to find whether a particular record is existing in a table or not .

In such cases we need to use READ statement to find out whether the record is vailable or not.

If the record is available then the return code will be 0.

In this case LOOP also works but performancewise READ is better.

Regards,

Ram

Subhankar
Active Contributor
0 Kudos

When you try catch one record use READ statement,

When you want retrieved all the record use loop statement.

when u want to get all the records from one ITAB then want get the particular record of another ITAB then use LOOP in first ITAB then use read statement in second ITAB with in the loop.