<?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: Dynamic Internal Tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982338#M704115</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0002.

type-pools: slis.

field-symbols: &amp;lt;dyn_table&amp;gt; type standard table,
               &amp;lt;dyn_wa&amp;gt;,
               &amp;lt;dyn_field&amp;gt;.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.

type-pools : abap.

data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

data: new_table type ref to data,
      new_line  type ref to data,
      wa_it_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.


* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=&amp;gt;describe_by_name( p_table ).
it_details[] = ref_descr-&amp;gt;components[].

loop at it_details into wa_details.
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = wa_details-name .
  wa_it_fldcat-datatype = wa_details-type_kind.
  wa_it_fldcat-inttype = wa_details-type_kind.
  wa_it_fldcat-intlen = wa_details-length.
  wa_it_fldcat-decimals = wa_details-decimals.
  append wa_it_fldcat to it_fldcat .
endloop.

* Create dynamic internal table and assign to FS
call method cl_alv_table_create=&amp;gt;create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table.

assign new_table-&amp;gt;* to &amp;lt;dyn_table&amp;gt;.

* Create dynamic work area and assign to FS
create data new_line like line of &amp;lt;dyn_table&amp;gt;.
assign new_line-&amp;gt;* to &amp;lt;dyn_wa&amp;gt;.

* Select Data from table.
select * into corresponding fields of table &amp;lt;dyn_table&amp;gt;
           from (p_table).

* Write out data from table.
loop at &amp;lt;dyn_table&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.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Oct 2007 13:03:18 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2007-10-26T13:03:18Z</dc:date>
    <item>
      <title>Dynamic Internal Tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982336#M704113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody provide me with eample of creating Dynamic internal tables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Parvez.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 12:54:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982336#M704113</guid>
      <dc:creator>former_member2382</dc:creator>
      <dc:date>2007-10-26T12:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982337#M704114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the sample code...&lt;/P&gt;&lt;P&gt;REPORT ZREPORT_TEST.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPE-POOLS SLIS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;  BEGIN OF T_MARC OCCURS 0,&lt;/P&gt;&lt;P&gt;  MATNR LIKE MARC-MATNR,&lt;/P&gt;&lt;P&gt;  WERKS LIKE MARC-WERKS,&lt;/P&gt;&lt;P&gt;  END OF T_MARC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT MATNR WERKS&lt;/P&gt;&lt;P&gt;  FROM MARC&lt;/P&gt;&lt;P&gt;  INTO TABLE T_MARC UP TO 10 ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;  T_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,&lt;/P&gt;&lt;P&gt;  T_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: NEW_table type  ref to data.&lt;/P&gt;&lt;P&gt;data: new_line  type ref to data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &amp;lt;l_table&amp;gt; TYPE table,&lt;/P&gt;&lt;P&gt;               &amp;lt;l_line&amp;gt;  TYPE ANY,&lt;/P&gt;&lt;P&gt;               &amp;lt;l_field&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;T_FIELDCAT-FIELDNAME = 'MATNR'.&lt;/P&gt;&lt;P&gt;T_FIELDCAT-REF_TABLE = 'MARC'.&lt;/P&gt;&lt;P&gt;APPEND T_FIELDCAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;T_FIELDCAT-FIELDNAME = 'WERKS'.&lt;/P&gt;&lt;P&gt;T_FIELDCAT-REF_TABLE = 'MARC'.&lt;/P&gt;&lt;P&gt;APPEND T_FIELDCAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; call method cl_alv_table_create=&amp;gt;create_dynamic_table&lt;/P&gt;&lt;P&gt;     exporting&lt;/P&gt;&lt;P&gt;       it_fieldcatalog = T_FIELDCAT[]&lt;/P&gt;&lt;P&gt;      importing&lt;/P&gt;&lt;P&gt;        ep_table        = NEW_table .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ASSIGN new_table-&amp;gt;* TO &amp;lt;l_table&amp;gt;.&lt;/P&gt;&lt;P&gt;CREATE DATA new_line LIKE LINE OF &amp;lt;l_table&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN new_line-&amp;gt;* TO &amp;lt;l_line&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT 'MATNR' OF STRUCTURE &amp;lt;l_line&amp;gt; TO &amp;lt;l_field&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;L_FIELD&amp;gt; = '12345'.&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT 'WERKS' OF STRUCTURE &amp;lt;l_line&amp;gt; TO &amp;lt;l_field&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;L_FIELD&amp;gt; = '1000'.&lt;/P&gt;&lt;P&gt;APPEND &amp;lt;L_LINE&amp;gt; TO &amp;lt;L_TABLE&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT 'MATNR' OF STRUCTURE &amp;lt;l_line&amp;gt; TO &amp;lt;l_field&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;L_FIELD&amp;gt; = '52349'.&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT 'WERKS' OF STRUCTURE &amp;lt;l_line&amp;gt; TO &amp;lt;l_field&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;L_FIELD&amp;gt; = '2000'.&lt;/P&gt;&lt;P&gt;APPEND &amp;lt;L_LINE&amp;gt; TO &amp;lt;L_TABLE&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*LOOP AT &amp;lt;L_TABLE&amp;gt; INTO &amp;lt;L_LINE&amp;gt;.&lt;/P&gt;&lt;P&gt;*WRITE: / &amp;lt;L_LINE&amp;gt;.&lt;/P&gt;&lt;P&gt;*ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT T_FIELDCAT.&lt;/P&gt;&lt;P&gt;T_FCAT-FIELDNAME = T_FIELDCAT-FIELDNAME.&lt;/P&gt;&lt;P&gt;T_FCAT-REF_TABNAME = T_FIELDCAT-REF_TABLE.&lt;/P&gt;&lt;P&gt;APPEND T_FCAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt; EXPORTING&lt;/P&gt;&lt;P&gt;   IT_FIELDCAT                       = T_FCAT[]&lt;/P&gt;&lt;P&gt;  TABLES&lt;/P&gt;&lt;P&gt;    t_outtab                          = &amp;lt;l_table&amp;gt;&lt;/P&gt;&lt;P&gt; EXCEPTIONS&lt;/P&gt;&lt;P&gt;   PROGRAM_ERROR                     = 1&lt;/P&gt;&lt;P&gt;   OTHERS                            = 2&lt;/P&gt;&lt;P&gt;          .&lt;/P&gt;&lt;P&gt;IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt; MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;P&gt;         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:02:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982337#M704114</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982338#M704115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0002.

type-pools: slis.

field-symbols: &amp;lt;dyn_table&amp;gt; type standard table,
               &amp;lt;dyn_wa&amp;gt;,
               &amp;lt;dyn_field&amp;gt;.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.

type-pools : abap.

data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

data: new_table type ref to data,
      new_line  type ref to data,
      wa_it_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.


* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=&amp;gt;describe_by_name( p_table ).
it_details[] = ref_descr-&amp;gt;components[].

loop at it_details into wa_details.
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = wa_details-name .
  wa_it_fldcat-datatype = wa_details-type_kind.
  wa_it_fldcat-inttype = wa_details-type_kind.
  wa_it_fldcat-intlen = wa_details-length.
  wa_it_fldcat-decimals = wa_details-decimals.
  append wa_it_fldcat to it_fldcat .
endloop.

* Create dynamic internal table and assign to FS
call method cl_alv_table_create=&amp;gt;create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table.

assign new_table-&amp;gt;* to &amp;lt;dyn_table&amp;gt;.

* Create dynamic work area and assign to FS
create data new_line like line of &amp;lt;dyn_table&amp;gt;.
assign new_line-&amp;gt;* to &amp;lt;dyn_wa&amp;gt;.

* Select Data from table.
select * into corresponding fields of table &amp;lt;dyn_table&amp;gt;
           from (p_table).

* Write out data from table.
loop at &amp;lt;dyn_table&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.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 13:03:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982338#M704115</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-10-26T13:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982339#M704116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Parvez,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the latest way of creating and using dynamic internal tables.&lt;/P&gt;&lt;P&gt;we have 2 concepts called : RTTI and RTTC. Both together called as RTTS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just copy the below code into se38 and execute. Give any table name it will create a dynamic table and show the contents in ALV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  zgs_rttc.

 PARAMETERS   p_par TYPE dd02l-tabname.

 DATA : r_descr TYPE REF TO cl_abap_structdescr,
        r_tab TYPE REF TO cl_abap_tabledescr.

 DATA : itab TYPE REF TO data.
 FIELD-SYMBOLS : &amp;lt;fs&amp;gt; TYPE STANDARD TABLE.

 START-OF-SELECTION.

r_descr ?= cl_abap_structdescr=&amp;gt;describe_by_name( p_par ).


CALL METHOD cl_abap_tabledescr=&amp;gt;create
 EXPORTING
   p_line_type = r_descr
 RECEIVING
   p_result    = r_tab .


CREATE DATA itab TYPE HANDLE r_tab.

ASSIGN itab-&amp;gt;* TO &amp;lt;fs&amp;gt;.

 SELECT *
   FROM (p_par)
   INTO TABLE &amp;lt;fs&amp;gt;
     UP TO 10 ROWS.

 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_structure_name = p_par
   TABLES
     t_outtab         = &amp;lt;fs&amp;gt;.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to know more about these concepts do get back to me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful,&lt;/P&gt;&lt;P&gt;Aleem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2007 15:20:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-tables/m-p/2982339#M704116</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-26T15:20:56Z</dc:date>
    </item>
  </channel>
</rss>

