[SAP] Business-Objekte (BOR) / BAPI

Transaktionen

SWO1 (Business Object Builder)

  • Business Objekte anlegen und anzeigen

SWO2 (BOR Browser)
SWO3 (Business Object Builder)
SWO4 (Business Object Repository)
SWO6 (Customizing Objekttypen)
BAPI (BAPI Explorer)

  • Business Objekte anlegen und anzeigen

Objekttypen (Beispiele)

BUS1001 (Material)
BUS1001006 (Standard Material)
BUS2010 (Lieferantenanfrage)
BUS2011 (Lieferantenangebot)
BUS2012 (Bestellung)
BUS2015 (Anlieferung)
BUS2017 (Warenbewegung)
BUS2030 (Kundenanfrage)
BUS2032 (Kundenauftrag)
BUS2081 (Eingangsrechnung)
BUS2091 (Leistungserfassungsblatt)
BUS2105 (Bestellanforderung)
BUS3005 (Kondition)

Klassen

CL_BINARY_RELATION (API für Binäre Verknüpfung)

Tabellen

TOJTB (Business Object Repository Grunddaten)
TOJTT (Texte Grunddaten)
TOJTD (Customizing Objekttypen)
SWOTDI (Definition Schnittstellen)
SWOTDV (Objekttyp Verben Definition)
SWOTLQ (Laufzeittabelle Parameter, Ausnahmen)
SWOTLV (Laufzeittabelle Verben)
SWOTTV (Texte zu Verben)

Funktionsbausteine

SWO_CREATE (Business Objekt initiieren)
SWO_INVOKE (Buisness Objekt Metode aufrufen / Attribute setzen)
SWO_FREE (Business Objekt freigeben)
SWE_EVENT_CREATE (Erzeugen eines Ereignisses (public))
SWE_EVENT_GET_RECEIVERS (Ermittelt die Empfänger eines Ereignisses (INTERN))

Reports

MMPUR_BOR_CHANGE_ARL (Business Object Migration von EKKO nach BUS20xx)

Links

[ABAP] Informationen zu Business Objekten anzeigen

* Transaktion SWO1

DATA: lv_objtyp TYPE swo_objtyp.
DATA: lv_stext TYPE swc_shtext.

SELECT-OPTIONS: so_objtp FOR lv_objtyp.
SELECT-OPTIONS: so_stext FOR lv_stext.
*PARAMETERS: p_spras type sy-langu DEFAULT 'E'.

INITIALIZATION.

  so_objtp[] = VALUE #( ( sign = 'I' option = 'EQ' low = 'BUS2012' high = '' ) ).
  so_stext[] = VALUE #( ( sign = 'I' option = 'CP' low = 'Bestellung*' high = '' )
                        ( sign = 'I' option = 'CP' low = 'Eink*' high = '' ) ).

START-OF-SELECTION.

  SELECT FROM tojtb AS tb
    INNER JOIN tojtt AS tt ON tb~name = tt~name
    FIELDS tb~name,
           tb~editelem,
           tt~ntext,
           tt~stext
    WHERE tb~name IN @so_objtp
*      AND tb~activelang = @p_spras
*      AND tt~language = @p_spras
    INTO TABLE @DATA(it_tojtb).

  IF sy-subrc = 0.

    SELECT dv~objtype,   " BO Typ
           dv~verb,      " Funktion
           dv~verbtype,  " Funktionstyp ( ' ' =   Kein Verb, K = Schlüsselfeld, A = Attribut, M = Methode, E = Ereignis )
           dv~editelem,  " Element
           dv~refstruct, " Tabelle
           dv~reffield,  " Bezugsfeld
           dv~abapname,  " Funktionsbaustein
           tv~descript,  " Beschreibung
           tv~shorttext  " Kurztext
      INTO TABLE @DATA(it_bor_info)
      FROM swotdv AS dv
      INNER JOIN swottv AS tv ON dv~objtype = tv~objtype AND dv~verb = tv~verb
      WHERE dv~objtype IN @so_objtp
*        AND tv~language = @p_spras
      AND tv~shorttext IN @so_stext.

    IF sy-subrc = 0.

      SORT: it_bor_info BY verbtype verb.

      TRY.
          DATA(lv_tojtb_name) = SWITCH #( lines( it_tojtb ) WHEN 0 THEN || ELSE it_tojtb[ 1 ]-name ).
          DATA(lv_tojtb_stext) = SWITCH #( lines( it_tojtb ) WHEN 0 THEN || ELSE it_tojtb[ 1 ]-stext ).

          lv_tojtb_name = SWITCH #( lines( so_objtp ) WHEN 0 THEN || ELSE |Objekttyp: { lv_tojtb_name }| ).
          lv_tojtb_stext = SWITCH #( lines( so_objtp ) WHEN 0 THEN |keine Selektion| ELSE lv_tojtb_stext ).

* SALV-Table
          DATA: o_salv TYPE REF TO cl_salv_table.

          cl_salv_table=>factory( IMPORTING
                                    r_salv_table   = o_salv
                                  CHANGING
                                    t_table        = it_bor_info ).

* Grundeinstellungen
          o_salv->get_functions( )->set_all( abap_true ).
          o_salv->get_columns( )->set_optimize( abap_true ).
          o_salv->get_display_settings( )->set_list_header( |{ lv_tojtb_name } ({ lv_tojtb_stext })| ).
          o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
          o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

* Spaltenüberschriften: technischer Name und Beschreibungstexte
          LOOP AT o_salv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<c>).
            DATA(o_col) = <c>-r_column.
            o_col->set_short_text( || ).
            o_col->set_medium_text( || ).
            o_col->set_long_text( |{ o_col->get_columnname( ) } [{ o_col->get_long_text( ) }]| ).
          ENDLOOP.

          o_salv->display( ).
        CATCH cx_root INTO DATA(e_txt).
          WRITE: / e_txt->get_text( ).
      ENDTRY.
    ENDIF.
  ENDIF.

[ABAP] Funktionen von Business Objekten aufrufen

Beispiel 1 (Bestellung anzeigen)

* http://saptechnical.com/Tutorials/Workflow/BusinessObjects/Page1.htm
* weitere Funktionen siehe SAP-Include:
* INCLUDE <cntn01>.

* Paket: SWO

* Tabellen:

* TOJTB (Business Object Repository Grunddaten)
* TOJTT (Texte Grunddaten)
* TOJTD (Customizing Objekttypen)
* SWOTDI (Definition Schnittstellen)
* SWOTDV (Objekttyp Verben Definition)
* SWOTLQ (Laufzeittabelle Parameter, Ausnahmen)
* SWOTLV (Laufzeittabelle Verben)

* BUS2012 == Bestellung
PARAMETERS: p_objtyp TYPE swo_objtyp DEFAULT 'BUS2012'.
* Bestellnummer
PARAMETERS: p_objkey TYPE swo_typeid DEFAULT '0001122333'.

START-OF-SELECTION.

  TYPES: ty_it_container TYPE STANDARD TABLE OF swcont WITH DEFAULT KEY.

  DATA: lv_obj TYPE swo_objhnd.
  DATA: lv_ret TYPE swotreturn.

  * Business Objekt initiieren
  CALL FUNCTION 'SWO_CREATE'
    EXPORTING
      objtype           = p_objtyp
      objkey            = p_objkey
    IMPORTING
      object            = lv_obj
      return            = lv_ret
    EXCEPTIONS
      no_remote_objects = 1
      OTHERS            = 2.

  IF sy-subrc = 0.
  * Container für Rückgabewerte
    DATA: it_container TYPE ty_it_container.

  * Buisness Objekt Metode aufrufen / Attribute setzen
    CALL FUNCTION 'SWO_INVOKE'
      EXPORTING
        access     = 'C'        " C - Call Method, G - Get Attribute
        object     = lv_obj
        verb       = 'DISPLAY'  " Anzeigen
      IMPORTING
        return     = lv_ret
      TABLES
        container  = it_container.

    IF lv_ret-code <> 0.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ELSE.
    IF lv_ret-code <> 0.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ENDIF.

  CALL FUNCTION 'SWO_FREE'
    EXPORTING
      object = lv_obj
    IMPORTING
      return = lv_ret.

  IF lv_ret-code <> 0.
    WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
  ENDIF.

Beispiel 2 (Details zur Bestellung auflisten)

* http://saptechnical.com/Tutorials/Workflow/BusinessObjects/Page1.htm
* weitere Funktionen siehe SAP-Include:
* INCLUDE <cntn01>.

* BUS2012 == Bestellung
PARAMETERS: p_objtyp TYPE swo_objtyp DEFAULT 'BUS2012'.
* Bestellnummer
PARAMETERS: p_objkey TYPE swo_typeid DEFAULT '0001122333'.

START-OF-SELECTION.

  TYPES: ty_it_container TYPE STANDARD TABLE OF swcont WITH DEFAULT KEY.

  DATA: lv_obj TYPE swo_objhnd.
  DATA: lv_ret TYPE swotreturn.

  * Business Objekt initiieren
  CALL FUNCTION 'SWO_CREATE'
    EXPORTING
      objtype           = p_objtyp
      objkey            = p_objkey
    IMPORTING
      object            = lv_obj
      return            = lv_ret
    EXCEPTIONS
      no_remote_objects = 1
      OTHERS            = 2.

  IF sy-subrc = 0.
  * Container für Rückgabewerte
    DATA: it_container TYPE ty_it_container.

  * Buisness Objekt Metode aufrufen / Attribute setzen
    CALL FUNCTION 'SWO_INVOKE'
      EXPORTING
        access    = 'C'           " C - Call Method, G - Get Attribute
        object    = lv_obj
        verb      = 'GETDETAIL1'  " Details
      IMPORTING
        return    = lv_ret
      TABLES
        container = it_container.

    IF lv_ret-code = 0.
      LOOP AT it_container ASSIGNING FIELD-SYMBOL(<a>).
        WRITE: / |{ <a>-element }: { <a>-value }|.
      ENDLOOP.
    ELSE.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ELSE.
    IF lv_ret-code <> 0.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ENDIF.

  CALL FUNCTION 'SWO_FREE'
    EXPORTING
      object = lv_obj
    IMPORTING
      return = lv_ret.

  IF lv_ret-code <> 0.
    WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
  ENDIF.

Beispiel 3 (Attribut zum Material anzeigen)

* http://saptechnical.com/Tutorials/Workflow/BusinessObjects/Page1.htm
* weitere Funktionen siehe SAP-Include:
* INCLUDE <cntn01>.

* BUS1001006 == Standard Material
PARAMETERS: p_objtyp TYPE swo_objtyp DEFAULT 'BUS1001006'.
* 18-stellige Materialnummer
PARAMETERS: p_objkey TYPE swo_typeid DEFAULT '000000001112223333'.

START-OF-SELECTION.

  TYPES: ty_it_container TYPE STANDARD TABLE OF swcont WITH DEFAULT KEY.

  DATA: lv_obj TYPE swo_objhnd.
  DATA: lv_ret TYPE swotreturn.

  * Buisiness Objekt initiieren
  CALL FUNCTION 'SWO_CREATE'
    EXPORTING
      objtype           = p_objtyp
      objkey            = p_objkey
    IMPORTING
      object            = lv_obj
      return            = lv_ret
    EXCEPTIONS
      no_remote_objects = 1
      OTHERS            = 2.

  IF sy-subrc = 0.
  * Container für Rückgabewerte
    DATA: it_container TYPE ty_it_container.

  * Buisness Objekt Metode aufrufen / Attribute setzen
    CALL FUNCTION 'SWO_INVOKE'
      EXPORTING
        access    = 'G'             " C - Call Method, G - Get Attribute
        object    = lv_obj
        verb      = 'MATERIALTYPE'  " Attribut
      IMPORTING
        return    = lv_ret
      TABLES
        container = it_container.

    IF lv_ret-code = 0.
      LOOP AT it_container ASSIGNING FIELD-SYMBOL(<a>).
        WRITE: / |{ <a>-element }: { <a>-value }|.
      ENDLOOP.
    ELSE.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ELSE.
    IF lv_ret-code <> 0.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ENDIF.

  CALL FUNCTION 'SWO_FREE'
    EXPORTING
      object = lv_obj
    IMPORTING
      return = lv_ret.

  IF lv_ret-code <> 0.
    WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
  ENDIF.

Beispiel 4 (Material Detail)

* http://saptechnical.com/Tutorials/Workflow/BusinessObjects/Page1.htm
* weitere Funktionen siehe SAP-Include:
* INCLUDE <cntn01>.

* BUS1001006 == Standard Material
PARAMETERS: p_objtyp TYPE swo_objtyp DEFAULT 'BUS1001006'.
* 18-stellige Materialnummer
PARAMETERS: p_objkey TYPE swo_typeid DEFAULT '000000001112223333'.

START-OF-SELECTION.

  TYPES: ty_it_container TYPE STANDARD TABLE OF swcont WITH DEFAULT KEY.

  DATA: lv_obj TYPE swo_objhnd.
  DATA: lv_ret TYPE swotreturn.

  * Buisiness Objekt initiieren
  CALL FUNCTION 'SWO_CREATE'
    EXPORTING
      objtype           = p_objtyp
      objkey            = p_objkey
    IMPORTING
      object            = lv_obj
      return            = lv_ret
    EXCEPTIONS
      no_remote_objects = 1
      OTHERS            = 2.

  IF sy-subrc = 0.
  * Container für Rückgabewerte
    DATA: it_container TYPE ty_it_container.

  * SWO1 -> Objekttyp -> Methoden
  * oder
  * Tabelle SWOTDV -> Spalte VERB, VERBTYPE = M
  *GetDetail                             Detaildaten zu einem Material ermitteln
  *ExistenceCheck                        Existenz des Objekts prüfen
  *GetList                               Liste mit Kurztext
  *Display                               Material anzeigen
  *GetMRPList                            Dispositionsliste eines Materials
  *GetStockRequirementsList              Aktuelle Bedarfs-/Bestandsliste eines Materials

  * Buisness Objekt Metode aufrufen / Attribute setzen
    CALL FUNCTION 'SWO_INVOKE'
      EXPORTING
        access    = 'C'          " C - Call Method, G - Get Attribute
        object    = lv_obj
        verb      = 'GETDETAIL'  " Details
      IMPORTING
        return    = lv_ret
      TABLES
        container = it_container.

    IF lv_ret-code = 0.
      LOOP AT it_container ASSIGNING FIELD-SYMBOL(<a>).
        WRITE: / |{ <a>-element }: { <a>-value }|.
      ENDLOOP.
    ELSE.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ELSE.
    IF lv_ret-code <> 0.
      WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
    ENDIF.
  ENDIF.

  CALL FUNCTION 'SWO_FREE'
    EXPORTING
      object = lv_obj
    IMPORTING
      return = lv_ret.

  IF lv_ret-code <> 0.
    WRITE: / lv_ret-code, lv_ret-errortype, lv_ret-workarea, lv_ret-message, lv_ret-text, lv_ret-variable1, lv_ret-variable2, lv_ret-variable3, lv_ret-variable4.
  ENDIF.