2016 Aug 07 3:27 PM
Hello,
I know that the READ TABLE statement can only return a single row, and for that reason the WITH (TABLE) KEY addition cannot accept anything but comparison ('=').
The question is, why can't I type 'EQ' instead of '='?
For example,
This is the possible syntax:
READ TABLE lt_materials[] INTO ls_material WITH KEY material_type = 'FOOD'.
This is my desired syntax:
READ TABLE lt_materials[] INTO ls_material WITH KEY material_type EQ 'FOOD'.
I always use only 'EQ' whenever I compare - in WHERE clauses of SELECTs and LOOP ATs, in IFs and CHECKs. So why does READ TABLE WITH KEY have to be different?
In my opinion, the '=' operator should only be used for assignments. When I go through my code quickly, I can easily see exactly where there are assignments and where there are comparisons, except this case of READ TABLE WITH KEY.
Does anyone have an explanation for this?
2016 Aug 08 7:09 AM
Hi,
Relational operators (EQ,NE,GT,LT ,etc) represent conditions that are applied to data. The purposes of these conditions are to determine the result of a comparison between two data values. A condition result can only be of two possible values.
2016 Aug 08 7:19 AM
Thank you for your answer.
I know all that, and I know there are two version of each operator, for example 'NE' and '<>' are the same, and 'GT' and '>' are the same.
I'm asking: why is 'WITH KEY' exceptional? Why is it possible to use only the '=' operator but not 'EQ'?
2016 Aug 08 8:20 AM
Hi Pranay,
I believe, parser first hits the db table and then compare what are records have the same fields which are passed as a parameter using EQ and returns only those records.
But in case of read table, since parser doesn't hit db table, it first assigns value to the field of internal table using '=' and then with the assigned field value, a record is returned.
Thanks,
Anil
2016 Aug 08 8:53 AM
Best practice is use comaparison operator (=,<,>,<>) instead of EQ,GT,LT,NE.
THANKS
2016 Aug 08 10:17 AM
Hello,
Can you please point me to some official documentation about this statement.
Regards.