Select all fields from table A but single field from B?

Lilienthal picture Lilienthal · Jun 23, 2016 · Viewed 8.4k times · Source

Is there a way in ABAP's OpenSQL to simplify the select columns in a JOIN when I want to grab all the fields of one table but only selected fields from the other table(s)?

For instance, in mysql we can simply do:

SELECT  tb1.*, tb2.b, tb2.d
FROM       tableA tb1
INNER JOIN tableB tb2 ON tb1.x = tb2.a

However, OpenSQL does not seem to allow selecting tb1~*, tb2~b, tb2~d so I have to resort to this:

SELECT  tb1.x, tb1.y, tb1.z, tb2.b, tb2.d
FROM       tableA tb1
INNER JOIN tableB tb2 ON tb1.x = tb2.a

For very large tables, especially standard tables, this becomes unwieldy, difficult to read and more annoying to maintain.

Is there a better way to select all fields of tb1 and some fields from tb2?

Answer

Jagger picture Jagger · Jun 23, 2016

Yes, this is possible in the OpenSQL from 7.40 SP08. See this article.

The quotation from the article has that.

Column Specification

In the SELECT list, you can specify all columns of a data source using the syntax data_source~* from 7.40, SP08 on. This can be handy when working with joins.

SELECT scarr~carrname, spfli~*, scarr~url
       FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
       INTO TABLE @DATA(result).

In the previous versions unfortunately one has to specify the columns one by one or use database native SQL for example with ADBC.