<?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 to declare internal table field reference dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848637#M1474083</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lakshmi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way you want it to work is not possible I think. This is beacuse in &lt;EM&gt;key&lt;/EM&gt; field you can store only references of other data objects i.e. of other table field, not the value itself. You will later need to dereference it using field symbol in order to get value behind it. So the code would look like&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT it_tab1 INTO wa_it_tab1.
get reference of wa_it_tab1-some_field into it_tab-key.  
APPEND it_tab.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So now IT_TAB-KEY holds the reference of SOME_FIELD from IT_TAB1 (not the value!). If you want to know the value you need to dereference it, but you cannot store it directly in this IT_TAB table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
field-symbols &amp;lt;value&amp;gt; type any.

loop at it_tab into wa_it_tab.
   assign wa_it_tab-key to &amp;lt;value&amp;gt;.
   write &amp;lt;value&amp;gt;.  "here you have the value behind this reference
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem which however raises is that when you refresh your original table IT_TAB1, the reference in this new table IT_TAB-KEY will "point" to nothing. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally I don't understand your business requirement. If you want to have &lt;EM&gt;dynamic&lt;/EM&gt; field which holds the &lt;STRONG&gt;value&lt;/STRONG&gt; you have to generate whole table dynamically, then pass the values from the original table to this newly cretead one. This way you can have any fields in that table and populate them with respective values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise going the above way, you can only have a &lt;STRONG&gt;reference&lt;/STRONG&gt; of some other field/data objects (but not the value). This will gone after the referencing object is gone too. Assuming above you have to use the &lt;EM&gt;dynamic table generation&lt;/EM&gt; rather that &lt;EM&gt;generic&lt;/EM&gt; field which holds only a reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is clear&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 May 2010 06:49:29 GMT</pubDate>
    <dc:creator>MarcinPciak</dc:creator>
    <dc:date>2010-05-05T06:49:29Z</dc:date>
    <item>
      <title>How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848631#M1474077</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 have a requirement to declare the internal table field reference dynamically. I would know the field reference only during runtime and at that time, I accordingly need to build the internal table and that will be used later for different purpose. The structure of the internal table should appear as mentioned below for better understaning. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DATA: BEGIN OF it_tab OCCURS 0,&lt;/P&gt;&lt;P&gt;                  key LIKE &amp;lt;dynamic&amp;gt;,&lt;/P&gt;&lt;P&gt;                  text LIKE t179t-vtext,&lt;/P&gt;&lt;P&gt;              END OF it_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &amp;lt;Dynamic&amp;gt; - dynamic field reference is known at the run time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Please help me as how to declare this internal table having dynamic field reference.  &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;&lt;/P&gt;&lt;P&gt;  Lakshmi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 13:45:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848631#M1474077</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-03T13:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848632#M1474078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lakshmi,&lt;/P&gt;&lt;P&gt;This is one of the way to create Dynamic Internal Table..&lt;/P&gt;&lt;P&gt;Check this may help u..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PARAMETERS : p_table(10) TYPE C. &lt;/P&gt;&lt;P&gt;  DATA: w_tabname TYPE w_tabname,             &lt;/P&gt;&lt;P&gt;        w_dref TYPE REF TO data,              &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  FIELD-SYMBOLS: &amp;lt;t_itab&amp;gt; TYPE ANY TABLE.  &lt;/P&gt;&lt;P&gt;  w_tabname = p_table.  &lt;/P&gt;&lt;P&gt;  CREATE DATA w_dref TYPE TABLE OF (w_tabname). &lt;/P&gt;&lt;P&gt;  ASSIGN w_dref-&amp;gt;* TO &amp;lt;t_itab&amp;gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT * &lt;/P&gt;&lt;P&gt;    FROM (w_tabname) UP TO 20 ROWS &lt;/P&gt;&lt;P&gt;    INTO TABLE &amp;lt;t_itab&amp;gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;Krishna Chaitanya G&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 14:11:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848632#M1474078</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-03T14:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848633#M1474079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Krishna,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Thank you for the response. But my requirement is different from the code you have provided. I do not have my internal table structure referring to a particular table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  The main point here is that the internal table field reference is dynamic. The example I have provided shows my requirement.&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;&lt;/P&gt;&lt;P&gt;Lakshmi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 14:17:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848633#M1474079</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-03T14:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848634#M1474080</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;Try to see the references of the class cl_alv_table_create, static method create_dynamic_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kleber Santos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 16:32:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848634#M1474080</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-03T16:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848635#M1474081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What I understand is that you want the &lt;STRONG&gt;field&lt;/STRONG&gt; of a table be dynamic, not a &lt;STRONG&gt;table&lt;/STRONG&gt; itself. Is that right?&lt;/P&gt;&lt;P&gt;For this you can simply declare that field as &lt;EM&gt;generic&lt;/EM&gt; field (reference to any type). During runtime you can hold any reference there. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF it_tab OCCURS 0,
key TYPE REF TO DATA,    "generic field
...
END OF it_tab.

"during runtime
GET REFERENCE OF ... TO itab-key.  "just get the reference of any field here
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can also use that field when passing different references (known at runtime). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note!&lt;/P&gt;&lt;P&gt;You cannot declare the field like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
key LIKE some_field.  "some_field known at runtime
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Syntax error will be raised in the above statement, as during compilation &lt;EM&gt;some_field&lt;/EM&gt; is not a type itself. &lt;/P&gt;&lt;P&gt;So you must handle that with &lt;EM&gt;data reference&lt;/EM&gt; or if you really want that field receive dynamic type at runtime, you will have to create a subroutine pool wherein you place all the code of the program and then submit that program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more info refer &lt;A href="http://www.sapdev.co.uk/tips/dynamic/dyn_prog.htm" target="test_blank"&gt;http://www.sapdev.co.uk/tips/dynamic/dyn_prog.htm&lt;/A&gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 16:56:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848635#M1474081</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-05-03T16:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848636#M1474082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marcin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   Thank you for the help. I have a problem if i declare internal table the way it was suggested when i populate the values to this internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   I have to populate the values from other internal table to this internal table and while populating the values, i get error message that the value is not convertible to KEY field. Please suggest. Example is provided below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DATA: BEGIN OF it_tab OCCURS 0,&lt;/P&gt;&lt;P&gt;                 key TYPE REF TO data,&lt;/P&gt;&lt;P&gt;                 text TYPE t179t-vtext,&lt;/P&gt;&lt;P&gt;              END OF it_tab.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; LOOP AT it_tab1 INTO wa_it_tab1.&lt;/P&gt;&lt;P&gt;    it_tab-key = wa_it_tab1-&amp;lt;field1&amp;gt;.   "This is where i have the problem as I cannot directly assign the value of &lt;/P&gt;&lt;P&gt;                                                           " wa_it_tab1- &amp;lt;field1&amp;gt; to  it_tab-key&lt;/P&gt;&lt;P&gt;   APPEND it_tab.&lt;/P&gt;&lt;P&gt;ENDLOOP.&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;Lakshmi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 17:40:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848636#M1474082</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-04T17:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848637#M1474083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lakshmi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way you want it to work is not possible I think. This is beacuse in &lt;EM&gt;key&lt;/EM&gt; field you can store only references of other data objects i.e. of other table field, not the value itself. You will later need to dereference it using field symbol in order to get value behind it. So the code would look like&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT it_tab1 INTO wa_it_tab1.
get reference of wa_it_tab1-some_field into it_tab-key.  
APPEND it_tab.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So now IT_TAB-KEY holds the reference of SOME_FIELD from IT_TAB1 (not the value!). If you want to know the value you need to dereference it, but you cannot store it directly in this IT_TAB table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
field-symbols &amp;lt;value&amp;gt; type any.

loop at it_tab into wa_it_tab.
   assign wa_it_tab-key to &amp;lt;value&amp;gt;.
   write &amp;lt;value&amp;gt;.  "here you have the value behind this reference
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem which however raises is that when you refresh your original table IT_TAB1, the reference in this new table IT_TAB-KEY will "point" to nothing. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally I don't understand your business requirement. If you want to have &lt;EM&gt;dynamic&lt;/EM&gt; field which holds the &lt;STRONG&gt;value&lt;/STRONG&gt; you have to generate whole table dynamically, then pass the values from the original table to this newly cretead one. This way you can have any fields in that table and populate them with respective values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise going the above way, you can only have a &lt;STRONG&gt;reference&lt;/STRONG&gt; of some other field/data objects (but not the value). This will gone after the referencing object is gone too. Assuming above you have to use the &lt;EM&gt;dynamic table generation&lt;/EM&gt; rather that &lt;EM&gt;generic&lt;/EM&gt; field which holds only a reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is clear&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 06:49:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848637#M1474083</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-05-05T06:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to declare internal table field reference dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848638#M1474084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Create a dynamic table using field catalog. You can create the field catalog based on your required fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this link......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://wiki.sdn.sap.com/wiki/display/ABAP/Dynamic" target="test_blank"&gt;https://wiki.sdn.sap.com/wiki/display/ABAP/Dynamic&lt;/A&gt;&lt;EM&gt;Internal&lt;/EM&gt;table&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 08:53:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-declare-internal-table-field-reference-dynamically/m-p/6848638#M1474084</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-05T08:53:17Z</dc:date>
    </item>
  </channel>
</rss>

