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: 

About Read stmt

Former Member
0 Kudos

Hi Friends,

can anyone .. Explain this below READ statement.

LOOP AT it_hrp1000.

READ TABLE it_hrp1000 WITH KEY plvar = p_plvar

and otype = p_otype

and endda = p_endda2

BINARY SEARCH.

MY QUESTION IS,

WHY WE ARE USING THE ABOVE READ STMT WITH CONDITIONS IN PRG.. I MEAN WHICH WHICH SCENARIO..(SITUATION).

PLS.EXPLAIN ANY ONE.

4 REPLIES 4

former_member194669
Active Contributor
0 Kudos

Hi,

Read statement is usually used find exact match in an internal table.

Please change the query as it is



sort it_hrp1000 by plvar otype endda.
READ TABLE it_hrp1000 WITH KEY plvar = p_plvar
                               otype = p_otype
                               endda = p_endda2
                               BINARY SEARCH.

Please make a sort before using read with binary search otherwise your read statement will not give proper result.

aRs

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You are read statement to find out whether the record satisfying this condition is in internal table.The binary search is used to make the efficiency in reading.

But before using binary search, as sugggested you should sort the table by using the fields you are giving as condition in read statement.

You need to clear the workarea before the read statement, then only the work area will have the correct valueas after read.

sort it_hrp1000 by plvar otype endda.

LOOP AT it_hrp1000.

clear it_hrp1000.

READ TABLE it_hrp1000 WITH KEY plvar = p_plvar

and otype = p_otype

and endda = p_endda2

BINARY SEARCH.

....

endloop.

gopi_narendra
Active Contributor
0 Kudos

READ statement always returns a single value based on the Key validations given.

in your case you are looping on an internal table and trying to read the same internal table with some parameter values p_plvar p_otype p_endda2, which does not make any sense. Even if the it_hrp1000 contains 200 records. every time in the loop you are trying to match the values p_plvar..... in the same internal table.

so loop is not really necessary.

Just use READ statement.

or Use the loop at using where conditions.

loop at it_hrp1000 where plvar = p_plvar and otype = p_otype and endda = p_endda2.

<do your requirement here>

clear it_hrp1000.

endloop.

Apart from this as what other suggested of using binary search, clear work area etc should be followed and make then a general practice.

Regards

Gopi

Former Member
0 Kudos

Read statement is basically used to capture one particular record instead of looping over the whole table. With the read statment you can just get one particular row of the table , put it in a work area and process it as per your requirement.

please go through the following links to understand the fucntionality of read statement and how can we read lines of tables;

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

Please reward the helpful entries.

Regards,

Raman.