<?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 declaration for variable. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080083#M97570</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arpit Gattani,&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    To store output of an dynamic Select statement you can use dynamic data objects and field symbols. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    To create a data object dynamically during a program, you need a data reference variable and the following statement: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA &amp;lt;dref&amp;gt; TYPE &amp;lt;type&amp;gt;|LIKE &amp;lt;obj&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This statement creates a data object in the internal session of the current ABAP program. After the statement, the data reference in the data reference variable &amp;lt;dref&amp;gt; points to the object. The data object that you create does not have its own name. You can only address it using a data reference variable. To access the contents of the data object, you must dereference the data reference. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must specify the data type of the object using the TYPE or LIKE addition. In the TYPE addition, you can specify the data type dynamically as the contents of a field (this is not possible with other uses of TYPE). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA &amp;lt;dref&amp;gt; TYPE (&amp;lt;name&amp;gt;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here, &amp;lt;name&amp;gt; is the name of a field that contains the name of the required data type. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;A specific field is read from database table X031L. Neither the field name nor the table name is known until runtime: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Read a field from the table X031L&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS:&lt;/P&gt;&lt;P&gt;  TAB_NAME    LIKE SY-TNAME,           "Table name&lt;/P&gt;&lt;P&gt;  TAB_COMP    LIKE X031L-FIELDNAME,   "Field name&lt;/P&gt;&lt;P&gt;  ANZAHL      TYPE I DEFAULT 10.       Number of lines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &amp;lt;WA&amp;gt;   TYPE ANY,&lt;/P&gt;&lt;P&gt;               &amp;lt;COMP&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DATA: WA_REF TYPE REF TO DATA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CREATE DATA WA_REF TYPE (TAB_NAME). "Suitable work area&lt;/P&gt;&lt;P&gt;  ASSIGN WA_REF-&amp;gt;* TO &amp;lt;WA&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM (TAB_NAME) INTO &amp;lt;WA&amp;gt; &lt;/P&gt;&lt;P&gt;  UP TO anzahl ROWS.&lt;/P&gt;&lt;P&gt;  WRITE: / TAB_COMP, &amp;lt;COMP&amp;gt;.&lt;/P&gt;&lt;P&gt;  ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dont Forget to give points if it helps ;&amp;gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Rakesh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Dec 2005 10:46:14 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-12-26T10:46:14Z</dc:date>
    <item>
      <title>dynamic declaration for variable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080079#M97566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can we declare a variable dynamic with varing data type.&lt;/P&gt;&lt;P&gt;My req is i have to define a variable to store output from a dynamic select statement. Now since SELECT is dynamic, its output type changes each time and for the same I need a variable defined dynamically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Arpit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Dec 2005 22:41:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080079#M97566</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-23T22:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic declaration for variable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080080#M97567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may be able to use field symbols for this.  Do you have experience with field symbols?  Here is an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;report zrich_0002.


data: matnr type mara-matnr.
data: ersda type mara-ersda.
data: brgew type mara-brgew.
data: field(20) type c.

field-symbols: &amp;lt;fs&amp;gt;.


parameters: p_matnr type mara-matnr.

start-of-selection.

  assign matnr to &amp;lt;fs&amp;gt;.
  select single matnr into &amp;lt;fs&amp;gt; from mara
               where matnr = p_matnr.
  write:/ &amp;lt;fs&amp;gt;.


  assign ersda to &amp;lt;fs&amp;gt;.
  select single ersda into &amp;lt;fs&amp;gt; from mara
               where matnr = p_matnr.
  write:/ &amp;lt;fs&amp;gt;.

  assign brgew to &amp;lt;fs&amp;gt;.
  select single brgew into &amp;lt;fs&amp;gt; from mara
               where matnr = p_matnr.
  write:/ &amp;lt;fs&amp;gt;.&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>Fri, 23 Dec 2005 23:12:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080080#M97567</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-23T23:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic declaration for variable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080081#M97568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Rich,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did the same thing but it is giving problem with data type DEC. Following is the error from dump.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    Since the caller of the procedure could not have expected this exception       &lt;/P&gt;&lt;P&gt;     to occur, the running program was terminated.                                 &lt;/P&gt;&lt;P&gt;    The reason for the exception is:                                               &lt;/P&gt;&lt;P&gt;    The data read during a SELECT access could not be inserted into the            &lt;/P&gt;&lt;P&gt;    target field.                                                                  &lt;/P&gt;&lt;P&gt;    Either conversion is not supported for the target field's type or the          &lt;/P&gt;&lt;P&gt;    target field is too short to accept the value or the data are not in a         &lt;/P&gt;&lt;P&gt;    form that the target field can accept                                          &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Arpit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Arpit Gattani&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Dec 2005 00:07:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080081#M97568</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-24T00:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic declaration for variable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080082#M97569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Define the catching field as....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data: the_field(13) type p decimals 3.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does it work now?&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>Sat, 24 Dec 2005 01:27:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080082#M97569</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-24T01:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic declaration for variable.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080083#M97570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arpit Gattani,&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    To store output of an dynamic Select statement you can use dynamic data objects and field symbols. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    To create a data object dynamically during a program, you need a data reference variable and the following statement: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA &amp;lt;dref&amp;gt; TYPE &amp;lt;type&amp;gt;|LIKE &amp;lt;obj&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This statement creates a data object in the internal session of the current ABAP program. After the statement, the data reference in the data reference variable &amp;lt;dref&amp;gt; points to the object. The data object that you create does not have its own name. You can only address it using a data reference variable. To access the contents of the data object, you must dereference the data reference. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must specify the data type of the object using the TYPE or LIKE addition. In the TYPE addition, you can specify the data type dynamically as the contents of a field (this is not possible with other uses of TYPE). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA &amp;lt;dref&amp;gt; TYPE (&amp;lt;name&amp;gt;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here, &amp;lt;name&amp;gt; is the name of a field that contains the name of the required data type. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;A specific field is read from database table X031L. Neither the field name nor the table name is known until runtime: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Read a field from the table X031L&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS:&lt;/P&gt;&lt;P&gt;  TAB_NAME    LIKE SY-TNAME,           "Table name&lt;/P&gt;&lt;P&gt;  TAB_COMP    LIKE X031L-FIELDNAME,   "Field name&lt;/P&gt;&lt;P&gt;  ANZAHL      TYPE I DEFAULT 10.       Number of lines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &amp;lt;WA&amp;gt;   TYPE ANY,&lt;/P&gt;&lt;P&gt;               &amp;lt;COMP&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DATA: WA_REF TYPE REF TO DATA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CREATE DATA WA_REF TYPE (TAB_NAME). "Suitable work area&lt;/P&gt;&lt;P&gt;  ASSIGN WA_REF-&amp;gt;* TO &amp;lt;WA&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM (TAB_NAME) INTO &amp;lt;WA&amp;gt; &lt;/P&gt;&lt;P&gt;  UP TO anzahl ROWS.&lt;/P&gt;&lt;P&gt;  WRITE: / TAB_COMP, &amp;lt;COMP&amp;gt;.&lt;/P&gt;&lt;P&gt;  ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dont Forget to give points if it helps ;&amp;gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Rakesh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Dec 2005 10:46:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-declaration-for-variable/m-p/1080083#M97570</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-26T10:46:14Z</dc:date>
    </item>
  </channel>
</rss>

