INNER JOIN instead of FOR ALL ENTRIES

images/thumbnail.png - Thumbnail

A while ago I showed you that you could SELECT from an internal table. And then I asked myself: if that is possible, shouldn’t INNER JOIN be possible too?

And yes, it is possible.

SELECT kunnr, name1
FROM kna1
INNER JOIN @itbl AS customers ON customers~kunnr = kna1~kunnr
INTO TABLE @DATA(output).

And there you have it. The only thing that needs to be done is name the table using @itbl AS customers.

Unless I’m missing something, this seems to be a better alternative to SELECT FOR ALL ENTRIES.

Why does it seem better to me? Because, according to SAP, FOR ALL ENTRIES executes SELECT for each row in the internal table, running it as many times as there are rows in the internal table. In the case of INNER JOIN, the internal table is sent to the database all at once and then used as if it were a database table.

And you no longer have to stress about having to check if the internal table is not empty before performing the SELECT.

Also, FOR ALL ENTIES has the annoying limitation that, in the WHERE clause, the data type of the variable must be of the same type of the field. For some reason in INNER JOIN this is no longer necessary.

Are these really just advantages or am I missing something and there are drawbacks?

Thank you Silk Road Collection for the photo.

Greetings from Abapinho.