简体   繁体   中英

Read statement fails as internal table is empty

Recently I've come across a Read statement which gives Sy-subrc eq 8. this happens because the internal table has no records and at the same time variables in the WHERE clause are empty too. What I have been wondering is why wouldn't we check if the table is not initial before the read statement?

pleas let me know if we can check the itab is not initial before read statement.

Thanks!

Yes, you can check itab is not initial before read statement. what's bothering you? it's not an issue. And WITH KEY or WITH TABLE KEY clause used with read statement not WHERE .
And if there is no value exist in internal table for given key value then SY-SUBRC will be 4

It's a wrong assumption to make a direct link between READ TABLE on an empty table and SY-SUBRC = 8 . If you read the official ABAP documentation , you will see that SY-SUBRC = 8 is related to the variant READ TABLE ... BINARY SEARCH .

So, with READ TABLE ... BINARY SEARCH , SY-SUBRC will be 8 if the searched line doesn't exist but if it was inserted it would be placed after the last line of the table. Of course, that's always the case when the internal table is empty.

Addendum May, 10th: SY-SUBRC = 8 may also occur with READ TABLE on internal tables of type SORTED (because it's using a binary search implicitly).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM