<?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 Dynamic calling objects in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591529#M864776</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created one interface zif_test and method is calc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created two class in SE24- zcl_stf and zcl_wrk with interface zif_test. [ calculation varies in both classes ].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;stf and wrk are two category.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do i call the object based on category ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;P&gt;Point will be rewarded&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Mar 2008 12:38:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-18T12:38:47Z</dc:date>
    <item>
      <title>Dynamic calling objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591529#M864776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created one interface zif_test and method is calc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created two class in SE24- zcl_stf and zcl_wrk with interface zif_test. [ calculation varies in both classes ].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;stf and wrk are two category.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do i call the object based on category ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;P&gt;Point will be rewarded&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2008 12:38:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591529#M864776</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-18T12:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic calling objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591530#M864777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Vijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You question is not very clear. Can you please explain a bit?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general, if you have an interface &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if_xyz having method meth1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and two classes implement this interface&lt;/P&gt;&lt;P&gt;cl_one and cl_two.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Youu can call the method in interface statically is &lt;/P&gt;&lt;P&gt;cl_one-&amp;gt;if_xyz~meth1   and&lt;/P&gt;&lt;P&gt;cl_two-&amp;gt;if_xyz~meth1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to have dynamic call, assign &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if_xyz = cl_one or if_xyz = cl_two depending on your situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can call if_xyz-&amp;gt;meth1 and the implementation called will depend on which class is now assigned to if_xyz.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general it is useful, when you call a method which takes a import paramater of type if_xyz and you pass cl_one or cl_two when you call it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Rakesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 13 Apr 2008 13:57:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591530#M864777</guid>
      <dc:creator>rakesh_kumar</dc:creator>
      <dc:date>2008-04-13T13:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic calling objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591531#M864778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Vijay&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would recommend to create a &lt;STRONG&gt;factory&lt;/STRONG&gt; method or class which instantiates the appropriate class depending on your category.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The factory method or class could look like this (please note that I define it as local class for this purpose. You should create a global class):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS lcl_factory DEFINITION.

  PUBLIC SECTION.
    
    CLASS-METHODS:
      create
        IMPORTING
          id_category           TYPE zcategory
       RETURNING
         value(ro_instance)   TYPE REF TO zif_test.  " your interface

ENDCLASS.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS lcl_factory IMPLEMENTATION.

  METHOD create.

    CASE id_category.
      WHEN 'STF'.
        CREATE OBJECT ro_instance TYPE ( 'ZCL_STF' ).

      WHEN 'WRK'.
        CREATE OBJECT ro_instance TYPE ( 'ZCL_WRK' ).
 
      WHEN OTHERS.
       " perhaps you can define a default implementation
      ENDCASE.


  ENDMETHOD.

ENDCLASS.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The advantage of using a factory method is that in your main program you do not need to think about the required implementation but just call your CALC method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: go_test    TYPE REF TO zif_test.  " interface (!!!) variable

PARAMETERS:
  p_catego      TYPE zcategory     DEFAULT 'STF'.  " your category


START-OF-SELECTION.

" NOTE: the factory method returns the required implementation
  go_test = lcl_factory=&amp;gt;create( p_catego ).

  go_test-&amp;gt;calc(...).

...

END-OF-SELECTION.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 13 Apr 2008 16:08:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-calling-objects/m-p/3591531#M864778</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2008-04-13T16:08:15Z</dc:date>
    </item>
  </channel>
</rss>

