[ABAP] Klassen für Zugriff auf Business-Objekte

SAPoffice Dokumente

  • verlinkt auf Business Objekte via Object Relationship Service Tables
  • Klasse: CL_BINARY_RELATION (ersetzt FuBas SO_DOCUMENT*)
  • Tabellen: SRGBTBREL

Beispiel

* Quelle / Inspiration: https://www.inwerken.de/gos-anhange-auslesen-anlegen/

**********************************************************************
* Typen
**********************************************************************
TYPES: BEGIN OF ty_s_key,
         foltp     TYPE so_fol_tp,
         folyr     TYPE so_fol_yr,
         folno     TYPE so_fol_no,
         objtp     TYPE so_obj_tp,
         objyr     TYPE so_obj_yr,
         objno     TYPE so_obj_no,
         forwarder TYPE so_usr_nam,
       END OF ty_s_key.
**********************************************************************
* Selektionsbild
**********************************************************************
PARAMETERS: p_instid TYPE sibfboriid DEFAULT '000000001234567890'.
PARAMETERS: p_typeid TYPE sibftypeid DEFAULT 'BUS1001006'.
PARAMETERS: p_catid TYPE sibfcatid DEFAULT 'BO'.

START-OF-SELECTION.

* Schlüssel des Business-Objekts
  DATA(lv_object) = VALUE sibflporb( instid  = p_instid
                                     typeid  = p_typeid
                                     catid   = p_catid ).

* Verknüpfungsoptionen
* Verknüpfungstypen
  DATA(it_relopt) = VALUE obl_t_relt( ( sign   = 'I'
                                        option = 'EQ'
                                        low    = 'ATTA' " Anhänge
                                      )
                                      ( sign   = 'I'
                                        option = 'EQ'
                                        low    = 'NOTE' " Notizen
                                      )
                                      ( sign   = 'I'
                                        option = 'EQ'
                                        low    = 'URL'  " URLs
                                      )
                                    ).

  TRY.
* Verknüpfungen zum Objekt
      DATA(it_links) = VALUE obl_t_link( ).
      DATA(it_roles) = value obl_t_role( ).

* Verknüpfungen zum Objekt lesen
      cl_binary_relation=>read_links_of_binrels( EXPORTING
                                                   is_object           = lv_object
                                                   it_relation_options = it_relopt
                                                   ip_role             = 'GOSAPPLOBJ'
                                                 IMPORTING
                                                   et_links            = it_links
                                                   et_roles            = it_roles ).

      cl_demo_output=>write_data( it_links ).
      cl_demo_output=>write_data( it_roles ).

* Verknüpfungen vom Typ 'MESSAGE' durchgehen
      LOOP AT it_links ASSIGNING FIELD-SYMBOL(<l>) WHERE typeid_b = 'MESSAGE'.

        cl_demo_output=>line( ).

* Schlüssel einer Verknüpfung
        DATA(lv_key) = CONV ty_s_key( <l>-instid_b ).
        cl_demo_output=>write_data( lv_key ).

* Dokumenten-Grunddaten
        DATA(lv_doc_data) = VALUE sofolenti1( ).
* Dokumenteninhalt Text und Binär
        DATA(it_contx) = VALUE solix_tab( ).
        DATA(it_cont) = VALUE soli_tab( ).

* Daten des Dokuments lesen
        CALL FUNCTION 'SO_DOCUMENT_READ_API1'
          EXPORTING
            document_id                = CONV sofolenti1-doc_id( <l>-instid_b ) " Dokumenten-ID für SAPOffice == Instanz-ID
          IMPORTING
            document_data              = lv_doc_data
          TABLES
            object_content             = it_cont
            contents_hex               = it_contx
          EXCEPTIONS
            document_id_not_exist      = 1
            operation_no_authorization = 2
            x_error                    = 3
            OTHERS                     = 4.
        IF sy-subrc = 0.
          cl_demo_output=>write_data( lv_doc_data ).
          cl_demo_output=>write_data( it_cont ).
        ENDIF.

      ENDLOOP.

      cl_demo_output=>display( ).

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

Archivdokumente

  • Logische Dokumente, verlinkt auf Business Objekte via Connection Tables des Content Management Systems
  • Klasse: CL_ALINK_CONNECTION
  • Funktionen: find, find_by_doc_key, compose, insert, delete_by_key
  • Tabellen: TOAAR, TOAOM, TOJTB, TOA01, TOA02, TOA03

Beispiel

TRY.
    DATA(o_alink) = NEW cl_alink_connection( ).
* Suche von Verknüpfungen
    o_alink->find( EXPORTING 
                     sap_object = 'ZXYZ'                   " SAP ArchiveLink: Objekttyp des Business Objekts
                     object_id  = CONV saeobjid( '12345' ) " SAP ArchiveLink: Objekt-Id (Objektidentifikator)
                     mandt      = sy-mandt                 " Mandantenkennung des aktuellen Benutzers
                     archiv_id  = 'XY'                     " Content Repository Identifikation
                   IMPORTING
                     connections = DATA(it_conn) ).
    
    cl_demo_output=>display( it_conn ).
  CATCH cx_root.
ENDTRY.

[SAP] Archivobjekt anhand seiner ARC_DOC_ID lesen

* Archiv-ID aus Tabelle TOAAR
PARAMETERS: p_arc TYPE toaar-archiv_id.
* ARC_DOC_ID: Beispiel siehe Tabelle TOA01, TOA02, TOA03
PARAMETERS: p_docid TYPE saeardoid DEFAULT '41C0CC07B977349DE10000000A450668'.

START-OF-SELECTION.

  DATA: lv_toa0x TYPE toa01.

* Pr?fen, ob das Archivobjekt in der Tabelle TOA01, TOA02 oder TOA03 abgelegt ist
* Tabelle TOA01
  SELECT SINGLE *
    INTO @lv_toa0x
    FROM toa01
    WHERE arc_doc_id = @p_docid
      AND archiv_id  = @p_arc.

  IF sy-subrc <> 0.
* Tabelle TOA02
    SELECT SINGLE *
      INTO @lv_toa0x
      FROM toa02
      WHERE arc_doc_id = @p_docid
        AND archiv_id  = @p_arc.
  ENDIF.

  IF sy-subrc <> 0.
* Tabelle TOA03
    SELECT SINGLE *
      INTO @lv_toa0x
      FROM toa03
      WHERE arc_doc_id = @p_docid
        AND archiv_id  = @p_arc.
  ENDIF.

  IF sy-subrc = 0.

    WRITE: / lv_toa0x-sap_object.
    WRITE: / lv_toa0x-object_id.
    WRITE: / lv_toa0x-archiv_id.
    WRITE: / lv_toa0x-arc_doc_id.
    WRITE: / lv_toa0x-ar_object.
    WRITE: / lv_toa0x-ar_date.
    WRITE: / lv_toa0x-del_date.
    WRITE: / lv_toa0x-reserve.

    ULINE.

    DATA: lv_url TYPE swk_url.

* CMS:AO API Url für Dokumentzugriff
    CALL FUNCTION 'SCMS_AO_URL_READ'
      EXPORTING
        arc_id = p_arc
        doc_id = p_docid
      IMPORTING
        url    = lv_url
      EXCEPTIONS
        error  = 1
        OTHERS = 2.

    IF sy-subrc = 0.
* URL anzeigen, kann auch im cl_gui_html_viewer direkt angezeigt werden
      WRITE: / lv_url.
*      DATA(o_html) = new cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).
*      o_html->show_url( lv_url ).
      ULINE.
    ELSE.
      WRITE: / 'URL-Error:', sy-subrc.
    ENDIF.

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

    DATA: lv_status TYPE char64.
    DATA: lv_doc_type TYPE char64.
    DATA: lv_arch_date TYPE d.
    DATA: lv_arch_time TYPE t.
    DATA: lv_mimetype TYPE char64.
    DATA: it_scms_comps TYPE STANDARD TABLE OF scms_comps WITH DEFAULT KEY.
    DATA: it_scms_compsl TYPE STANDARD TABLE OF scms_compsl WITH DEFAULT KEY.

* Status des AO lesen
* CMS: AO API Statusabfrage
    CALL FUNCTION 'SCMS_AO_STATUS'
      EXPORTING
        arc_id       = p_arc
        doc_id       = p_docid
      IMPORTING
        status       = lv_status
        doc_type     = lv_doc_type
        arch_date    = lv_arch_date
        arch_time    = lv_arch_time
        mimetype     = lv_mimetype
      TABLES
        comps        = it_scms_comps
        compsl       = it_scms_compsl
      EXCEPTIONS
        error_http   = 1
        error_kernel = 2
        error_archiv = 3
        error_config = 4
        OTHERS       = 5.
    IF sy-subrc = 0.
      LOOP AT it_scms_comps ASSIGNING FIELD-SYMBOL(<c>).
        WRITE: / <c>-compid, <c>-mimetype, <c>-compsize, <c>-compdatec, <c>-comptimec, <c>-compdatem, <c>-comptimem, <c>-status.
      ENDLOOP.
    ELSE.
      WRITE: / 'Status-Error:', sy-subrc.
    ENDIF.

    ULINE.

* Bin?rdaten des AO lesen
* CMS: AO API Dokument bereitstellen Tabelle
    CALL FUNCTION 'SCMS_AO_TABLE_GET'
      EXPORTING
        arc_id       = p_arc
        doc_id       = p_docid
      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 getting AO-data:', sy-subrc.
    ENDIF.
  ELSE.
    WRITE: / 'ARC_DOC_ID not found:', sy-subrc.
  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.