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 Statement

Former Member
0 Kudos
164

Hi All,

I am new to ABAP ,could any one explain me the READ statment,

1. Is it specific any internal table type

2. How is readind data different from using loop.

Thanks in advance.

AS

7 REPLIES 7

rainer_hbenthal
Active Contributor
0 Kudos
92

Why dont you use the online help? Just position the cursor on the keyword read and press F1, all your questions will be answered there.

FredericGirod
Active Contributor
0 Kudos
92

Hi Aima,

when you use LOOP, you will read all the data of the table. When you use READ, you will read only one line of the table.

for example a loop can be replace by.

describe table it_data lines v_count.
do.
  v_countb = v_countb + 1.
  if v_countb gt v_count.
    exit
  endif.
  read table it_data index v_countb.
enddo.

(I didn't check the code)

Read allow condition of selection, but you must be sure that this condition will only answer one line. Or you will not be sure that the answer will be the good one.

Have a look of the transaction ABAPDOCU for all advanced documentation.

Regards

Frédéric

Vinod_Chandran
Active Contributor
0 Kudos
92

Hi Aima,

READ is for reading record from any type of internal table using index or with fields.

LOOP statement will loop through the internal table record by record, based on the condition given if any.

Hope this is clear.

Cheers

Vinod

Former Member
0 Kudos
92

Hi,

Suppose, the records in an internal table(it_table) with field ID are

1 2 3 4 5.

if we say:

Read table it_table with key id = '3'.

the number of records processed will be only 3.

if we say :

loop at it_table where id = '3'.

endloop.

the number of records processed will be 5.

the number of records processed in case of both read and loop will be same if record is not found.

0 Kudos
92

Hi ,Firstly thanq for all ur replies,

Is it possible to use read statement for checking a validity date,i mean every syntax of READ uses '=' while checking the condition but for me the validaity date lies between two fields and specifing the condition like

datab =< wa_st-datum and datbi >= wa_st-datum

this will work.

Thanks,

AS

0 Kudos
92

You have to use the loop statement with condition gt ge lt le .. (> >= < <= ) and to exit to the first line.

for example

loop at it_table where datab =< wa_st-datum and datbi >= wa_st-datum.
  exit.
endloop.
if sy-subrc eq space.
  ... had your code ...
endif.

jayanthi_jayaraman
Active Contributor
0 Kudos
92

Hi,

Using read statement,you can only read single record.

But using loop,you can read more than one record.