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 Table With Key syntax - why cannot use 'EQ'?

cuky
Participant
0 Kudos
1,341

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?

5 REPLIES 5

pranay570708
Active Contributor
0 Kudos
579

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.

0 Kudos
579

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'?

0 Kudos
579

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

waqasalikhan
Discoverer
0 Kudos
579

Best practice is use comaparison operator (=,<,>,<>) instead of EQ,GT,LT,NE.

THANKS 


0 Kudos
579

Hello,

Can you please point me to some official documentation about this statement.

Regards.