<?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: how do we SELECT the fields dynamically ? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251853#M1631154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From your very thin initial description I would understand that the standard SELECT (column_syntax) might be what you need to use, in conjunction with INTO CORRESPONDING as described by Florian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please read ABAP online help:&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/abapdocu_702/en/abapselect_clause_cols.htm#!ABAP_ALTERNATIVE_3@3@" target="test_blank"&gt;http://help.sap.com/abapdocu_702/en/abapselect_clause_cols.htm#!ABAP_ALTERNATIVE_3@3@&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;The data object column_syntax can be a character-type data object or an internal table with a character-type data type&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Oct 2011 14:17:25 GMT</pubDate>
    <dc:creator>ThomasZloch</dc:creator>
    <dc:date>2011-10-10T14:17:25Z</dc:date>
    <item>
      <title>how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251848#M1631149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  how do we SELECT the fields dynamically ( with only the fields present in the dynamic internal table )?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For eg : If my dynamic internal table has only 4 fields. I need to fetch only these 4 fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 13:40:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251848#M1631149</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-10T13:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251849#M1631150</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;use the technique of field symbol, referencing, Assign component etc of dynamic programming.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;simple exapmle coding is as below,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create variable that can contain referecene to any data&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;dataref TYPE REF TO data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS:&lt;/P&gt;&lt;P&gt;TYPE ANY,&lt;/P&gt;&lt;P&gt;TYPE ANY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS:&lt;/P&gt;&lt;P&gt;p_tab TYPE tabname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create a workarea for the tabel selected on the selection screen&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA dataref TYPE (p_tab).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The variable dataref cannot be accessed directly, so a field symbol is&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;used&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;ASSIGN dataref-&amp;gt;* TO .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM (p_tab) UP TO 10 ROWS&lt;/P&gt;&lt;P&gt;INTO .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NEW-LINE.&lt;/P&gt;&lt;P&gt;DO.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Write all the fields in the record &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;ASSIGN COMPONENT sy-index&lt;/P&gt;&lt;P&gt;OF STRUCTURE &lt;/P&gt;&lt;P&gt;TO .&lt;/P&gt;&lt;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;EXIT.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;WRITE .&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chandra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 13:44:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251849#M1631150</guid>
      <dc:creator>ChandrashekharMahajan</dc:creator>
      <dc:date>2011-10-10T13:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251850#M1631151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try to create select query in a string variable using concatenation based on fields in your internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example:- if your itab contains say field1, field2, field3, make a string say &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;concatenate itab-field in string variable say str_var&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select ( str_var) from table into corresponding field of internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks. Rashi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 13:46:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251850#M1631151</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-10T13:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251851#M1631152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is no statement that does this.&lt;/P&gt;&lt;P&gt;we got one that is quite close to what you need. The addition "INTO CORRESPONDING FIELDS OF" of the select statement.&lt;/P&gt;&lt;P&gt;But as i´m not sure if this transfers everything to application server and then throws away fields that are not needed i would guess this one produces overhead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Only chance i see is to first find out what fields you got in your itab, making use of the statement "loop at component of structure".&lt;/P&gt;&lt;P&gt;Build a list of fields and then select just those.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on the other hand, i´m not even sure you can make the part , where you provide the fields to select, generic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 13:48:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251851#M1631152</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-10T13:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251852#M1631153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the replies. can anyone explain with a better example?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 13:55:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251852#M1631153</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-10T13:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251853#M1631154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From your very thin initial description I would understand that the standard SELECT (column_syntax) might be what you need to use, in conjunction with INTO CORRESPONDING as described by Florian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please read ABAP online help:&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/abapdocu_702/en/abapselect_clause_cols.htm#!ABAP_ALTERNATIVE_3@3@" target="test_blank"&gt;http://help.sap.com/abapdocu_702/en/abapselect_clause_cols.htm#!ABAP_ALTERNATIVE_3@3@&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;The data object column_syntax can be a character-type data object or an internal table with a character-type data type&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 14:17:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251853#M1631154</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2011-10-10T14:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251854#M1631155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES : BEGIN OF ty_m1 ,
         matnr TYPE mara-matnr ,
        END OF ty_m1 ,

        BEGIN OF ty_m2 ,
          matnr TYPE mara-matnr ,
          ernam TYPE mara-ernam ,
        END OF ty_m2 .

DATA : i_m1 TYPE TABLE OF ty_m1 ,
       i_m2 TYPE TABLE OF ty_m2 .

DATA : v_fields TYPE string .

START-OF-SELECTION .
* select with one field
  PERFORM get_fields USING i_m1 CHANGING v_fields .
  WRITE : / v_fields .
  SELECT (v_fields)
    INTO TABLE i_m1
    FROM mara.
*   WHERE matnr IN s_matnr .

* select with two fields
  PERFORM get_fields USING i_m2 CHANGING v_fields .
  WRITE : / v_fields .
  SELECT (v_fields)
    INTO TABLE i_m1
    FROM mara.
*   WHERE matnr IN s_matnr .



*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  get_fields
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --&amp;gt;INTERNAL_TABLE  text
*----------------------------------------------------------------------*
FORM get_fields USING internal_table TYPE ANY TABLE
                CHANGING fields TYPE string .

  DATA:
      wa_ref        TYPE REF TO data,
      desc_table    TYPE REF TO cl_abap_tabledescr,
      desc_struc    TYPE REF TO cl_abap_structdescr.

  FIELD-SYMBOLS:
      &amp;lt;p_data&amp;gt;      TYPE ANY,
      &amp;lt;p_component&amp;gt; TYPE abap_compdescr.

  CLEAR fields .

  CREATE DATA wa_ref LIKE LINE OF internal_table.
  ASSIGN wa_ref-&amp;gt;* TO &amp;lt;p_data&amp;gt;.

  desc_table ?= cl_abap_tabledescr=&amp;gt;describe_by_data( internal_table ).
  desc_struc ?= desc_table-&amp;gt;get_table_line_type( ).

  LOOP AT desc_struc-&amp;gt;components ASSIGNING &amp;lt;p_component&amp;gt;.

    CONCATENATE fields &amp;lt;p_component&amp;gt;-name INTO fields SEPARATED BY space .
  ENDLOOP.

ENDFORM.                    "get_fields&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;part of above code is taken from &lt;SPAN __jive_macro_name="message" id="6104741"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 15:49:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251854#M1631155</guid>
      <dc:creator>Pawan_Kesari</dc:creator>
      <dc:date>2011-10-10T15:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251855#M1631156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Charan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Above replies are correct, but I believe unless your query/table is too heavy, you can live with 'into corresponding fields of' as it provides a very minimum overhead. So, you can simply use * instead of finding the exact column names in your dynamic internal table. Depends more on your scenario that what is table size, no. of fields in DB table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcat
IMPORTING
ep_table = i_dyntab                  "dynamic itab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.

ASSIGN i_dyntab-&amp;gt;* TO &amp;lt;f_dyntable&amp;gt;.              "&amp;lt;f_dyntable&amp;gt; behaves a normal itab now

sellect * from ztable into CORRESPONDING FIELDS OF TABLE &amp;lt;f_dyntable&amp;gt;
              where .......................
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Oct 2011 03:14:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251855#M1631156</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-11T03:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: how do we SELECT the fields dynamically ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251856#M1631157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Issue is resolved&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Oct 2011 06:19:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-we-select-the-fields-dynamically/m-p/8251856#M1631157</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-11T06:19:47Z</dc:date>
    </item>
  </channel>
</rss>

