<?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: Select INTO fields dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509439#M17902</link>
    <description>&lt;P&gt;If you're on 7.4 you can use CORRESPONDING maps:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;select ... from (table_name) into @data(query_results) where ... .
case table_name. 
  when 'T1'.
    itab = corresponding #( query_results mapping f1 = d11
                                                  f2 = d12 ).
  when 'T2'. 
    itab = corresponding #( query_results mapping f1 = d21
                                                  f2 = d22 ).
endcase.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;If you're on 7.5 you can use cl_abap_corresponding which can do the mapping part dynamically, see &lt;A href="https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/index.htm?file=abenreflexive_corresponding_abexa.htm"&gt;doco&lt;/A&gt; and &lt;A href="https://blogs.sap.com/2015/10/29/abap-news-for-release-750-corresponding-again/"&gt;blog 1&lt;/A&gt; and &lt;A href="https://blogs.sap.com/2016/10/21/abap-news-release-7.51-cl_abap_corresponding-completed/"&gt;blog 2&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2017 07:14:01 GMT</pubDate>
    <dc:creator>pokrakam</dc:creator>
    <dc:date>2017-10-11T07:14:01Z</dc:date>
    <item>
      <title>Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509433#M17896</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;
  &lt;P&gt;I have some different source tables that I must read through SELECT statement, but the target tables is always the same. Due to a condition, I must read only one of these tables. The problem is that the names of the fields isn't always changes between the source tables. E.g.:&lt;/P&gt;
  &lt;P&gt;/BIC/ZSRC1 has fields D11 D12 D13&lt;/P&gt;
  &lt;P&gt;/BIC/ZSRC2 has fields D21 D22 D23&lt;/P&gt;
  &lt;P&gt;/BIC/ZSRC3 has fields D31 D32 D33&lt;/P&gt;
  &lt;P&gt;Target table: ITAB has fields F1 F2 F3.&lt;/P&gt;
  &lt;P&gt;Obviously, 1st 2nd and 3rd fields or source tables must be mapped into F1, F2 and F3 fields of target table.&lt;/P&gt;
  &lt;P&gt;Here is an example of the code I've developed that doesn't work:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;v_col_syntax = 'D11 D12 D13'.
v_tab_syntax = '/BIC/ZSRC1'.
v_into_syntax = '(ITAB-F1, ITAB-F2, ITAB-F3)'.

SELECT (v_col_syntax)
        FROM (v_tab_syntax)
        INTO (v_into_syntax)"(gt_txtbuff-code, gt_txtbuff-TXTLG)
        cl_demo_output=&amp;gt;write_data( ITAB ).
ENDSELECT.&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Any suggestions?&lt;/P&gt;
  &lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 18:09:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509433#M17896</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-10-10T18:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509434#M17897</link>
      <description>&lt;P&gt;Has D11, D21, D31 same DDIC type ?&lt;BR /&gt;Has D12, D22, D32 same DDIC type ?&lt;BR /&gt;Has D13, D23, D33 same DDIC type ?&lt;/P&gt;
  &lt;P&gt;Various options to map it:&lt;/P&gt;
  &lt;P&gt;If source and target have different field order&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  DATA:
    v_col_syntax  TYPE string VALUE 'CARRID as F1 CONNID as F2 FLDATE as F3',
    v_tab_syntax  TYPE string VALUE 'SFLIGHT', " BIC/ZSRC1',
    v_into_syntax TYPE string VALUE '(ITAB-F1, ITAB-F2, ITAB-F3)',
    BEGIN OF itab,
      f1 TYPE sflight-carrid,
      f2 TYPE sflight-connid,
      f3 TYPE sflight-fldate,
    END OF itab.

  SELECT (v_col_syntax)
          FROM (v_tab_syntax)
          INTO CORRESPONDING FIELDS OF itab.
    cl_demo_output=&amp;gt;write_data( itab ).
    EXIT.
  ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;or why do you need a dynamic INTO ?&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  SELECT (v_col_syntax)
          FROM (v_tab_syntax)
          INTO (ITAB-F1, ITAB-F2, ITAB-F3).&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;3rd alternative, replace ITAB-F1, ITAB-F2, ITAB-F3 with field-symbols assigned to ITAB-F1, ...&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 20:54:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509434#M17897</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-10-10T20:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509435#M17898</link>
      <description>&lt;P&gt;INTO CORRESPONDING only works when the field names are the same (not the OP's case).&lt;/P&gt;
  &lt;P&gt;I don't get either why dynamic INTO is needed. Get rid of ENDSELECT and just select INTO TABLE. As long as the field type / length is compatible, it will be just put into the internal table fields in sequence.&lt;/P&gt;
  &lt;P&gt;Perhaps OP could share more details.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 21:20:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509435#M17898</guid>
      <dc:creator>Jelena_Perfiljeva</dc:creator>
      <dc:date>2017-10-10T21:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509436#M17899</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;SELECT (v_col_syntax)
  INTO TABLE LT
...&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Where LT - table with 3 fields so first column from select goes to first column of local table, etc.&lt;/P&gt;
  &lt;P&gt;or use &lt;STRONG&gt;AS&lt;/STRONG&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;SELECT field1 AS a, field2 AS b&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 04:41:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509436#M17899</guid>
      <dc:creator>former_member210008</dc:creator>
      <dc:date>2017-10-11T04:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509437#M17900</link>
      <description>&lt;P&gt;Worse, the OP appears to be using a table with header lines. &lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 06:07:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509437#M17900</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-10-11T06:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509438#M17901</link>
      <description>&lt;P&gt;Dynamic creation of data types and usage is well covered. Search for RTTS. &lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 06:08:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509438#M17901</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-10-11T06:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509439#M17902</link>
      <description>&lt;P&gt;If you're on 7.4 you can use CORRESPONDING maps:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;select ... from (table_name) into @data(query_results) where ... .
case table_name. 
  when 'T1'.
    itab = corresponding #( query_results mapping f1 = d11
                                                  f2 = d12 ).
  when 'T2'. 
    itab = corresponding #( query_results mapping f1 = d21
                                                  f2 = d22 ).
endcase.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;If you're on 7.5 you can use cl_abap_corresponding which can do the mapping part dynamically, see &lt;A href="https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/index.htm?file=abenreflexive_corresponding_abexa.htm"&gt;doco&lt;/A&gt; and &lt;A href="https://blogs.sap.com/2015/10/29/abap-news-for-release-750-corresponding-again/"&gt;blog 1&lt;/A&gt; and &lt;A href="https://blogs.sap.com/2016/10/21/abap-news-release-7.51-cl_abap_corresponding-completed/"&gt;blog 2&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 07:14:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509439#M17902</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2017-10-11T07:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Select INTO fields dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509440#M17903</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;for the v_col_syntax you may use a STRING_TABLE. Each line represents a field (using joins it is &amp;lt;tabname&amp;gt;~fieldname) eventually followed by ALIAS, i.e. &amp;lt;field-a&amp;gt; AS &amp;lt;field-b&amp;gt;. Do not use the angle brackets, that's documentary syntax. If you use INTO CORRESPONDING FIELDS OF, you can always one structure contatinig all possible fields or you may even create a matching structure dynamically.&lt;/P&gt;
  &lt;P&gt;Jus my 2 cents&lt;/P&gt;
  &lt;P&gt;Regards Clemens&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 10:17:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-fields-dynamically/m-p/509440#M17903</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2017-10-11T10:17:17Z</dc:date>
    </item>
  </channel>
</rss>

