Skip to Content
author's profile photo Former Member
Former Member

using a generic object

I would like to be able to create an instance of an ABAP object without knowing the object type first. for example, if a specific type of message hits a queue, create a handler object specific to that message. I need to be able to declare the object variable as something not strongly typed, and do the create object for whatever actual object i want to use. I have checked the docs, but found nothing.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2004 at 06:00 AM

    Hi,

    Take a look at the document https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/advanced and generic programming in abap.pdf and the webcast titled Advanced and Generic Programming in ABAP in the SAP TechEd Education Sessions available on SDN. It will help you in getting an idea about runtime type specification. The book Abap Objects gives a detailed description of the concepts as well.

    If your prgram is using inheritance/interfaces, you can use polymorphism to achieve your purpose. Otherwise, take a look at the documentation for <b>CREATE DATA dref TYPE REF TO type|(typename)</b> and cl_abap_refdesc=>create_by_name( 'CLASS_NAME' )

    Hope this helps.

    Regards

    Message was edited by: Shehryar Khan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2004 at 05:17 AM

    Hello David,

    If I have understood your requirement correctly, then I think it is possible to meet it. Consider the following example :

    
    data w_obj type ref to object.
    data meth(5) type c value 'WRITE'.
    
    class test definition.
      public section.
        data:
          lv_test_variable type c value 'A'.
        methods write.
    endclass.
    
    class test implementation.
      method write.
        write:
            lv_test_variable,
            'Simple Sample'.
      endmethod.
    endclass.
    
    start-of-selection.
    
    create object w_obj type test.
    
    call method w_obj->(meth).
    

    As you are sure to discover, this approach has some limitations. I have not studied this thoroughly, but at least you can begin thinking in the lines of creating Object References.

    I hope this has been of some help to you.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.