[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] 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.

[ABAP] RFC-Abruf aller verlinkten Dokumente zu einem Business Object

* System-ID
PARAMETERS: p_rfc TYPE sy-sysid DEFAULT 'XYZ'.
* Typ-Material 
PARAMETERS: p_sobj TYPE toav0-sap_object DEFAULT 'BUS1001006'.
* MATNR
PARAMETERS: p_oid TYPE toav0-object_id DEFAULT '000000001234567890'.

START-OF-SELECTION.

  DATA: lv_message TYPE bapiret2.
  DATA: it_results TYPE STANDARD TABLE OF toars_s WITH DEFAULT KEY.
  DATA: it_urls TYPE STANDARD TABLE OF toadurl_s WITH DEFAULT KEY.

* Gibt alle Dokumente zum Business Object zurück
  CALL FUNCTION 'ALINK_RFC_DOCUMENTS_GET' DESTINATION p_rfc
    EXPORTING
      im_botype             = p_sobj
      im_boid               = p_oid
      im_x_urls             = abap_false " Schalter zum Füllen von IT_URLS => Performance beachten
    IMPORTING
      ex_message            = lv_message
    TABLES
      ex_results            = it_results
      ex_urls               = it_urls
    EXCEPTIONS
      system_failure        = 1
      communication_failure = 2
      OTHERS                = 3.

  WRITE: / lv_message-message.

  IF sy-subrc = 0.
    cl_demo_output=>display( it_results ).
  ENDIF.

[ABAP] Archivobjekte lesen

* Archiv-ID aus Tabelle TOAAR
PARAMETERS: p_arc TYPE toaar-archiv_id.
* Dokumentart, in TOADV (SM30) gepflegt
PARAMETERS: p_aro TYPE toadv-ar_object DEFAULT 'SDOINVOICE'.
* Dateinamenerweiterung
PARAMETERS: p_dtype TYPE toaom-doc_type DEFAULT 'PDF'.
* SAP ArchiveLink: Objekt-Id (Objektidentifikator)
* SAP Objekt-Ident
* bei VBRK       - '0070000000                    0000000100'
* bei BUS1001006 - '0000000011000011111'
* Beispiele in TOA01, TOA02 oder TOA03
PARAMETERS: p_oid TYPE saeobjid DEFAULT '0070000000                    0000000100'.
* SAP ArchiveLink: Objekttyp des Business Objekts
* VBRK       - Kundeneinzelfaktura
* BUS1001006 - Standard Material
PARAMETERS: p_sobj TYPE tojtb-name DEFAULT 'VBRK'.

START-OF-SELECTION.

  DATA: it_connect_info TYPE STANDARD TABLE OF toav0 WITH DEFAULT KEY.

* Alle verkn?pften Archivobjekte zum Objekt anhand der Selektionskriterien ermitteln
* SAP ArchiveLink: Ermitteln von Ablage-Id und Dok.-Id zu Anwendungsobject
  CALL FUNCTION 'ARCHIV_CONNECTINFO_GET_META'
    EXPORTING
      archiv_id             = p_arc
      ar_object             = p_aro
      doc_type              = p_dtype
      object_id             = p_oid
      sap_object            = p_sobj
    TABLES
      connect_info          = it_connect_info
    EXCEPTIONS
      error_connectiontable = 1
      OTHERS                = 2.

  IF sy-subrc = 0.

* Liste der Verkn?fpungen durchgehen und Bin?rdaten aus Archiv holen
    LOOP AT it_connect_info ASSIGNING FIELD-SYMBOL(<ci>).

      WRITE: / <ci>-archiv_id, <ci>-sap_object, <ci>-object_id, <ci>-arc_doc_id, <ci>-reserve.

      DATA(lv_length) = 0.
      DATA: it_bin_data TYPE STANDARD TABLE OF tbl1024 WITH DEFAULT KEY.

      CLEAR: it_bin_data.

* Bin?rdaten des AO lesen
* CMS: AO API Dokument bereitstellen Tabelle
      CALL FUNCTION 'SCMS_AO_TABLE_GET'
        EXPORTING
          arc_id       = <ci>-archiv_id
          doc_id       = <ci>-arc_doc_id
        IMPORTING
          length       = lv_length
        TABLES
          data         = it_bin_data
        EXCEPTIONS
          error_http   = 1
          error_archiv = 2
          error_kernel = 3
          error_config = 4
          OTHERS       = 5.

      IF sy-subrc = 0.
        DATA: lv_xstring TYPE xstring.

* Bin?rdaten in xstring konvertieren
        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            input_length = CONV i( lv_length )
          IMPORTING
            buffer       = lv_xstring
          TABLES
            binary_tab   = it_bin_data
          EXCEPTIONS
            failed       = 1
            OTHERS       = 2.

        IF sy-subrc = 0.
          ...
        ENDIF.
      ELSE.
        WRITE: / 'Error:', sy-subrc.
      ENDIF.
    ENDLOOP.
  ELSE.
    WRITE: / 'Verbindungsdaten nicht gefunden:', sy-subrc.
  ENDIF.