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 only

SELECT * in a join using Open SQL

alejandro_bindi
Active Contributor
0 Likes
1,047

In a table join, how to select all fields from table1 (without having to write them one by one) and only some of table2?

I was trying something like this but it doesn't work:

DATA: BEGIN OF i_data OCCURS 0.
        INCLUDE STRUCTURE zt1.
DATA:   field4 TYPE zt2-field4,
      END OF i_data.

SELECT z1~* z2~field4
INTO TABLE i_data
FROM zt1 AS z1
  INNER JOIN zt2 AS z2
    ON z1~field1 = z2~field1 AND
       z1~field2 = z2~field2 AND
       z1~field3 = z2~field3
WHERE...

Points will be rewarded for helpful answers.

Many thanks

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
907

you must use following syntax:

DATA : BEGIN OF fields OCCURS 0,
       name LIKE dd03l-fieldname,
       END OF fields.

fill table fields from DD02L with tables z1 and z2:

concatenate Z1~ dd03l-fieldname into fields-name.



SELECT (fields) 
INTO TABLE i_data
FROM zt1 AS z1
  INNER JOIN zt2 AS z2
    ON z1~field1 = z2~field1 AND
       z1~field2 = z2~field2 AND
       z1~field3 = z2~field3
WHERE...

A.

6 REPLIES 6
Read only

andreas_mann3
Active Contributor
0 Likes
908

you must use following syntax:

DATA : BEGIN OF fields OCCURS 0,
       name LIKE dd03l-fieldname,
       END OF fields.

fill table fields from DD02L with tables z1 and z2:

concatenate Z1~ dd03l-fieldname into fields-name.



SELECT (fields) 
INTO TABLE i_data
FROM zt1 AS z1
  INNER JOIN zt2 AS z2
    ON z1~field1 = z2~field1 AND
       z1~field2 = z2~field2 AND
       z1~field3 = z2~field3
WHERE...

A.

Read only

0 Likes
907

Thanks Andreas, so the only way is that (building dynamically the fields list)?

Read only

Former Member
0 Likes
907

Hi Alejandro,

Select A* Bmatnr Bwerks into table itab from maar as a inner join marc as B on Amatnr = B~matnr

where A~matnr in s_matnr.

rewad points if helpful.

Regards,

Hemant

Read only

0 Likes
907

Hemant, your code is the same as the one i've tried and returns the same error: "Unknown column name "A~*". not determined until runtime, you cannot specify a field list.

Read only

ferry_lianto
Active Contributor
0 Likes
907

Hi,

Please try this.


DATA: BEGIN OF I_DATA OCCURS 0.
        INCLUDE STRUCTURE ZT1.
DATA:   FIELD4 TYPE ZT2-FIELD4,
      END OF I_DATA.
 
SELECT *
INTO CORRESPONDING FIELDS OF I_DATA
FROM ZT1 AS Z1
INNER JOIN ZT2 AS Z2
   ON Z1~FIELD1 = Z2~FIELD1 AND
      Z1~FIELD2 = Z2~FIELD2 AND
      Z1~FIELD3 = Z2~FIELD3
WHERE <condition>
  APPEND I_DATA.
ENDSELECT.

Regards,

Ferry Lianto

Read only

0 Likes
907

Hi Ferry, i'd like to avoid INTO CORRESPONDING, however yours is a valid alternative also.

I rewarded points. If someone has other alternatives please add them.