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: 

Fetching record number (INDEX) in READ TABLE

Former Member
0 Kudos
9,941

Hi experts,

I have one internal table with 40000 records.

Now I want to read the particular record with key. So I am using


READ TABLE  TABNAME  WITH  KEY  FIELD = 'XYZ'.

But I want the record number (INDEX of int table or SY-TABIX in LOOP....ENDLOOP) of selected record.

I can find it using Loop ...Endloop...

But that int table is huge, So this option is not suitable.............

Could anybody suggest me an alternative.......

Thanks.................

1 ACCEPTED SOLUTION

Former Member
2,225

hi

declare a global variable of type int and after you read teh record with

READ TABLE TABNAME WITH KEY FIELD = 'XYZ'.

if sy-subrc = 0, assign the sy-tabix value to that global variable.

the sy-tabix returns the table index of the record whether u use it in loop-endloop or with read statement.

6 REPLIES 6

Former Member
0 Kudos
2,225

you can create one more field in your internal table and use count in that field whenever you fetch the record get the count field value also so that you will get the index

Former Member
2,226

hi

declare a global variable of type int and after you read teh record with

READ TABLE TABNAME WITH KEY FIELD = 'XYZ'.

if sy-subrc = 0, assign the sy-tabix value to that global variable.

the sy-tabix returns the table index of the record whether u use it in loop-endloop or with read statement.

Former Member
0 Kudos
2,225

Hi,

Try like this...



READ TABLE  TABNAME  WITH  KEY  FIELD = 'XYZ'.
lv_index = sy-tabix.

Hope its helps

Former Member
0 Kudos
2,225

Hello


READ TABLE  TABNAME  WITH  KEY  FIELD = 'XYZ'.
IF SY-SUBRC = 0.
  INDEX = SY-TABIX. " SY-TABIX - record number
ENDIF.

Former Member
0 Kudos
2,225

Hi,

try this .

data w_index type i.

READ TABLE TABNAME WITH KEY FIELD = 'XYZ'.

if sy-subrc eq 0.

w_index = sy-tabix.( This holds the index number of the record )

endif.

Former Member
0 Kudos
2,225

Hi,

Why you want to use another loop-endloop forreading the sy-tabix when after the the same READ statement you can read the sy-tabix that gives the index of the current record.

Is there anything else you wan to do?

Pooja