Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Object Oriented BAPI access

Harsh_Jain2512
Participant
0 Likes
1,347

Hi,

Is object oriented access of BAPIs is possible  or through only FM we can access them in ABAP. If possible can somebody provide link to a documentation/example for that.

Regards,

5 REPLIES 5
Read only

sabirshah1
Participant
0 Likes
976

This message was moderated.

Read only

Harsh_Jain2512
Participant
0 Likes
976

Thanks Sabir for your response, but my question is that: Is the object Oriented access to BAPIs is possible in ABAP??? The link you provided is for OO BAPI access from other languages C++, Java. I want to know Is BAPI access in ABAP is possible only via FMs or classes are also there.

Read only

0 Likes
976

What do you mean with "OO access?"

BAPIs are FM and as FM can be called both in "old way" FORM and in methods

Read only

Former Member
0 Likes
976

I think you are looking for some standard ABAP Object classes encapsulating business objects from the BOR (since BAPI's are the API's of business objects). I don't believe there are many (any?) provided by SAP.

However, you can create your own wrapper classes calling methods of business objects using dedicated FM's  starting with SWO_...

Here is a small example:

REPORT ybkpf_swo_test.

*----------------------------------------------------------------------*
*       CLASS LCL_ACCOUNTING_DOCUMENT
*----------------------------------------------------------------------*
CLASS lcl_accounting_document DEFINITION.

   PUBLIC SECTION.

     TYPES BEGIN OF ac_doc_key.
     TYPES company_code  TYPE bukrs.
     TYPES doc_number    TYPE belnr_d.
     TYPES fiscal_year   TYPE gjahr.
     TYPES END OF ac_doc_key.

     CLASS-METHODS get
       IMPORTING
         i_company_code  TYPE ac_doc_key-company_code
         i_doc_number    TYPE ac_doc_key-doc_number
         i_fiscal_year   TYPE ac_doc_key-fiscal_year
       RETURNING
         value(r_object) TYPE REF TO lcl_accounting_document.

     METHODS display.

   PRIVATE SECTION.

     DATA key    TYPE ac_doc_key.
     DATA object TYPE swo_objhnd.

ENDCLASS.                    "LCL_ACCOUNTING_DOCUMENT


*----------------------------------------------------------------------*
*       CLASS LCL_ACCOUNTING_DOCUMENT IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_accounting_document IMPLEMENTATION.

   METHOD get.

     DATA:
       objtype TYPE swo_objtyp,
       objkey  TYPE swo_typeid.

     CREATE OBJECT r_object.

     r_object->key-company_code = i_company_code.
     r_object->key-doc_number   = i_doc_number.
     r_object->key-fiscal_year  = i_fiscal_year.

     objtype 'BKPF'.
     objkey  r_object->key.

     CALL FUNCTION 'SWO_CREATE'
       EXPORTING
         objtype = objtype
         objkey  = objkey
       IMPORTING
         object  = r_object->object.

   ENDMETHOD.                    "lcl_accounting_document

   METHOD display.

     DATA :
       container_tab TYPE STANDARD TABLE OF swcont.

     CALL FUNCTION 'SWO_INVOKE'
       EXPORTING
         object    = object
         verb      = 'Display'
       TABLES
         container = container_tab.

   ENDMETHOD.                    "display

ENDCLASS.                    "LCL_ACCOUNTING_DOCUMENT IMPLEMENTATION

PARAMETERS p_bukrs TYPE bkpf-bukrs.
PARAMETERS p_belnr TYPE bkpf-belnr.
PARAMETERS p_gjahr TYPE bkpf-gjahr.

DATA :
   ac_document TYPE REF TO lcl_accounting_document.

*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*

   ac_document = lcl_accounting_document=>get(
     i_company_code = p_bukrs
     i_doc_number   = p_belnr
     i_fiscal_year  = p_gjahr ).

   ac_document->display( ).


BR,

Gábor

Read only

0 Likes
976

Thanks Gabor for understanding yes I had to confirm are there any wrapper classes available for Business Objects, since I also googled a lot on this and I thinks  there are not any standard provided by SAP.