<?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 Table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878183#M675778</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can try something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.

type-pools: slis.

field-symbols: &amp;lt;dyn_table&amp;gt; type standard table,
               &amp;lt;dyn_wa&amp;gt;.

data: it_alvfc type slis_t_fieldcat_alv,
      wa_alvfc type slis_fieldcat_alv,
      it_fldcat type lvc_t_fcat,
      wa_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.

start-of-selection.

* build the dynamic internal table
  perform build_dyn_itab.

* write 5 records to the alv grid
  do 5 times.
    perform build_report.
  enddo.

* call the alv grid.
  perform call_alv.


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

* Create the dynamic internal table
  data: new_table type ref to data,
        new_line  type ref to data.

* Create fields .
  do p_flds times.
    clear wa_fldcat.
    wa_fldcat-fieldname = sy-index.
    wa_fldcat-datatype  = 'CHAR'.
    wa_fldcat-intlen    = 5.
    append wa_fldcat to it_fldcat .
  enddo.

* 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;.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

* Fill some values into the dynamic internal table

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: &amp;lt;fs1&amp;gt;.

  do p_flds times.

    index = sy-index.

* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.

    assign component  index  of structure &amp;lt;dyn_wa&amp;gt; to &amp;lt;fs1&amp;gt;.
    &amp;lt;fs1&amp;gt; =  fieldvalue.

  enddo.

* Append to the dynamic internal table
  append &amp;lt;dyn_wa&amp;gt; to &amp;lt;dyn_table&amp;gt;.


endform.

************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.

* Build FC for ALV
  loop at  it_fldcat into wa_fldcat.
    wa_alvfc-fieldname = wa_fldcat-fieldname.
    wa_alvfc-seltext_s = sy-tabix.
    wa_alvfc-outputlen = wa_fldcat-intlen.
    append wa_alvfc to it_alvfc.
  endloop.

* Call ABAP List Viewer (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat = it_alvfc
       tables
            t_outtab    = &amp;lt;dyn_table&amp;gt;.

endform.

&lt;/CODE&gt;&lt;/PRE&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>Wed, 19 Sep 2007 16:24:33 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2007-09-19T16:24:33Z</dc:date>
    <item>
      <title>Dynamic Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878182#M675777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have got a selection screen in which a person will enter months, so how may so ever months increases the table columns should also increase automatically according to given criteria.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does any one have a code for this? if yes then please do send me a very simple code so that it could be easily understood &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2007 16:15:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878182#M675777</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-19T16:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878183#M675778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can try something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.

type-pools: slis.

field-symbols: &amp;lt;dyn_table&amp;gt; type standard table,
               &amp;lt;dyn_wa&amp;gt;.

data: it_alvfc type slis_t_fieldcat_alv,
      wa_alvfc type slis_fieldcat_alv,
      it_fldcat type lvc_t_fcat,
      wa_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.

start-of-selection.

* build the dynamic internal table
  perform build_dyn_itab.

* write 5 records to the alv grid
  do 5 times.
    perform build_report.
  enddo.

* call the alv grid.
  perform call_alv.


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

* Create the dynamic internal table
  data: new_table type ref to data,
        new_line  type ref to data.

* Create fields .
  do p_flds times.
    clear wa_fldcat.
    wa_fldcat-fieldname = sy-index.
    wa_fldcat-datatype  = 'CHAR'.
    wa_fldcat-intlen    = 5.
    append wa_fldcat to it_fldcat .
  enddo.

* 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;.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

* Fill some values into the dynamic internal table

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: &amp;lt;fs1&amp;gt;.

  do p_flds times.

    index = sy-index.

* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.

    assign component  index  of structure &amp;lt;dyn_wa&amp;gt; to &amp;lt;fs1&amp;gt;.
    &amp;lt;fs1&amp;gt; =  fieldvalue.

  enddo.

* Append to the dynamic internal table
  append &amp;lt;dyn_wa&amp;gt; to &amp;lt;dyn_table&amp;gt;.


endform.

************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.

* Build FC for ALV
  loop at  it_fldcat into wa_fldcat.
    wa_alvfc-fieldname = wa_fldcat-fieldname.
    wa_alvfc-seltext_s = sy-tabix.
    wa_alvfc-outputlen = wa_fldcat-intlen.
    append wa_alvfc to it_alvfc.
  endloop.

* Call ABAP List Viewer (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat = it_alvfc
       tables
            t_outtab    = &amp;lt;dyn_table&amp;gt;.

endform.

&lt;/CODE&gt;&lt;/PRE&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>Wed, 19 Sep 2007 16:24:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878183#M675778</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-09-19T16:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878184#M675779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi Usman,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you have to call the method CREATE_DYNAMIC_TABLE of class CL_ALV_TABLE_CREATE. You have to import a table with the fieldcatalog. When it is done you can reach the dynamic internal table with ASSIGN-ing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can insert code as well, if you want to, but it is not short and not simple... &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ec&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2007 16:25:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table/m-p/2878184#M675779</guid>
      <dc:creator>JozsefSzikszai</dc:creator>
      <dc:date>2007-09-19T16:25:29Z</dc:date>
    </item>
  </channel>
</rss>

