<?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: Creating a variable of specified type dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821622#M351078</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1.)You always can return as data type 'table'.&lt;/P&gt;&lt;P&gt;2.)You can return as ref to data. For that, you need to create a variable dynamically in your method, compare:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: lv_var TYPE i VALUE 19768,&lt;/P&gt;&lt;P&gt;          l_dref1 TYPE REF TO data,&lt;/P&gt;&lt;P&gt;          l_dref2 TYPE REF TO data.&lt;/P&gt;&lt;P&gt;        &lt;/P&gt;&lt;P&gt;    FIELD-SYMBOLS: &amp;lt;fs_1&amp;gt; TYPE i, &amp;lt;fs_2&amp;gt; TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  Get name and value of import parameter&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    GET REFERENCE OF lv_var INTO l_dref1.&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    CREATE DATA l_dref2 TYPE i.&lt;/P&gt;&lt;P&gt;    ASSIGN l_dref2-&amp;gt;* TO &amp;lt;fs_2&amp;gt;.&lt;/P&gt;&lt;P&gt;    ASSIGN l_dref1-&amp;gt;* TO &amp;lt;fs_1&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &amp;lt;fs_2&amp;gt; = &amp;lt;fs_1&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    re_va2 = l_dref2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 03 Feb 2007 20:46:05 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-02-03T20:46:05Z</dc:date>
    <item>
      <title>Creating a variable of specified type dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821621#M351077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have requirement where in I need to return a variable of specified data type either through a method or function call. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: var_typ type char30 value 'I',&lt;/P&gt;&lt;P&gt;      var_val type char30 value '123'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To create a generic function or method which would return a variable of type 'I' with value '123', taking the var_typ and var_val as input parameter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is just an example, actual I have a internal table with multiple records and each record has a different data type, for each record a different variable needs to be created i.e. variable should be a return type and not a exporting type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More information about the requirement&lt;/P&gt;&lt;P&gt;Invoke methods dynamically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given:&lt;/P&gt;&lt;P&gt;1) You have a table with 2 fields (data type and value)&lt;/P&gt;&lt;P&gt;2) You have the class name and the method name (assume that method has one importing parameter).&lt;/P&gt;&lt;P&gt;3) Not to declare a variable of type importing or exporting in the program. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Information already gathered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Knows how to create objects dynamically (CREATE OBJECT obj_add TYPE (class_name)).&lt;/P&gt;&lt;P&gt;2) Knows how to invoke a method dynamically (CALL METHOD obj_add-&amp;gt;(method_name) PARAMETER-TABLE ptab).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would be helpful if you can provide the piece of code or guide me on how this can be implemented in ABAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Raghavendra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Feb 2007 10:21:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821621#M351077</guid>
      <dc:creator>raghavendra_subhash</dc:creator>
      <dc:date>2007-02-02T10:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable of specified type dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821622#M351078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1.)You always can return as data type 'table'.&lt;/P&gt;&lt;P&gt;2.)You can return as ref to data. For that, you need to create a variable dynamically in your method, compare:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: lv_var TYPE i VALUE 19768,&lt;/P&gt;&lt;P&gt;          l_dref1 TYPE REF TO data,&lt;/P&gt;&lt;P&gt;          l_dref2 TYPE REF TO data.&lt;/P&gt;&lt;P&gt;        &lt;/P&gt;&lt;P&gt;    FIELD-SYMBOLS: &amp;lt;fs_1&amp;gt; TYPE i, &amp;lt;fs_2&amp;gt; TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  Get name and value of import parameter&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    GET REFERENCE OF lv_var INTO l_dref1.&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    CREATE DATA l_dref2 TYPE i.&lt;/P&gt;&lt;P&gt;    ASSIGN l_dref2-&amp;gt;* TO &amp;lt;fs_2&amp;gt;.&lt;/P&gt;&lt;P&gt;    ASSIGN l_dref1-&amp;gt;* TO &amp;lt;fs_1&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &amp;lt;fs_2&amp;gt; = &amp;lt;fs_1&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    re_va2 = l_dref2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Feb 2007 20:46:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821622#M351078</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-03T20:46:05Z</dc:date>
    </item>
  </channel>
</rss>

