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