<?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 field(s) dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869674#M930059</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to create field or multiple fields dynamically????&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Requirement :&lt;/P&gt;&lt;P&gt;In "Z" table lets say there are 2 entries. Structure of "Z" table as follows: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    TableName type tabname&lt;/P&gt;&lt;P&gt;    fieldname type field&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;entries of Z table will be e.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     TableName  |  fieldname&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="----------------------------------------------" /&gt;&lt;P&gt;      VBAK        |   SPART&lt;/P&gt;&lt;P&gt;       MARA      |    MATNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, i will get these two entries into internal table. Using thsese two entries i want to declare two variable dynamically.  e.g. &lt;/P&gt;&lt;P&gt;V TYPE VBAK-SPART&lt;/P&gt;&lt;P&gt;V1 TYPE MARA-MATNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;V, V1 should be declare dynamically.&lt;/P&gt;&lt;P&gt;if the entries are 5 then program should declare five variables.&lt;/P&gt;&lt;P&gt;This should be done dynamically. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any Sample code???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;&lt;P&gt;Saurabh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 May 2008 05:41:49 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-05-22T05:41:49Z</dc:date>
    <item>
      <title>create field(s) dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869674#M930059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to create field or multiple fields dynamically????&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Requirement :&lt;/P&gt;&lt;P&gt;In "Z" table lets say there are 2 entries. Structure of "Z" table as follows: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    TableName type tabname&lt;/P&gt;&lt;P&gt;    fieldname type field&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;entries of Z table will be e.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     TableName  |  fieldname&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="----------------------------------------------" /&gt;&lt;P&gt;      VBAK        |   SPART&lt;/P&gt;&lt;P&gt;       MARA      |    MATNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, i will get these two entries into internal table. Using thsese two entries i want to declare two variable dynamically.  e.g. &lt;/P&gt;&lt;P&gt;V TYPE VBAK-SPART&lt;/P&gt;&lt;P&gt;V1 TYPE MARA-MATNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;V, V1 should be declare dynamically.&lt;/P&gt;&lt;P&gt;if the entries are 5 then program should declare five variables.&lt;/P&gt;&lt;P&gt;This should be done dynamically. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any Sample code???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;&lt;P&gt;Saurabh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2008 05:41:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869674#M930059</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-22T05:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: create field(s) dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869675#M930060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is no easy methods. You can try create dynamic structure with variables, for example. But using it is not simple.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: BEGIN OF ITAB OCCURS 0,
        TABLENAME TYPE TABNAME,
        FIELDNAME TYPE FIELDNAME,
      END OF ITAB.
DATA: FCAT TYPE LVC_T_FCAT,
      HCAT TYPE LVC_S_FCAT,
      NUM.
DATA: DREF TYPE REF TO DATA,
      HEAD TYPE REF TO DATA.

FIELD-SYMBOLS: &amp;lt;TABLE&amp;gt; TYPE TABLE,
               &amp;lt;STRUC&amp;gt; TYPE ANY,
               &amp;lt;VARIABLE&amp;gt;.

INITIALIZATION.
  REFRESH ITAB.
  ITAB-TABLENAME = 'VBAK'.
  ITAB-FIELDNAME = 'SPART'.
  APPEND ITAB.
  ITAB-TABLENAME = 'MARA'.
  ITAB-FIELDNAME = 'MATNR'.
  APPEND ITAB.

START-OF-SELECTION.
* Create fieldcatalog
  LOOP AT ITAB.
    " Set variable name
    NUM = NUM + 1.
    CONCATENATE 'V' NUM INTO HCAT-FIELDNAME.

    " Set reference type
    HCAT-REF_TABLE = ITAB-TABLENAME.
    HCAT-REF_FIELD = ITAB-FIELDNAME.

    APPEND HCAT TO FCAT.
  ENDLOOP.

* Create internal table
  CALL METHOD CL_ALV_TABLE_CREATE=&amp;gt;CREATE_DYNAMIC_TABLE
    EXPORTING
      IT_FIELDCATALOG = FCAT
    IMPORTING
      EP_TABLE        = DREF.
  ASSIGN  DREF-&amp;gt;* TO &amp;lt;TABLE&amp;gt;.

* Create header with variables
  CREATE DATA HEAD LIKE LINE OF &amp;lt;TABLE&amp;gt;.
  ASSIGN HEAD-&amp;gt;* TO &amp;lt;STRUC&amp;gt;.

* Get first variable
  ASSIGN COMPONENT 'V1' OF STRUCTURE &amp;lt;STRUC&amp;gt; TO &amp;lt;VARIABLE&amp;gt;.
  SELECT SINGLE SPART FROM VBAK INTO &amp;lt;VARIABLE&amp;gt;.
  WRITE &amp;lt;VARIABLE&amp;gt;.

* Get second variable
  ASSIGN COMPONENT 'V2' OF STRUCTURE &amp;lt;STRUC&amp;gt; TO &amp;lt;VARIABLE&amp;gt;.
  SELECT SINGLE MATNR FROM MARA INTO &amp;lt;VARIABLE&amp;gt;.
  WRITE &amp;lt;VARIABLE&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2008 07:11:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869675#M930060</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-22T07:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: create field(s) dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869676#M930061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Andrey. It works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2008 11:16:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-field-s-dynamically/m-p/3869676#M930061</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-22T11:16:55Z</dc:date>
    </item>
  </channel>
</rss>

