<?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 Create dynamic table using a pre-existing structure from the data dictionar in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533706#M1656879</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;&amp;lt;Subject line changed&amp;gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a dynamic internal table.  I have found examples that build this dynamic table using a pre-existing structure from the data dictionary.  But how can I do this if all I have is the following (values are assigned during program execution, and there could be more than 3 columns) :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data:  gs_comp  TYPE abap_compdescr.

* Column 1
  gs_comp-name       = 'FIELD1'.
  gs_comp-type_kind  = 'CHAR'.
  gs_comp-length     = 4.
  gs_comp-decimals   = 0.

* Column 2
  gs_comp-name       = 'FIELD2'.
  gs_comp-type_kind  = 'QUAN'.
  gs_comp-length     = 13.
  gs_comp-decimals   = 2.

* Column 3
  gs_comp-name       = 'FIELD3'.
  gs_comp-type_kind  = 'CHAR'.
  gs_comp-length     = 10.
  gs_comp-decimals   = 3.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was using CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table but need to come up with a different idea since that method dumps after executing 36 times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;Moderator Message: Please use a more descriptive subject line in future &amp;amp; use the  tags to format your code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Suhas Saha on Jan 24, 2012 9:45 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Jan 2012 21:48:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2012-01-23T21:48:13Z</dc:date>
    <item>
      <title>Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533706#M1656879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;&amp;lt;Subject line changed&amp;gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a dynamic internal table.  I have found examples that build this dynamic table using a pre-existing structure from the data dictionary.  But how can I do this if all I have is the following (values are assigned during program execution, and there could be more than 3 columns) :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data:  gs_comp  TYPE abap_compdescr.

* Column 1
  gs_comp-name       = 'FIELD1'.
  gs_comp-type_kind  = 'CHAR'.
  gs_comp-length     = 4.
  gs_comp-decimals   = 0.

* Column 2
  gs_comp-name       = 'FIELD2'.
  gs_comp-type_kind  = 'QUAN'.
  gs_comp-length     = 13.
  gs_comp-decimals   = 2.

* Column 3
  gs_comp-name       = 'FIELD3'.
  gs_comp-type_kind  = 'CHAR'.
  gs_comp-length     = 10.
  gs_comp-decimals   = 3.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was using CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table but need to come up with a different idea since that method dumps after executing 36 times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;Moderator Message: Please use a more descriptive subject line in future &amp;amp; use the  tags to format your code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Suhas Saha on Jan 24, 2012 9:45 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jan 2012 21:48:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533706#M1656879</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-23T21:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533707#M1656880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;look at [Runtime Type Services|http://wiki.sdn.sap.com/wiki/display/ABAP/Runtime&lt;EM&gt;Type&lt;/EM&gt;Services+(RTTS)].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Graham Robbo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jan 2012 21:54:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533707#M1656880</guid>
      <dc:creator>GrahamRobbo</dc:creator>
      <dc:date>2012-01-23T21:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533708#M1656881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I have been staring at some of those examples, links from that page, but most of them say to use:&lt;/P&gt;&lt;P&gt; cl_abap_structdescr=&amp;gt;describe_by_name( p_tabnam )&lt;/P&gt;&lt;P&gt;But in my case, I don't know p_tabnam.   I just have the attributes: Name, Type_kind, Length, and Decimals for each column.  How would I assign those values to the attributes and append to something declared as TYPE abap_component_tab ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jan 2012 22:23:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533708#M1656881</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-23T22:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533709#M1656882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can pass a table of components to the CREATE method of the CL_ABAP_STRUCTDESCR class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Graham Robbo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jan 2012 22:40:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533709#M1656882</guid>
      <dc:creator>GrahamRobbo</dc:creator>
      <dc:date>2012-01-23T22:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533710#M1656883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;I  was using CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table but need to come up with a different idea since that method dumps after executing 36 times.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is because &lt;EM&gt;cl_alv_table_create=&amp;gt;create_dynamic_table( )&lt;/EM&gt; uses GENERATE SUBROUTINE POOL technique to generate the dynamic internal table &amp;amp; in the current internal session maximum of 36 dynamic subroutine pools can be generated. Hence the dump!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Graham has mentioned dynamic internal tables can easily created using the RTTC classes. And they are easy to use &amp;amp; maintain!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;But in my case, I don't know p_tabnam. I just have the attributes: Name, Type_kind, Length, and Decimals for each column.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Check the class &lt;EM&gt;CL_ABAP_ELEMDESCR&lt;/EM&gt; &amp;amp; the corres. methods &lt;EM&gt;GET_&amp;lt;data_type&amp;gt;( )&lt;/EM&gt; methods. You'll have to use these methods to populate &lt;EM&gt;COMPONENT_TABLE&lt;/EM&gt; param.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: If you are on Release 702, you should use &lt;EM&gt;CL_ABAP_STRUCTDESCR=&amp;gt;GET( )&lt;/EM&gt; method instead of &lt;EM&gt;CREATE( )&lt;/EM&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2012 04:26:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533710#M1656883</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2012-01-24T04:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533711#M1656884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your help.  I have accomplished what I was trying to do.  Feel free to try out my sample code below.  I was also helped by code found at the bottom of the following thread:  &lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="10023523"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  dyn_test
*&amp;amp;---------------------------------------------------------------------*
*    My goal here is to create an internal table called &amp;lt;dyn_tab&amp;gt;
*    I tested the code below and it works good.
*----------------------------------------------------------------------*
form dyn_test.

** v_tab will just be used to put some entries in &amp;lt;dyn_tab&amp;gt;.
  types: begin of v_typ,
           FIELD1(20)  TYPE c,
           FIELD2      TYPE d,
           FIELD3(10)  TYPE p DECIMALS 2,
         end of v_typ.
  data:  v_wa          TYPE v_typ,
         v_tab         TYPE STANDARD TABLE OF v_typ.

  data: w_tab          TYPE STANDARD TABLE OF abap_compdescr,
        w_tab_wa       TYPE abap_compdescr,
        w_typ          TYPE REF TO cl_abap_elemdescr,
        lt_tot_comp    TYPE cl_abap_structdescr=&amp;gt;component_table,
        lt_comp        TYPE cl_abap_structdescr=&amp;gt;component_table,
        la_comp        LIKE LINE OF lt_comp,
        lo_new_type    TYPE REF TO cl_abap_structdescr,
        lo_table_type  TYPE REF TO cl_abap_tabledescr,
        w_tref         TYPE REF TO data,
        w_dy_line      TYPE REF TO data.

  FIELD-SYMBOLS: &amp;lt;dyn_tab&amp;gt;  TYPE STANDARD TABLE,
                 &amp;lt;dyn_wa&amp;gt;,
                 &amp;lt;dyn_field&amp;gt;.

* Add entries to w_fields_tab
  clear w_tab_wa.
  w_tab_wa-name      = 'FIELD1'.
  w_tab_wa-type_kind = 'C'.         "Char field
  w_tab_wa-length    = '20'.
  append w_tab_wa to w_tab.

  clear w_tab_wa.
  w_tab_wa-name      = 'FIELD2'.
  w_tab_wa-type_kind = 'D'.         "Date field
  append w_tab_wa to w_tab.

  clear w_tab_wa.
  w_tab_wa-name      = 'FIELD3'.
  w_tab_wa-type_kind = 'P'.
  w_tab_wa-length    = '10'.
  w_tab_wa-decimals  = '2'.         "Numeric field with decimals
  append w_tab_wa to w_tab.


  LOOP AT w_tab INTO w_tab_wa.

    CASE w_tab_wa-type_kind.
      WHEN 'STRING'.  w_typ = cl_abap_elemdescr=&amp;gt;get_string( ).
      WHEN 'XSTRING'. w_typ = cl_abap_elemdescr=&amp;gt;get_xstring( ).
      WHEN 'I'.       w_typ = cl_abap_elemdescr=&amp;gt;get_i( ).
      WHEN 'F'.       w_typ = cl_abap_elemdescr=&amp;gt;get_f( ).
      WHEN 'D'.       w_typ = cl_abap_elemdescr=&amp;gt;get_d( ).
      WHEN 'T'.       w_typ = cl_abap_elemdescr=&amp;gt;get_t(  ).
      WHEN 'C'.       w_typ = cl_abap_elemdescr=&amp;gt;get_c( p_length = w_tab_wa-length ).
      WHEN 'N'.       w_typ = cl_abap_elemdescr=&amp;gt;get_n( p_length = w_tab_wa-length ).
      WHEN 'X'.       w_typ = cl_abap_elemdescr=&amp;gt;get_x( p_length = w_tab_wa-length ).
      WHEN 'P'.       w_typ = cl_abap_elemdescr=&amp;gt;get_p( p_length = w_tab_wa-length p_decimals = w_tab_wa-decimals ).
    ENDCASE.

* { begin test
*  WRITE: / 'absolute_name:', w_typ-&amp;gt;absolute_name.
*  WRITE: / 'type_kind    :', w_typ-&amp;gt;type_kind.
*  WRITE: / 'length       :', w_typ-&amp;gt;length.
*  WRITE: / 'decimals     :', w_typ-&amp;gt;decimals.
* } end test

    clear la_comp.
    la_comp-type = w_typ.               "Field type
    la_comp-name = w_tab_wa-name.       "Field name   ex: FIELD1
    APPEND la_comp TO lt_tot_comp.      "Add entry to component table

  ENDLOOP.

* Create new type from component table
  lo_new_type = cl_abap_structdescr=&amp;gt;create( lt_tot_comp ).

* Create new table type
  lo_table_type = cl_abap_tabledescr=&amp;gt;create( lo_new_type ).

* Create dynamic internal table and assign to Field Symbol
  CREATE DATA w_tref TYPE HANDLE lo_table_type.
  ASSIGN w_tref-&amp;gt;* TO &amp;lt;dyn_tab&amp;gt;.


*** Put a breakpoint on the next statement here, then take a look
*** at the structure of &amp;lt;dyn_tab&amp;gt; in the debugger.


* Create dynamic work area and assign to Field Symbol
  CREATE DATA w_dy_line LIKE LINE OF &amp;lt;dyn_tab&amp;gt;.
  ASSIGN w_dy_line-&amp;gt;* to &amp;lt;dyn_wa&amp;gt;.

* Now put some data in the dynamic table so we can see the results
  v_wa-FIELD1 = 'Hello World'.
  v_wa-FIELD2 = sy-datum.
  v_wa-FIELD3 = '1234.56'.
  do 5 times.
    append v_wa to v_tab.
  enddo.
  &amp;lt;dyn_tab&amp;gt;[] = v_tab[].

* Write results
  LOOP AT &amp;lt;dyn_tab&amp;gt; into &amp;lt;dyn_wa&amp;gt;.
    do.
      assign component  sy-index
         of structure &amp;lt;dyn_wa&amp;gt; to &amp;lt;dyn_field&amp;gt;.
      if sy-subrc &amp;lt;&amp;gt; 0.
        exit.
      endif.
      if sy-index = 1.
        write: / &amp;lt;dyn_field&amp;gt;.
      else.
        write: &amp;lt;dyn_field&amp;gt;.
      endif.
    enddo.
  ENDLOOP.

  WRITE: / 'Finished.', /.

endform.                                                    "dyn_test
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2012 16:50:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533711#M1656884</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-24T16:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create dynamic table using a pre-existing structure from the data dictionar</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533712#M1656885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good stuff Mark, and thanks for posting your sample code so others can see it. You could also add it to the [Wiki area on RTTC|http://wiki.sdn.sap.com/wiki/display/Snippets/Concept&lt;EM&gt;of&lt;/EM&gt;Run&lt;EM&gt;Time&lt;/EM&gt;Type+Creation] to enhance that information as well? &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Graham Robbo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2012 22:37:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-dynamic-table-using-a-pre-existing-structure-from-the-data-dictionar/m-p/8533712#M1656885</guid>
      <dc:creator>GrahamRobbo</dc:creator>
      <dc:date>2012-01-24T22:37:23Z</dc:date>
    </item>
  </channel>
</rss>

