Skip to Content
author's profile photo
Former Member

Instanciation of a business object in ABAP?

Hello,

I know that you can call the methods of business objects with BAPIs. But I want to instantiate a business object directly in the ABAP code. Does anybody have a code example for doing this?

In theory I think that I have first do define a reference variable of the objecttype of the buisness object. Than I have to call the Create-Methode of the business object and assign the returned object to the reference variable. Is this correct?

Thanks.

Regards, Lars.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 05, 2005 at 11:59 AM

    Business objects are not really class which can be instaniated. They are more or less "documentation" of the business element(process) which may or may not have a BAPI tied to it. If that is the case, then the BAPI is the coding that you would need to call.

    Regards,

    Rich Heilman

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 05, 2005 at 12:01 PM

    Hello,

    INCLUDE <cntn01>.

    DATA: l_object type swc_object.

    DATA: lv_key(70) type c.

    swc_container m_container.

    SWC_CREATE_OBJECT l_object 'BUS2081' lv_key.

    *WHERE bus2081 is any object type

    *where lv_key is the key of the object

    swc_call_method l_object 'DISPLAY' m_container.

    where mcontainer is the methd container

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 05, 2005 at 12:14 PM

    Hello,

    thank you for your quick responces. They helped me a lot.

    Regards, Lars.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Lars,

      Some more info to add to what Peter has already explained well.

      If you are going to call a method that has parameters (like a Create method as you mentioned) you would need to create and populate the container as follows.

       swc_container wa_container.
      
         swc_set_element wa_container 'Element1'  'Value'.
         swc_set_table wa_container 'Element2'  Itab.
      

      Also make sure you are not calling a dialog method in a background context!

      Cheers,

      Ramki Maley.