<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: About SQL Query using joins in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343855#M1539786</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can not use A~* or anything similar. But you can specify a list of columns to be selected dynamically. Like in this SAP help example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PERFORM my_select USING `CITYFROM`. 
PERFORM my_select USING `CITYTO`. 

FORM my_select USING l_group TYPE string. 
  DATA: l_columns   TYPE TABLE OF string, 
        l_container TYPE string, 
        l_count     TYPE i. 
  APPEND l_group TO l_columns. 
  APPEND `count( * )` TO l_columns. 
  SELECT (l_columns) 
         FROM spfli 
         INTO (l_container, l_count) 
         GROUP BY (l_group). 
    WRITE: / l_count, l_container. 
  ENDSELECT. 
ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For getting a list of table fields, you can use a selection from table DD03L.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Oct 2010 08:39:50 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-10-15T08:39:50Z</dc:date>
    <item>
      <title>About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343852#M1539783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to write a SQL statement using Joins. The base table "A" has about 100 fields and the join table "B" a few. I would like to fetch all fields from table "A" and a few from table "B".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to write a query wherein I can use "Select * " for table "A" rather than writing all 100 field name in the query? Please keep in mind that I want to use a Join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 07:44:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343852#M1539783</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-15T07:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343853#M1539784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * INTO CORRESPONDING FIELDS OF struc FROM ... JOIN ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and declare struc with the required fields, e.g. include the entire structure of table A and only the desired fields of table B. Also works with INTO CORRESPONDING FIELDS OF TABLE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Make sure there are no duplicate field names in table A and B with the exception of the fields providing the JOIN condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No, INTO CORRESPONDING does not cause performance problems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 07:52:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343853#M1539784</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-10-15T07:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343854#M1539785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using a join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For eg:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select A&lt;SUB&gt;* B&lt;/SUB&gt;fld1 B~fld2.... from A &lt;/P&gt;&lt;P&gt;Join B On B~fld1 = Afld1&lt;/P&gt;&lt;P&gt;into table itab&lt;/P&gt;&lt;P&gt;where...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there is way to write A~* or something which will fetch all fields from table A?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 08:12:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343854#M1539785</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-15T08:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343855#M1539786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can not use A~* or anything similar. But you can specify a list of columns to be selected dynamically. Like in this SAP help example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PERFORM my_select USING `CITYFROM`. 
PERFORM my_select USING `CITYTO`. 

FORM my_select USING l_group TYPE string. 
  DATA: l_columns   TYPE TABLE OF string, 
        l_container TYPE string, 
        l_count     TYPE i. 
  APPEND l_group TO l_columns. 
  APPEND `count( * )` TO l_columns. 
  SELECT (l_columns) 
         FROM spfli 
         INTO (l_container, l_count) 
         GROUP BY (l_group). 
    WRITE: / l_count, l_container. 
  ENDSELECT. 
ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For getting a list of table fields, you can use a selection from table DD03L.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 08:39:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343855#M1539786</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-15T08:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343856#M1539787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand you are using a join. By using SELECT * INTO CORRESPONDING, all the columns with matching names in the joined tables will be moved to the respective columns of your target structure or internal table, without the need to specifiy single columns, also no need for dynamic column list as suggested in the previous post.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 09:51:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343856#M1539787</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-10-15T09:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343857#M1539788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but if there are some fields which are in both tables, SELECT * will be not sufficient. E.g. fields ERNAM, ERDAT, AENAM, AEDAT are such fields which can occur in more tables. In case that a target area will contain these fields, by * with addition INTO CORRESPONDING FIELDS OF, you are not able to specify from which table these values should be taken. In such case, it can be solved by specifying field list dynamically. If it is not that case SELECT * is sufficient. You should check intersection of common fields for tables you are joining. Thereafter you should decide if you can use SELECT *.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe for better understanding, what exactly I am talking about, look at this example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ts_data,
        ernam TYPE mara-ernam,
       END OF ts_data.

DATA: ls_data TYPE ts_data,
      ls_mara TYPE mara,
      ls_mchb TYPE mchb.

START-OF-SELECTION.

  ls_mara-matnr = '1'.
  ls_mchb-matnr = ls_mara-matnr.
  ls_mara-ernam = 'A'.
  ls_mchb-ernam = 'B'.

  INSERT mara FROM ls_mara.
  INSERT mchb FROM ls_mchb.


  SELECT SINGLE * FROM mara INNER JOIN mchb ON mara~matnr = mchb~matnr INTO CORRESPONDING FIELDS OF ls_data.

  ROLLBACK WORK.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You as a developer are not able to tell from which table common fields should be selected. But maybe this is really too specific case...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 10:17:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343857#M1539788</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-15T10:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: About SQL Query using joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343858#M1539789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adrian, that's what I meant with my statement in my first post:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;Make sure there are no duplicate field names in table A and B with the exception of the fields providing the JOIN condition.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but your explanation is much more detailed of course. Your dynamic field list can be a workaround for such cases.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Oct 2010 10:30:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-sql-query-using-joins/m-p/7343858#M1539789</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-10-15T10:30:03Z</dc:date>
    </item>
  </channel>
</rss>

