<?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/1821868#M351178</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DATA: &lt;/P&gt;&lt;P&gt;ref_itab TYPE REF TO data,&lt;/P&gt;&lt;P&gt;ref_wa TYPE REF TO data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &lt;/P&gt;&lt;P&gt;&amp;lt;fs_itab&amp;gt; TYPE ANY TABLE,&lt;/P&gt;&lt;P&gt;&amp;lt;fs_wa&amp;gt; TYPE ANY,&lt;/P&gt;&lt;P&gt;&amp;lt;fs_comp&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS:&lt;/P&gt;&lt;P&gt;pa_tab TYPE dd02l-tabname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Start-of-Selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA ref_itab TYPE STANDARD TABLE OF (pa_tab) WITH NON-UNIQUE DEFAULT KEY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ASSIGN ref_itab-&amp;gt;* to &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM (pa_tab) INTO TABLE &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA ref_wa LIKE LINE OF &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN ref_wa to &amp;lt;fs_wa&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT &amp;lt;fs_itab&amp;gt; into &amp;lt;fs_wa&amp;gt;.&lt;/P&gt;&lt;P&gt;	DO.&lt;/P&gt;&lt;P&gt;		ASSIGN COMPONENT sy-index OF STRUCTURE &amp;lt;fs_wa&amp;gt; TO &amp;lt;fs_comp&amp;gt;.&lt;/P&gt;&lt;P&gt;			IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;				NEW-LINE.&lt;/P&gt;&lt;P&gt;				EXIT.&lt;/P&gt;&lt;P&gt;			ENDIF.&lt;/P&gt;&lt;P&gt;			WRITE &amp;lt;fs_comp&amp;gt;.&lt;/P&gt;&lt;P&gt;	ENDDO.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Feb 2007 10:54:45 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-02-02T10:54:45Z</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/1821866#M351176</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:22:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821866#M351176</guid>
      <dc:creator>raghavendra_subhash</dc:creator>
      <dc:date>2007-02-02T10:22:46Z</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/1821867#M351177</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;Why dont you use a field symbol&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g FIELD-SYMBOLS : value type any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can assign any value to this variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this link for more information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm" target="test_blank"&gt;http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Feb 2007 10:30:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821867#M351177</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-02T10:30:05Z</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/1821868#M351178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DATA: &lt;/P&gt;&lt;P&gt;ref_itab TYPE REF TO data,&lt;/P&gt;&lt;P&gt;ref_wa TYPE REF TO data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &lt;/P&gt;&lt;P&gt;&amp;lt;fs_itab&amp;gt; TYPE ANY TABLE,&lt;/P&gt;&lt;P&gt;&amp;lt;fs_wa&amp;gt; TYPE ANY,&lt;/P&gt;&lt;P&gt;&amp;lt;fs_comp&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS:&lt;/P&gt;&lt;P&gt;pa_tab TYPE dd02l-tabname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Start-of-Selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA ref_itab TYPE STANDARD TABLE OF (pa_tab) WITH NON-UNIQUE DEFAULT KEY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ASSIGN ref_itab-&amp;gt;* to &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM (pa_tab) INTO TABLE &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE DATA ref_wa LIKE LINE OF &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN ref_wa to &amp;lt;fs_wa&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT &amp;lt;fs_itab&amp;gt; into &amp;lt;fs_wa&amp;gt;.&lt;/P&gt;&lt;P&gt;	DO.&lt;/P&gt;&lt;P&gt;		ASSIGN COMPONENT sy-index OF STRUCTURE &amp;lt;fs_wa&amp;gt; TO &amp;lt;fs_comp&amp;gt;.&lt;/P&gt;&lt;P&gt;			IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;				NEW-LINE.&lt;/P&gt;&lt;P&gt;				EXIT.&lt;/P&gt;&lt;P&gt;			ENDIF.&lt;/P&gt;&lt;P&gt;			WRITE &amp;lt;fs_comp&amp;gt;.&lt;/P&gt;&lt;P&gt;	ENDDO.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Feb 2007 10:54:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821868#M351178</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-02T10:54:45Z</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/1821869#M351179</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;Thanks for quick responce. I tried using the field symbols, but was not possible. I pasted a sinp of the code that actual work i.e. without using the field symbol.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: ptab type abap_parmbind_tab,&lt;/P&gt;&lt;P&gt;ptab_line TYPE abap_parmbind.&lt;/P&gt;&lt;P&gt;DATA: class_name type CHAR30 VALUE 'ZCL_ADD,&lt;/P&gt;&lt;P&gt;method_name type CHAR30 VALUE 'ADD'.&lt;/P&gt;&lt;P&gt;DATA: obj type ref to OBJECT.&lt;/P&gt;&lt;P&gt;DATA: IV_var1 TYPE I.&lt;/P&gt;&lt;P&gt;DATA: IV_var2 TYPE I.&lt;/P&gt;&lt;P&gt;DATA: EV_OUT TYPE I.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;IV_var1 = 1.&lt;/P&gt;&lt;P&gt;IV_var2 = 2.&lt;/P&gt;&lt;P&gt;EV_OUT = 0.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;create object obj type (class_name).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ptab_line-name = 'IV_var1'.&lt;/P&gt;&lt;P&gt;ptab_line-kind = CL_ABAP_OBJECTDESCR=&amp;gt;EXPORTING.&lt;/P&gt;&lt;P&gt;GET REFERENCE OF IV_var1 INTO ptab_line-value.&lt;/P&gt;&lt;P&gt;INSERT ptab_line into table ptab.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;ptab_line-name = 'IV_var2'.&lt;/P&gt;&lt;P&gt;ptab_line-kind = CL_ABAP_OBJECTDESCR=&amp;gt;EXPORTING.&lt;/P&gt;&lt;P&gt;GET REFERENCE OF IV_var2 INTO ptab_line-value.&lt;/P&gt;&lt;P&gt;INSERT ptab_line into table ptab.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;ptab_line-name = 'EV_out'.&lt;/P&gt;&lt;P&gt;ptab_line-kind = CL_ABAP_OBJECTDESCR=&amp;gt;IMPORTING.&lt;/P&gt;&lt;P&gt;GET REFERENCE OF EV_out INTO ptab_line-value.&lt;/P&gt;&lt;P&gt;INSERT ptab_line into table ptab.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;*Then you can use&lt;/P&gt;&lt;P&gt;CALL METHOD obj-&amp;gt;(method_name) PARAMETER-TABLE ptab.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;WRITE: 'this test program'.&lt;/P&gt;&lt;P&gt;WRITE: EV_out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here I have declared a variables (iv_var1, iv_var2, ev_out) of the method ADD. Instead of declaring the variable, I need a generic function which can read from data from the table and return me variable with value., so that I can insert it to the ptab.&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 11:35:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-variable-of-specified-type-dynamically/m-p/1821869#M351179</guid>
      <dc:creator>raghavendra_subhash</dc:creator>
      <dc:date>2007-02-02T11:35:10Z</dc:date>
    </item>
  </channel>
</rss>

