<?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 dynamically create an Internal Table? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594891#M267266</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT ZCLUST1 . &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Example: how to create a dynamic internal table &lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; &lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The dynamic internal table stucture &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;DATA: BEGIN OF STRUCT OCCURS 10, &lt;/P&gt;&lt;P&gt;    FILDNAME(8) TYPE C, &lt;/P&gt;&lt;P&gt;    ABPTYPE TYPE C, &lt;/P&gt;&lt;P&gt;    LENGTH TYPE I, &lt;/P&gt;&lt;P&gt;END OF STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The dynamic program source table &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;DATA: BEGIN OF INCTABL OCCURS 10, &lt;/P&gt;&lt;P&gt;    LINE(72), &lt;/P&gt;&lt;P&gt;END OF INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: LNG TYPE I, TYPESRTING(6). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Sample dynamic internal table stucture &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'. &lt;/P&gt;&lt;P&gt;APPEND STRUCT. CLEAR STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'. &lt;/P&gt;&lt;P&gt;APPEND STRUCT. CLEAR STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'. &lt;/P&gt;&lt;P&gt;APPEND STRUCT. CLEAR STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create the dynamic internal table definition in the dyn. program &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT STRUCT. &lt;/P&gt;&lt;P&gt;  INCTABL-LINE = STRUCT-FILDNAME. &lt;/P&gt;&lt;P&gt;  LNG = STRLEN( STRUCT-FILDNAME ). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF NOT STRUCT-LENGTH IS INITIAL . &lt;/P&gt;&lt;P&gt;      TYPESRTING(1) = '('. &lt;/P&gt;&lt;P&gt;      TYPESRTING+1 = STRUCT-LENGTH. &lt;/P&gt;&lt;P&gt;      TYPESRTING+5 = ')'. &lt;/P&gt;&lt;P&gt;      CONDENSE TYPESRTING NO-GAPS. &lt;/P&gt;&lt;P&gt;      INCTABL-LINE+LNG = TYPESRTING. &lt;/P&gt;&lt;P&gt;  ENDIF. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  INCTABL-LINE+15 = 'type '. &lt;/P&gt;&lt;P&gt;  INCTABL-LINE+21 = STRUCT-ABPTYPE. &lt;/P&gt;&lt;P&gt;  INCTABL-LINE+22 = ','. &lt;/P&gt;&lt;P&gt;  APPEND INCTABL. &lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'end of dyntab. '. &lt;/P&gt;&lt;P&gt;APPEND INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create the code processes the dynamic internal table &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;INCTABL-LINE = ' '. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'append dyntab.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = ' '. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'endloop.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create and run the dynamic program &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;INSERT REPORT 'zdynpro'(001) FROM INCTABL. &lt;/P&gt;&lt;P&gt;SUBMIT ZDYNPRO. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Vibha &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Please mark all the helpful answers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Oct 2006 12:14:29 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-10-18T12:14:29Z</dc:date>
    <item>
      <title>How to dynamically create an Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594888#M267263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can someone give some help on the dynamic creation of internal table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 02:46:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594888#M267263</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T02:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically create an Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594889#M267264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Below code might give you some idea:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;type-pools : abap.
field-symbols: &amp;lt;dyn_table&amp;gt; type standard table,
               &amp;lt;dyn_wa&amp;gt;,
               &amp;lt;dyn_field&amp;gt;.
data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
   parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

   perform get_structure.
   perform create_dynamic_itab.
* Creates a dyanamic internal table **
   perform get_data.
   perform write_out.

form get_structure.

  data : idetails type abap_compdescr_tab,
         xdetails type abap_compdescr.
  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?= cl_abap_typedescr=&amp;gt;describe_by_name( p_table ).

  idetails[] = ref_table_des-&amp;gt;components[].

  loop at idetails into xdetails.
       clear xfc.
       xfc-fieldname = xdetails-name .
       xfc-datatype = xdetails-type_kind.
       xfc-inttype = xdetails-type_kind.
       xfc-intlen  = xdetails-length." / 2.
       xfc-decimals = xdetails-decimals. " / 2.
       append xfc  to ifc.
  endloop.

endform.

form create_dynamic_itab.
* Create dynamic internal table and assign to FS

   call method cl_alv_table_create=&amp;gt;create_dynamic_table
    exporting
             it_fieldcatalog = ifc
    importing
             ep_table        = dy_table.

   assign dy_table-&amp;gt;* to &amp;lt;dyn_table&amp;gt;.
* Create dynamic work area and assign to FS
   create data dy_line like line of &amp;lt;dyn_table&amp;gt;.
   assign dy_line-&amp;gt;* to &amp;lt;dyn_wa&amp;gt;.

endform.

form get_data.

* Select Data from table.
  select * into table &amp;lt;dyn_table&amp;gt;
     from (p_table).

endform.

form write_out.
* 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.

endform.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Thanks to the Original Contributors.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 02:58:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594889#M267264</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T02:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically create an Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594890#M267265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
  DATA dref TYPE REF TO data.

  FIELD-SYMBOLS: &amp;lt;xyz&amp;gt; TYPE ANY TABLE.

  TRY.
      CREATE DATA dref TYPE STANDARD TABLE OF (tab)
                            WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN dref-&amp;gt;* TO  &amp;lt;xyz&amp;gt;.
    CATCH cx_sy_create_data_error.
      WRITE 'Wrong Database!'.
  ENDTRY.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are done with it...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(tab) can hold any table name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Sandeep Josyula&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Reward if found useful...pl dont forget&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 12:09:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594890#M267265</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T12:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically create an Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594891#M267266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT ZCLUST1 . &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Example: how to create a dynamic internal table &lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; &lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The dynamic internal table stucture &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;DATA: BEGIN OF STRUCT OCCURS 10, &lt;/P&gt;&lt;P&gt;    FILDNAME(8) TYPE C, &lt;/P&gt;&lt;P&gt;    ABPTYPE TYPE C, &lt;/P&gt;&lt;P&gt;    LENGTH TYPE I, &lt;/P&gt;&lt;P&gt;END OF STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The dynamic program source table &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;DATA: BEGIN OF INCTABL OCCURS 10, &lt;/P&gt;&lt;P&gt;    LINE(72), &lt;/P&gt;&lt;P&gt;END OF INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: LNG TYPE I, TYPESRTING(6). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Sample dynamic internal table stucture &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'. &lt;/P&gt;&lt;P&gt;APPEND STRUCT. CLEAR STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'. &lt;/P&gt;&lt;P&gt;APPEND STRUCT. CLEAR STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'. &lt;/P&gt;&lt;P&gt;APPEND STRUCT. CLEAR STRUCT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create the dynamic internal table definition in the dyn. program &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT STRUCT. &lt;/P&gt;&lt;P&gt;  INCTABL-LINE = STRUCT-FILDNAME. &lt;/P&gt;&lt;P&gt;  LNG = STRLEN( STRUCT-FILDNAME ). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF NOT STRUCT-LENGTH IS INITIAL . &lt;/P&gt;&lt;P&gt;      TYPESRTING(1) = '('. &lt;/P&gt;&lt;P&gt;      TYPESRTING+1 = STRUCT-LENGTH. &lt;/P&gt;&lt;P&gt;      TYPESRTING+5 = ')'. &lt;/P&gt;&lt;P&gt;      CONDENSE TYPESRTING NO-GAPS. &lt;/P&gt;&lt;P&gt;      INCTABL-LINE+LNG = TYPESRTING. &lt;/P&gt;&lt;P&gt;  ENDIF. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  INCTABL-LINE+15 = 'type '. &lt;/P&gt;&lt;P&gt;  INCTABL-LINE+21 = STRUCT-ABPTYPE. &lt;/P&gt;&lt;P&gt;  INCTABL-LINE+22 = ','. &lt;/P&gt;&lt;P&gt;  APPEND INCTABL. &lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'end of dyntab. '. &lt;/P&gt;&lt;P&gt;APPEND INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create the code processes the dynamic internal table &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;INCTABL-LINE = ' '. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'append dyntab.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = ' '. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;INCTABL-LINE = 'endloop.'. APPEND INCTABL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create and run the dynamic program &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;INSERT REPORT 'zdynpro'(001) FROM INCTABL. &lt;/P&gt;&lt;P&gt;SUBMIT ZDYNPRO. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Vibha &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Please mark all the helpful answers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2006 12:14:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-dynamically-create-an-internal-table/m-p/1594891#M267266</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-18T12:14:29Z</dc:date>
    </item>
  </channel>
</rss>

