Reputation: 127
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!
Upvotes: 0
Views: 5096
Reputation: 13666
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).
Upvotes: 1
Reputation: 502
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
Upvotes: 1