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

READ TABLE with INDEX

Former Member
68,499

Hi Friends,

Please can u explain me what is the use of this READ statement, and why we use INDEX here.

READ TABLE z_tlines INDEX 1

Thank you,

Shreekant

1 ACCEPTED SOLUTION
Read only

Former Member
28,011

hi,

Read table with index 1 will read the first record from ur internal table.... index denotes the row of ur internal table....

<b>reward points if useful...</b>

regards,

raksha

11 REPLIES 11
Read only

Former Member
28,012

hi,

Read table with index 1 will read the first record from ur internal table.... index denotes the row of ur internal table....

<b>reward points if useful...</b>

regards,

raksha

Read only

Former Member
0 Likes
28,011

hi,

<u>READ TABLE z_tlines INDEX 1</u>

It reads only one record...Either by index or key.

READ TABLE MY_TAB INDEX 1.

READ TABLE MY_TAB WITH KEY CODE = 'ATG'.

when we use the INDEX 1, it reads the 1st record of the table.

Reading records with keys

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

Reading lines with Index

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3730358411d1829f0000e829fbfe/content.htm

Rgds

Reshma

Read only

0 Likes
28,011

Hi

Read table statement is used for Reading a particular internala table or a field it is used for selecting a single record.

READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.

Check this sample code

READ TABLE itab INTO wa WITH KEY field1 = X.
IF sy-subrc <> 0.
  READ TABLE itab INTO wa WITH KEY field2 = Y.
  IF sy-subrc <> 0.
    READ TABLE itab INTO wa WITH KEY field3 = Z.
  ENDIF. 
ENDIF.
 
CHECK sy-subrc = 0. "Or an IF, of course

  

Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
28,011

Hi,

If you need only the first record in the table you can use like this

Read only

Former Member
0 Likes
28,011

Hi,

Read table is used when you want to read the contents of the internal table Z_tlines.

The option INDEX 1 is used to read the first line of the internal table.

Shruthi R

Read only

0 Likes
28,011

Hi,

If I want to read all the lines from the internal table what should I do.

Pls. reply me.

Thanks,

Shreekant

Read only

0 Likes
28,011

Hi,

If u want to read all the lines either u just use the same table for the purpose of usage or just loop at this table and put it onto a wrk area and use the record for further processing

<b>reward points if useful</b>

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
28,011

Hi,

READ TABLE isused to read from internal tables.

And INDEX can only be used with STANDARD and SORTED tables. INDEX can be used only with ORDERED and INDEXED tables like STADARD and SORTED tables.

This is to read from certain position.

Regards,

Sesh

Read only

Former Member
0 Likes
28,011

hi,

Read table will get the first record that saitisfies the condition specified in the with key statement into the header.

if an itab contains the following data:

field1 field2

1 one

2 two

3 three

4 four

5 five

And if you read the itab like this:

read table itab into WA with key field1 = '3'.

if sy-subrc = 0.

write:/ wa.

endif.

The output will be

3 three.

The sy-tabix will hold the value of index of the current record.

<b>REWARDS POINT</b>

Regards,

ASHOK

Read only

Former Member
0 Likes
28,011

hi,

read table st is used to read a record from internal table into workarea. with read statement we can do in 2 ways

1. using index

2. using key fields of the record

for ex:

loop at itab.

read table itab with index sy-tabix.

endloop.

reads all records of internal table with respect to index. here index is also used to read particular record it its given outside loop.

as similar usingkey field also we can read a record.

if helpful reward some points.

with regards,

Suresh Aluri.

Read only

former_member668243
Discoverer
0 Likes
28,011

Read table is used to read the record from your internal table "z_tlines" and if you mention the INDEX 1 with it then it means it will read the First record.