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

problem in using read statement.

Former Member
0 Likes
935

i am using the read statement as follows :

read table tekpo with key werks = '1001'.

it is not reading the corresponding record.

though it reads or not it is returning the sy-subrc value 0.

plz let me know why it is happening as soon as possible.

points will be awarded.

8 REPLIES 8
Read only

Former Member
0 Likes
913

Weird...How is you internal table defined???

Greetings,

Blag.

Read only

suresh_datti
Active Contributor
0 Likes
913

try this..

sort tekpo by werks.

read table tekpo with key werks = '1001'

binary search.

~Suresh

Read only

Former Member
0 Likes
913

Hi,

The READ statement looks good..

read table tekpo with key werks = '1001'.

The sy-subrc will be 0 only if it finds a corresponding record.

Do you want all the records??what exactly is your requirement..

Thanks,

Naren

Read only

Former Member
0 Likes
913

Hi Srinivas rao,

You can use this example program and make the changes in your program as well:

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.

FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.

DO 4 TIMES.

LINE-COL1 = SY-INDEX.

LINE-COL2 = SY-INDEX ** 2.

APPEND LINE TO ITAB.

ENDDO.

READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.

<FS>-COL2 = 100.

READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.

DELETE ITAB INDEX 3.

IF <FS> IS ASSIGNED.

WRITE '<FS> is assigned!'.

ENDIF.

LOOP AT ITAB ASSIGNING <FS>.

WRITE: / <FS>-COL1, <FS>-COL2.

ENDLOOP.

The output is:

1 1

2 100

4 16

I think you have satisfied.

Thanks and regards

Vipin Das

Read only

Former Member
0 Likes
913

The information is not sufficient to identify the problem. Please post the data declaration of the internal table and the code around the read statement.

Read only

Former Member
0 Likes
913

Hi,

Sort your internal table by WERKS before reading it. Also use binary search addition with the read statement.

SORT tekpo BY werks.
READ TABLE tekpo
           WITH KEY werks = '1001' BINARY SEARCH.

Regards,

RS

Read only

Former Member
0 Likes
913

hi...,

Your read statement is correct..

If sy-subrc eq 0, then for sure it has got at least one record satisfying the given condition...

first check whether u are checking the Sy-subrc immediately after this read statement or not...

<i>This code onli improves the performance...

sort tekpo by werks.

read table tekpo with key werks eq '1001' binary search.</i>

regards,

sai ramesh.

    • reward all helpful answers...

Read only

RaymondGiuseppi
Active Contributor
0 Likes
913

Your syntax is correct. So there should be an other problem or misunderstanding.

Could you put more of your source ?

If SY-SUBRC = 0. The program has found a record.

Regards