[ABAP] DMS: Infos zu Dokumenteninfosätzen lesen

Variante 1 (JOIN)

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_type TYPE draw-dokar OBLIGATORY DEFAULT 'XYZ'.
* Dokumentnummer, mit Suchhilfe auf Tabelle DRAW (Dokumentinformationssatz)
PARAMETERS: p_num TYPE draw-doknr OBLIGATORY DEFAULT '10000000001' MATCHCODE OBJECT /plmb/dir_elm.
* Dokumentversion
PARAMETERS: p_ver TYPE draw-dokvr OBLIGATORY DEFAULT '00'.
* Teildokument
PARAMETERS: p_part TYPE draw-doktl OBLIGATORY DEFAULT '000'.

START-OF-SELECTION.

  SELECT FROM draw AS dw
    INNER JOIN drad AS dd ON ( dw~dokar EQ dd~dokar AND dw~doknr EQ dd~doknr AND dw~dokvr EQ dd~dokvr AND dw~doktl EQ dd~doktl )
    INNER JOIN drat AS dt ON ( dw~dokar EQ dt~dokar AND dw~doknr EQ dt~doknr AND dw~dokvr EQ dt~dokvr AND dw~doktl EQ dt~doktl )
    LEFT OUTER JOIN dms_doc2loio AS l ON ( dw~dokar EQ l~dokar AND dw~doknr EQ l~doknr AND dw~dokvr EQ l~dokvr AND dw~doktl EQ l~doktl )
    LEFT OUTER JOIN dms_doc_files AS f ON ( dw~dokar EQ f~dokar AND dw~doknr EQ f~doknr AND dw~dokvr EQ f~dokvr AND dw~doktl EQ f~doktl )
    LEFT OUTER JOIN dms_ph_cd1 AS ph ON ( ph~loio_id EQ l~lo_objid )
    LEFT OUTER JOIN dms_phf_cd1 AS pf ON ( pf~phio_id EQ ph~phio_id )
    LEFT OUTER JOIN dms_phio2file AS o ON ( o~file_id EQ ph~prop08 )
    FIELDS dw~dokar,                    " Dokumentart
           dw~doknr,                    " Dokumentnummer
           dw~dokvr,                    " Dokumentversion
           dw~doktl,                    " Teildokument
           dw~dwnam,                    " Name des zuständigen Sachbearbeiters
           dw~adatum,                   " Ausgabedatum des Dokuments
           dw~document_info_record_key, " Dokumentinfosatzschlüssel konkatenierter Form
           dd~dokob,                    " Verknüpftes SAP-Objekt
           dd~obzae,                    " Zähler Key
           dd~objky,                    " Objektkey Dokumentenverwaltung
           dt~dktxt,                    " Beschreibung
           l~lo_objid,                  " Log.Dokument
           f~dappl,                     " WS-Appl.
           f~filename,                  " Dateiname
           ph~phio_id,                  " Phys.Dokument
           ph~stor_cat,                 " Kategorie
           pf~mimetype,                 " MIME Typ
           pf~file_size,                " Größe
           pf~file_name,                " Komponentenname
           pf~file_type,                " Übertragungsart
           o~file_id,                   " DMS: GUID für Zuordnung PHIO - Dateiname
           o~filename AS file_path      " Original zu Dokument
    WHERE dw~dokar EQ @p_type
      AND dw~doknr EQ @p_num
      AND dw~dokvr EQ @p_ver
      AND dw~doktl EQ @p_part
    INTO TABLE @DATA(it_di).

  cl_demo_output=>write_data( it_di ).

* HTML-Code vom Demo-Output holen
  DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING title       = 'DMS'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.

Variante 2 (CDS-View P_DOCUMENTINFORECORDATTACHMENT)

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_type TYPE draw-dokar OBLIGATORY DEFAULT 'XYZ'.
* Dokumentnummer, mit Suchhilfe auf Tabelle DRAW (Dokumentinformationssatz)
PARAMETERS: p_num TYPE draw-doknr OBLIGATORY DEFAULT '10000000001' MATCHCODE OBJECT /plmb/dir_elm.
* Dokumentversion
PARAMETERS: p_ver TYPE draw-dokvr OBLIGATORY DEFAULT '00'.
* Teildokument
PARAMETERS: p_part TYPE draw-doktl OBLIGATORY DEFAULT '000'.

START-OF-SELECTION.

  SELECT FROM p_documentinforecordattachment
    FIELDS *
    WHERE documentinforecorddoctype EQ @p_type
      AND documentinforecorddocnumber EQ @p_num
      AND documentinforecorddocversion EQ @p_ver
      AND documentinforecorddocpart EQ @p_part
    INTO TABLE @DATA(it_di).

  TRY.
* 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_di ).

* 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( 'DMS' ).
      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, Short Text und Medium Text leer lassen für Autosize
      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_long_text( ) }| ).
      ENDLOOP.

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

[ABAP] DMS: Dokumenteninfosätze lesen (CVAPI_DOC_GETDETAIL), URL eines Archivdokumentes ermitteln

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_type TYPE bapi_doc_aux-doctype OBLIGATORY.
* Dokumentnummer, mit Suchhilfe auf Tabelle DRAW (Dokumentinformationssatz)
PARAMETERS: p_num TYPE bapi_doc_aux-docnumber OBLIGATORY DEFAULT '10000000001' MATCHCODE OBJECT /plmb/dir_elm.
* Teildokument
PARAMETERS: p_part TYPE bapi_doc_aux-docpart OBLIGATORY DEFAULT '000'.
* Dokumentversion
PARAMETERS: p_ver TYPE bapi_doc_aux-docversion OBLIGATORY DEFAULT '00'.

START-OF-SELECTION.
* Dokumentinformationssatz
  DATA(lv_draw) = VALUE draw(
                              doknr = p_num
                              dokar = p_type
                              doktl = p_part
                              dokvr = p_ver
                            ).

  DATA: lv_psx_draw TYPE draw.
  DATA: lv_pfx_dktxt TYPE drat-dktxt.
  DATA: it_doc_files TYPE STANDARD TABLE OF cvapi_doc_file WITH DEFAULT KEY.
  DATA: it_doc_comp TYPE STANDARD TABLE OF cvapi_doc_comp WITH DEFAULT KEY.
  DATA: it_drap TYPE STANDARD TABLE OF drap WITH DEFAULT KEY.
  DATA: it_drad TYPE STANDARD TABLE OF drad WITH DEFAULT KEY.
  DATA: it_drat TYPE STANDARD TABLE OF drat WITH DEFAULT KEY.

* DVS: Detaildaten eines Dokuments ermitteln
  CALL FUNCTION 'CVAPI_DOC_GETDETAIL'
    EXPORTING
      pf_dokar        = lv_draw-dokar
      pf_doknr        = lv_draw-doknr
      pf_dokvr        = lv_draw-dokvr
      pf_doktl        = lv_draw-doktl
      pf_read_drad    = abap_true
      pf_read_drap    = abap_true
      pf_active_files = abap_true
    IMPORTING
      psx_draw        = lv_psx_draw
      pfx_description = lv_pfx_dktxt
    TABLES
      pt_files        = it_doc_files
      pt_comp         = it_doc_comp
      pt_drap         = it_drap
      pt_drad         = it_drad
      pt_drat         = it_drat
    EXCEPTIONS
      not_found       = 1
      no_auth         = 2
      error           = 3
      OTHERS          = 4.

  IF sy-subrc = 0.

    cl_demo_output=>write_data( lv_psx_draw ).
    cl_demo_output=>write_data( lv_pfx_dktxt ).
    cl_demo_output=>write_data( it_doc_files ).
    cl_demo_output=>write_data( it_doc_comp ).
    cl_demo_output=>write_data( it_drap ).
    cl_demo_output=>write_data( it_drad ).
    cl_demo_output=>write_data( it_drat ).

* Dateien zum Dokumenteninfosatz durchloopen und anhand der physischen IDs
* die URLs für den Zugriff auf das Archivsystem holen
    LOOP AT it_doc_files ASSIGNING FIELD-SYMBOL(<f>).
      DATA(lv_urls) = VALUE sdokcompurls( ).
      DATA(lv_document_url) = CONV saeuri( '' ).

      DATA(lv_phioobj) = VALUE sdokobject( class = 'DMS_PCD1'      " Tabelle: SDOKIOCL -> DMS_PCD1 (DMS: Physikalische Objekt für Haupt-Originale)
                                           objid = <f>-ph_objid ). " PHIO-ID

* Liefert URL zum Lesen eines physischen Dokuments am Frontend
      CALL FUNCTION 'SDOK_PHIO_GET_URL_FOR_GET'
        EXPORTING
          object_id         = lv_phioobj
        IMPORTING
          urls              = lv_urls
          document_url      = lv_document_url
        EXCEPTIONS
          not_existing      = 1
          not_authorized    = 2
          no_content        = 3
          bad_storage_type  = 4
          no_urls_available = 5
          OTHERS            = 6.
      IF sy-subrc = 0.
        cl_demo_output=>write_data( lv_urls ).
        cl_demo_output=>write_data( lv_document_url ).
      ENDIF.
    ENDLOOP.

* HTML-Code vom Demo-Output holen
    DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = 'CVAPI_DOC_GETDETAIL'
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
    WRITE: space.

  ENDIF.

[ABAP] DMS: Dokumenteninfosätze löschen (BAPI_DOCUMENT_DELETE_DIRECT)

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_dtype TYPE bapi_doc_aux-doctype OBLIGATORY.
* Objekttyp (Material -> MARA)
PARAMETERS: p_otype TYPE bapi_doc_drad-objecttype OBLIGATORY DEFAULT 'MARA'.
* Objektkey (Material -> MATNR)
PARAMETERS: p_okey TYPE bapi_doc_drad-objectkey OBLIGATORY DEFAULT '000000001122334455'.

START-OF-SELECTION.

  DATA: it_doc_keys TYPE STANDARD TABLE OF bapi_doc_keys WITH DEFAULT KEY.
  DATA: lv_return   TYPE bapiret2.

* Determine Documents for an Object
  CALL FUNCTION 'BAPI_DOCUMENT_GETOBJECTDOCS'
    EXPORTING
      objecttype          = p_otype
      objectkey           = p_okey
      currentversionsonly = abap_false " alle Versionen lesen
      date                = sy-datum
    IMPORTING
      return              = lv_return
    TABLES
      documentlist        = it_doc_keys.

  IF lv_return-type CA 'EA'.
    WRITE: / lv_return-message.
  ELSE.
* Alle gefundenen Dokumenteninfosätze durchgehen
    LOOP AT it_doc_keys ASSIGNING FIELD-SYMBOL(<d>).
* Wenn Dokumenttyp gefunden
      IF <d>-documenttype = p_dtype.
        DATA: ret TYPE string.

* Abfrage zum Löschen
        CALL FUNCTION 'POPUP_TO_CONFIRM'
          EXPORTING
            titlebar              = 'Frage'
            text_question         = |Löschen DI { <d>-documentnumber } ?|
            display_cancel_button = abap_true
          IMPORTING
            answer                = ret.

        CASE ret.
          WHEN '1'.
* Ja --> löschen
* Delete document or set deletion indicator
            CALL FUNCTION 'BAPI_DOCUMENT_DELETE_DIRECT'
              EXPORTING
                documenttype    = <d>-documenttype
                documentnumber  = <d>-documentnumber
                documentpart    = <d>-documentpart
                documentversion = <d>-documentversion
              IMPORTING
                return          = lv_return.

            IF lv_return-type CA 'EA'.
* Rollback bei Fehler
              CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
            ELSE.
* Daten verbuchen
              CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                EXPORTING
                  wait = abap_true.
            ENDIF.
          WHEN OTHERS.

        ENDCASE.

      ENDIF.
    ENDLOOP.
  ENDIF.

[ABAP] DMS: Dateien von Dokumenteninfosätzen lesen (SCMS_DOC_READ)

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_type TYPE bapi_doc_aux-doctype OBLIGATORY.
* Dokumentnummer, mit Suchhilfe auf Tabelle DRAW (Dokumentinformationssatz)
PARAMETERS: p_num TYPE bapi_doc_aux-docnumber OBLIGATORY DEFAULT '10000000001' MATCHCODE OBJECT /plmb/dir_elm.
* Teildokument
PARAMETERS: p_part TYPE bapi_doc_aux-docpart OBLIGATORY DEFAULT '000'.
* Dokumentversion
PARAMETERS: p_ver TYPE bapi_doc_aux-docversion OBLIGATORY DEFAULT '00'.

START-OF-SELECTION.

  DATA: lv_bapi_doc_draw2 TYPE bapi_doc_draw2.
  DATA: lv_bapiret2 TYPE bapiret2.

  DATA: it_documentfiles TYPE STANDARD TABLE OF bapi_doc_files2 WITH DEFAULT KEY.

* Determine Detail Data for a Document
  CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
    EXPORTING
      documenttype       = p_type
      documentnumber     = p_num
      documentpart       = p_part
      documentversion    = p_ver
      getactivefiles     = abap_true
      getdocdescriptions = abap_true
      getdocfiles        = abap_true
    IMPORTING
      documentdata       = lv_bapi_doc_draw2
      return             = lv_bapiret2
    TABLES
      documentfiles      = it_documentfiles.

  cl_demo_output=>write_data( p_type ).
  cl_demo_output=>write_data( p_num ).
  cl_demo_output=>write_data( p_part ).
  cl_demo_output=>write_data( p_ver ).
  cl_demo_output=>write_data( lv_bapiret2 ).
  cl_demo_output=>write_data( lv_bapi_doc_draw2 ).
  cl_demo_output=>write_data( it_documentfiles ).

  IF lv_bapiret2-type CA 'EA'.

  ELSE.
    IF lines( it_documentfiles ) > 0.

      DATA: it_access_info TYPE STANDARD TABLE OF scms_acinf WITH DEFAULT KEY.
      DATA: it_content_txt TYPE STANDARD TABLE OF sdokcntasc WITH DEFAULT KEY.
      DATA: it_content_bin TYPE STANDARD TABLE OF sdokcntbin WITH DEFAULT KEY.

* CMS: Dokument lesen
      CALL FUNCTION 'SCMS_DOC_READ'
        EXPORTING
          stor_cat              = it_documentfiles[ 1 ]-storagecategory
          doc_id                = it_documentfiles[ 1 ]-file_id
          no_cache              = abap_true
        TABLES
          access_info           = it_access_info
          content_txt           = it_content_txt
          content_bin           = it_content_bin
        EXCEPTIONS
          bad_storage_type      = 1
          bad_request           = 2
          unauthorized          = 3
          comp_not_found        = 4
          not_found             = 5
          forbidden             = 6
          conflict              = 7
          internal_server_error = 8
          error_http            = 9
          error_signature       = 10
          error_config          = 11
          error_format          = 12
          error_parameter       = 13
          error                 = 14
          OTHERS                = 15.

      IF sy-subrc = 0.
        cl_demo_output=>write_data( it_access_info ).
        cl_demo_output=>write_data( it_content_txt ).

* Binärdaten für weitere Verarbeitung (Speichern, Anzeigen ...)	
        cl_demo_output=>write_data( it_content_bin ).
      ENDIF.
    ENDIF.

* HTML-Code vom Demo-Output holen
    DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = 'SCMS_DOC_READ'
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
    WRITE: space.
  ENDIF.

[ABAP] DMS: Verknüpfte Dokumenteninfosätze zu einem Objekt lesen (BAPI_DOCUMENT_GETOBJECTDOCS)

* Objekttyp (Material -> MARA)
PARAMETERS: p_otype TYPE bapi_doc_drad-objecttype OBLIGATORY DEFAULT 'MARA'.
* Objektkey (Material -> MATNR)
PARAMETERS: p_okey TYPE bapi_doc_drad-objectkey OBLIGATORY DEFAULT '000000001122334455'.

START-OF-SELECTION.

  DATA: it_doc_keys TYPE STANDARD TABLE OF bapi_doc_keys WITH DEFAULT KEY.
  DATA: lv_return   TYPE bapiret2.

* Determine Documents for an Object
  CALL FUNCTION 'BAPI_DOCUMENT_GETOBJECTDOCS'
    EXPORTING
      objecttype          = p_otype
      objectkey           = p_okey
      currentversionsonly = abap_false " alle Versionen lesen
      date                = sy-datum
    IMPORTING
      return              = lv_return
    TABLES
      documentlist        = it_doc_keys.

  cl_demo_output=>write_data( lv_return ).
  cl_demo_output=>write_data( it_doc_keys ).

* HTML-Code vom Demo-Output holen
  DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING title       = 'BAPI_DOCUMENT_GETOBJECTDOCS'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.

[ABAP] DMS: Dateien an Dokumenteninfosätze anhängen (CVAPI_DOC_CREATE)

TYPES: BEGIN OF bin_file,
         name TYPE string,
         size TYPE i,
         data TYPE solix_tab,
       END OF bin_file.

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_type TYPE bapi_doc_aux-doctype OBLIGATORY.
* Teildokument
PARAMETERS: p_part TYPE bapi_doc_aux-docpart OBLIGATORY DEFAULT '000'.
* Dokumentversion
PARAMETERS: p_ver TYPE bapi_doc_aux-docversion OBLIGATORY DEFAULT '00'.
* Beschreibung
PARAMETERS: p_desc TYPE bapi_doc_drat-description DEFAULT 'Test 123'.
* Ablagekategorie (TA OACT, Tabelle SDOKSTCAE, View V_SDOKSTCA)
PARAMETERS: p_stor TYPE bapi_doc_files2-storagecategory OBLIGATORY.
* Logisches Dokument/Workstation Application (TA S_ALR_87008829, Tabelle TDWP, Bild -> JPG)
PARAMETERS: p_appl TYPE bapi_doc_files2-application_id OBLIGATORY DEFAULT 'JPG'.
* Objekttyp (Material -> MARA)
PARAMETERS: p_otype TYPE bapi_doc_drad-objecttype OBLIGATORY DEFAULT 'MARA'.
* Objektkey (Material -> MATNR)
PARAMETERS: p_okey TYPE bapi_doc_drad-objectkey OBLIGATORY DEFAULT '000000001122334455'.

START-OF-SELECTION.
  TRY.
      DATA: lv_rc TYPE i.
      DATA: it_files TYPE filetable.
      DATA: lv_action TYPE i.

* FileOpen-Dialog aufrufen
      cl_gui_frontend_services=>file_open_dialog( EXPORTING file_filter = |jpg (*.jpg)\|*.jpg\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING  file_table  = it_files
                                                            rc          = lv_rc
                                                            user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* Dateien auf den Appl.-Server hochladen
          DATA: lv_file TYPE bin_file.
          cl_gui_frontend_services=>gui_upload( EXPORTING filename   = CONV #( it_files[ 1 ]-filename )
                                                          filetype   = 'BIN'
                                                IMPORTING filelength = lv_file-size
                                                CHANGING  data_tab   = lv_file-data ).

          DATA: lv_xstring TYPE xstring.

* Datei binär zu xstring wandeln
          CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
            EXPORTING
              input_length = lv_file-size
            IMPORTING
              buffer       = lv_xstring
            TABLES
              binary_tab   = lv_file-data.

* Dokumentinformationssatz
          DATA(lv_draw) = VALUE draw(
                                      dokar = p_type
                                      doktl = p_part
                                      dokvr = p_ver
                                    ).

* DVS: Steuerung für APIS
          DATA(lv_api_control) = VALUE cvapi_api_control(
                                                            no_update_task = abap_true
                                                        ).

* Kurztexte für Dokuinfosätze
          DATA: it_drat TYPE STANDARD TABLE OF dms_db_drat WITH DEFAULT KEY.
          it_drat = VALUE #( (
                                langu = sy-langu
                                dktxt = p_desc
                             )
                           ).

* Verknüpfung Dokument-Objekt
          DATA: it_drad TYPE STANDARD TABLE OF dms_db_drad WITH DEFAULT KEY.

          it_drad = VALUE #( (
                               dokob = p_otype
                               objky = p_okey
                             )
                           ).

* Originale für Dokumente (Dateianhang)
          DATA: it_bin_content TYPE STANDARD TABLE OF drao WITH DEFAULT KEY.

          DATA: lv_data_length TYPE i.
          DATA: it_content_raw TYPE STANDARD TABLE OF orblk WITH DEFAULT KEY.

* xstring --> ORBLK (Binärformat mit Zeilenlänge 2550 Bytes)
          CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
            EXPORTING
              buffer        = lv_xstring
            IMPORTING
              output_length = lv_data_length
            TABLES
              binary_tab    = it_content_raw.

* Datenaufbereitung
          LOOP AT it_content_raw ASSIGNING FIELD-SYMBOL(<raw>).

            APPEND VALUE #(
                            zaehl = sy-tabix
                            appnr = '1'
                            dokar = p_type
                            orln  = lv_data_length
*                            orbkl = 2550
                            orblk = <raw>
                          ) TO it_bin_content.
          ENDLOOP.

* DVS: Originale zu einem Dokument
          DATA: it_doc_files TYPE STANDARD TABLE OF cvapi_doc_file WITH DEFAULT KEY.

          it_doc_files = VALUE #( ( updateflag  = 'I'
                                    appnr       = '1'
                                    dappl       = p_appl
                                    filename    = it_files[ 1 ]-filename
                                    storage_cat = p_stor
                                    description = p_desc ) ).

          DATA(lv_message) = VALUE messages( ).
          DATA(lv_pfx_dokar) = VALUE draw-dokar( ).
          DATA(lv_pfx_doknr) = VALUE draw-doknr( ).
          DATA(lv_pfx_dokvr) = VALUE draw-dokvr( ).
          DATA(lv_pfx_doktl) = VALUE draw-doktl( ).

* DVS: Dokument anlegen
          CALL FUNCTION 'CVAPI_DOC_CREATE'
            EXPORTING
              ps_draw            = lv_draw
              ps_api_control     = lv_api_control
              pf_content_provide = 'TBL' " Binärdaten des Files als Tabelle übergeben
            IMPORTING
              psx_message        = lv_message
              pfx_dokar          = lv_pfx_dokar
              pfx_doknr          = lv_pfx_doknr
              pfx_dokvr          = lv_pfx_dokvr
              pfx_doktl          = lv_pfx_doktl
            TABLES
              pt_drad_x          = it_drad
              pt_drat_x          = it_drat
              pt_files_x         = it_doc_files
              pt_content         = it_bin_content.

          IF lv_message-msg_type CA 'EA'.
* Rollback bei Fehler
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSE.
* Daten verbuchen
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = abap_true.

            cl_demo_output=>write_data( lv_message ).
            cl_demo_output=>write_data( lv_pfx_dokar ).
            cl_demo_output=>write_data( lv_pfx_doknr ).
            cl_demo_output=>write_data( lv_pfx_dokvr ).
            cl_demo_output=>write_data( lv_pfx_doktl ).

* HTML-Code vom Demo-Output holen
            DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
            cl_abap_browser=>show_html( EXPORTING title       = 'CVAPI_DOC_CREATE'
                                                  html_string = lv_html
                                                  container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
            WRITE: space.
          ENDIF.
        ENDIF.
      ENDIF.
    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

[ABAP] DMS: Dateien an Dokumenteninfosätze anhängen (BAPI_DOCUMENT_CREATE2)

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_dtype TYPE bapi_doc_aux-doctype OBLIGATORY.
* Teildokument
PARAMETERS: p_dpart TYPE bapi_doc_aux-docpart OBLIGATORY DEFAULT '000'.
* Dokumentversion
PARAMETERS: p_dver TYPE bapi_doc_aux-docversion OBLIGATORY DEFAULT '00'.
* Beschreibung
PARAMETERS: p_desc TYPE bapi_doc_drat-description DEFAULT 'Test 123'.
* Ablagekategorie (TA OACT, Tabelle SDOKSTCAE, View V_SDOKSTCA)
PARAMETERS: p_stor TYPE bapi_doc_files2-storagecategory OBLIGATORY.
* Logisches Dokument/Workstation Application (TA S_ALR_87008829, Tabelle TDWP, Bild -> JPG)
PARAMETERS: p_appl TYPE bapi_doc_files2-application_id OBLIGATORY DEFAULT 'JPG'.
* Objekttyp (Material -> MARA)
PARAMETERS: p_otype TYPE bapi_doc_drad-objecttype OBLIGATORY DEFAULT 'MARA'.
* Objektkey (Material -> MATNR)
PARAMETERS: p_okey TYPE bapi_doc_drad-objectkey OBLIGATORY DEFAULT '000000001122334455'.

START-OF-SELECTION.

  TRY.
      DATA: lv_rc TYPE i.
      DATA: it_files TYPE filetable.
      DATA: lv_action TYPE i.

* FileOpen-Dialog aufrufen
      cl_gui_frontend_services=>file_open_dialog( EXPORTING file_filter = |jpg (*.jpg)\|*.jpg\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING  file_table  = it_files
                                                            rc          = lv_rc
                                                            user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.

          DATA(lv_bapi_doc_draw2) = VALUE bapi_doc_draw2(
                                                          documenttype    = p_dtype
                                                          documentversion = p_dver
                                                          documentpart    = p_dpart
                                                        ).

          DATA: lv_documenttype TYPE bapi_doc_aux-doctype.
          DATA: lv_documentnumber TYPE bapi_doc_aux-docnumber.
          DATA: lv_documentpart TYPE bapi_doc_aux-docpart.
          DATA: lv_documentversion TYPE bapi_doc_aux-docversion.
          DATA: lv_return TYPE bapiret2.

          DATA: it_documentdescriptions TYPE STANDARD TABLE OF bapi_doc_drat WITH DEFAULT KEY.
          it_documentdescriptions = VALUE #( (
                                                description  = p_desc
                                                language     = 'D'
                                                language_iso = 'DE'
                                             )
                                           ).

          DATA: it_documentfiles TYPE STANDARD TABLE OF bapi_doc_files2 WITH DEFAULT KEY.

          it_documentfiles = VALUE #( (
                                        originaltype      = '1'
*                                        sourcedatacarrier = 'SAP-SYSTEM' " oder 'DEFAULT'
                                        created_by        = sy-uname
                                        storagecategory   = p_stor
                                        docfile           = it_files[ 1 ]-filename
                                        wsapplication     = p_appl
*                                        checkedin         = abap_true
                                      )
                                    ).

          DATA: it_objectlinks TYPE STANDARD TABLE OF bapi_doc_drad WITH DEFAULT KEY.

          it_objectlinks = VALUE #( (
                                      objecttype    = p_otype
                                      objectkey     = p_okey
                                    )
                                  ).

* Create Document
          CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
            EXPORTING
              documentdata         = lv_bapi_doc_draw2
            IMPORTING
              documenttype         = lv_documenttype
              documentnumber       = lv_documentnumber
              documentversion      = lv_documentversion
              documentpart         = lv_documentpart
              return               = lv_return
            TABLES
              documentdescriptions = it_documentdescriptions
              documentfiles        = it_documentfiles
              objectlinks          = it_objectlinks.

          IF lv_return-type CA 'EA'.
* Rollback bei Fehler
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSE.
* Daten verbuchen
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = abap_true.

            cl_demo_output=>write_data( lv_documenttype ).
            cl_demo_output=>write_data( lv_documentnumber ).
            cl_demo_output=>write_data( lv_documentversion ).
            cl_demo_output=>write_data( lv_documentpart ).
            cl_demo_output=>write_data( lv_return ).

* HTML-Code vom Demo-Output holen
            DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
            cl_abap_browser=>show_html( EXPORTING title       = 'BAPI_DOCUMENT_CREATE2'
                                                  html_string = lv_html
                                                  container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
            WRITE: space.
          ENDIF.
        ENDIF.
      ENDIF.
    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

Links

[ABAP] DMS: Dokumenteninfosätze lesen (BAPI_DOCUMENT_GETDETAIL2)

* Dokumentart (TA DC10, Tabelle TDWA)
PARAMETERS: p_type TYPE bapi_doc_aux-doctype OBLIGATORY.
* Dokumentnummer, mit Suchhilfe auf Tabelle DRAW (Dokumentinformationssatz)
PARAMETERS: p_num TYPE bapi_doc_aux-docnumber MATCHCODE OBJECT /plmb/dir_elm.
* Teildokument
PARAMETERS: p_part TYPE bapi_doc_aux-docpart OBLIGATORY.
* Dokumentversion
PARAMETERS: p_ver TYPE bapi_doc_aux-docversion OBLIGATORY.

START-OF-SELECTION.

  DATA: lv_bapi_doc_draw2 TYPE bapi_doc_draw2.
  DATA: lv_bapiret2 TYPE bapiret2.

  DATA: it_objectlinks TYPE STANDARD TABLE OF bapi_doc_drad WITH DEFAULT KEY.
  DATA: it_documentdescriptions TYPE STANDARD TABLE OF bapi_doc_drat WITH DEFAULT KEY.
  DATA: it_longtexts TYPE STANDARD TABLE OF bapi_doc_text WITH DEFAULT KEY.
  DATA: it_statuslog TYPE STANDARD TABLE OF bapi_doc_drap WITH DEFAULT KEY.
  DATA: it_documentfiles TYPE STANDARD TABLE OF bapi_doc_files2 WITH DEFAULT KEY.
  DATA: it_components TYPE STANDARD TABLE OF bapi_doc_comp WITH DEFAULT KEY.
  DATA: it_characteristicvalues TYPE STANDARD TABLE OF bapi_characteristic_values WITH DEFAULT KEY.
  DATA: it_classallocations TYPE STANDARD TABLE OF bapi_class_allocation WITH DEFAULT KEY.
  DATA: it_documentstructure TYPE STANDARD TABLE OF bapi_doc_structure WITH DEFAULT KEY.
  DATA: it_whereusedlist TYPE STANDARD TABLE OF bapi_doc_structure WITH DEFAULT KEY.

* Determine Detail Data for a Document
  CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
    EXPORTING
      documenttype         = p_type
      documentnumber       = p_num
      documentpart         = p_part
      documentversion      = p_ver
      getobjectlinks       = abap_true
      getcomponents        = abap_true
      getstatuslog         = abap_true
      getlongtexts         = abap_true
      getactivefiles       = abap_true
      getdocdescriptions   = abap_true
      getdocfiles          = abap_true
      getclassification    = abap_true
      getstructure         = abap_true
      getwhereused         = abap_true
*     hostname             = ''
      inherited            = abap_true
*     PF_BAPI_CALL         =
    IMPORTING
      documentdata         = lv_bapi_doc_draw2
      return               = lv_bapiret2
    TABLES
      objectlinks          = it_objectlinks
      documentdescriptions = it_documentdescriptions
      longtexts            = it_longtexts
      statuslog            = it_statuslog
      documentfiles        = it_documentfiles
      components           = it_components
      characteristicvalues = it_characteristicvalues
      classallocations     = it_classallocations
      documentstructure    = it_documentstructure
      whereusedlist        = it_whereusedlist.

  cl_demo_output=>write_data( p_type ).
  cl_demo_output=>write_data( p_num ).
  cl_demo_output=>write_data( p_part ).
  cl_demo_output=>write_data( p_ver ).
  cl_demo_output=>write_data( lv_bapiret2 ).
  cl_demo_output=>write_data( lv_bapi_doc_draw2 ).
  cl_demo_output=>write_data( it_objectlinks ).
  cl_demo_output=>write_data( it_documentdescriptions ).
  cl_demo_output=>write_data( it_longtexts ).
  cl_demo_output=>write_data( it_statuslog ).
  cl_demo_output=>write_data( it_documentfiles ).
  cl_demo_output=>write_data( it_components ).
  cl_demo_output=>write_data( it_characteristicvalues ).
  cl_demo_output=>write_data( it_classallocations ).
  cl_demo_output=>write_data( it_documentstructure ).
  cl_demo_output=>write_data( it_whereusedlist ).

* HTML-Code vom Demo-Output holen
  DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING title       = 'Infos'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.

[ABAP] Archivierte Objekte lesen

*  Beispiele:
*
*  https://www.abapforum.com/forum/viewtopic.php?t=1196
*  https://copycodesap.wordpress.com/2014/10/27/custom-table-archival-read-program/
*
*  Transaktion:
*    ALO1 (Ermitteln Verknüpfungen ASH/DOREX)
*
*  Reports:
*    SBOOKR
*    SBOOKR_2
*    SBOOKR_3
*    RDRBFI00
*
*  Paket: SARC
*  Funktionsgruppe: ARCH
*
*  Funktionsbausteine:
*
*    ARCHIVE_CLOSE_FILE (Offene Archivdateien werden geschlossen)
*    ARCHIVE_GET_CUSTOMIZING_DATA (Customizing-Daten eines Archivierungsobjektes lesen)
*    ARCHIVE_GET_INFORMATION (Archivobjekt-Informationen werden aufgrund eines Handles übergeben)
*    ARCHIVE_GET_NEXT_OBJECT (Datenobjekt aus der Archivdatei lesen)
*    ARCHIVE_GET_NEXT_RECORD (Sequentielles Lesen der Sätze aus einem Datenobjekt)
*    ARCHIVE_GET_STATISTICS (Übernahme der vom ADK gesammelten Statistikdaten)
*    ARCHIVE_GET_TABLE (Sätze strukturgerecht aus aktuellem Datenobjekt lesen)
*    ARCHIVE_GIVE_STATISTICS (Übergabe von Statistikdaten in Programmen der Datenarchivierung)
*    ARCHIVE_NEW_OBJECT (Datenobjekt zum Schreiben anfordern)
*    ARCHIVE_OPEN_FOR_DELETE (Archivdatei öffnen zum Löschen der Sätze in der Datenbank)
*    ARCHIVE_OPEN_FOR_MOVE (Datenobjekte in eine neue Archivdatei schreiben und/oder zurückladen)
*    ARCHIVE_OPEN_FOR_READ (Öffnen einer vorhandenen Archivdatei zum Lesen)
*    ARCHIVE_OPEN_FOR_WRITE (Archivdatei zum Schreiben öffnen)
*    ARCHIVE_PUT_RECORD (Datensatz in Datenobjekt schreiben)
*    ARCHIVE_PUT_TABLE (Sätze strukturgerecht in aktuelles Datenobjekt stellen)
*    ARCHIVE_READ_OBJECT (Lesen eines Datenobjektes aus einer Archivdatei)
*    ARCHIVE_SAVE_OBJECT (Datenobjekt in die Archivdatei schreiben)
*    ARCHIVE_WRITE_STATISTICS (Ausgabe der vom ADK gesammelten Statistikdaten (Standardprotokoll))
*
*  Paket: SWW
*  Funktionsgruppe: SWWX
*
*  Funktionsbausteine:
*
*    WORKITEM_ARCHIVE_GET_TABLE (Lesen von archivierten Workitems)
*    WORKITEM_ARCHIVE_OBJECT (Archivierungsklasse WORKITEM: Schreiben eines Workitems in ein Archiv)
*    WORKITEM_ARCHIVE_PUT_TABLE (Übergabe konvertierter Daten an das ADK)
*    WORKITEM_READ_ARCHIVE_OBJ (Archivierungsklasse WORKITEM: Lesen von Workitems aus dem Archiv)
*
*  Tabellen:
*
*    ARCH_OBJ (Objekte für die Archivierung und Reorganisation)
*    ARCH_TXT (Bezeichnung der Archivierungsobjekte)
*    ARCH_DEF (Definition eines Archivierungsobjekts)
*    ADMI_RUN (Archivierungsläufe Kopfdaten)
*    ADMI_FILES (Archivdateien der Archivierungsläufe)
*    PATH (Definition der physischen Dateipfade je Syntax)
*    FILENAME (Umsetztabelle von internen Dateinamen in externe Dateinamen)
*    FILESYS (Definition der Gruppen der Dateibeschreibungssyntax)
*    FSYSTXT (Bezeichnung der Dateibeschreibungssyntax)
*    FILENAMECI (Plattformunabhängige Dateinamen, mandantenübergreifend)
*    FILEPATH (Definition der logischen Dateipfade)
*    PATHTEXT (Bezeichnung der logischen Dateipfade)
*
*  Customizing Dateipfade:
*
*  Transaktion FILE
*  oder
*  SPRO -> SAP NetWeaver -> Application Server -> Systemadministration -> Plattformunabhängige Dateinamen -> Dateinamen und Dateipfade mandantenunabhängig pflegen

* Archivierungsobjekt
PARAMETERS: p_obj TYPE arch_def-object DEFAULT 'CHANGEDOCU'.

DATA(lv_handle) = VALUE sy-tabix( ).
DATA: it_archive_files TYPE STANDARD TABLE OF rng_archiv WITH DEFAULT KEY.
DATA: it_selected_files TYPE STANDARD TABLE OF admi_files WITH DEFAULT KEY.

* Öffnen einer vorhandenen Archivdatei zum Lesen
* wenn nur ein Wert für "object" angegeben wurde, dann erscheint ein Auswahl-Popup
CALL FUNCTION 'ARCHIVE_OPEN_FOR_READ'
  EXPORTING
*   archive_document             = '000000'
*   ARCHIVE_NAME                 = ' '
    object                       = p_obj
*   MAINTAIN_INDEX               = ' '
  IMPORTING
    archive_handle               = lv_handle
  TABLES
    archive_files                = it_archive_files
    selected_files               = it_selected_files
  EXCEPTIONS
    file_already_open            = 1
    file_io_error                = 2
    internal_error               = 3
    no_files_available           = 4
    object_not_found             = 5
    open_error                   = 6
    not_authorized               = 7
    archiving_standard_violation = 8
    OTHERS                       = 9.

IF sy-subrc = 0.
* Testweise den externen Speicherpfad im UNIX-Dateisystem ermitteln
  LOOP AT it_selected_files ASSIGNING FIELD-SYMBOL(<f>).
    SELECT SINGLE pathextern
      INTO @DATA(lv_pathextern)
      FROM path
      WHERE pathintern = @<f>-pathintern
        AND filesys = 'UNIX'.

    WRITE: / <f>-document, <f>-archiv_key, <f>-pathintern, lv_pathextern.
  ENDLOOP.

  ULINE.

  DO.
* Datenobjekt aus der Archivdatei lesen
    CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT'
      EXPORTING
        archive_handle          = lv_handle
*         IMPORTING
*       OBJECT_ID               =
*       OBJECT_OFFSET           =
*       ARCHIVE_NAME            =
*       COMPR_OBJECT_LENGTH     =
*       SESSION                 =
*       EV_CONTAIN_BLOCKED_DATA =
      EXCEPTIONS
        end_of_file             = 1
        file_io_error           = 2
        internal_error          = 3
        open_error              = 4
        wrong_access_to_archive = 5
        OTHERS                  = 6.

    IF sy-subrc <> 0.
* Keine Objekte mehr
      EXIT.
    ELSE.
      DO.
        DATA(lv_data_struct) = VALUE arc_buffer-rname( ).
* Datenreferenz -> Unicodefähigkeit
        DATA: o_data_ref TYPE REF TO data.

* Sequentielles Lesen der Sätze aus einem Datenobjekt
        CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD'
          EXPORTING
            archive_handle   = lv_handle
          IMPORTING
            record_structure = lv_data_struct
            record_ref       = o_data_ref
          EXCEPTIONS
            end_of_object    = 1
            OTHERS           = 2.

        IF sy-subrc <> 0.
* Keine Daten mehr
          EXIT.
        ELSE.
* Farbe definieren
          FORMAT COLOR COL_HEADING.
* Ausgabetext
          WRITE: / 'Struktur:', to_upper( lv_data_struct ).
* Leerzeichen am Zeilenende, damit der Farbbalken durchgezogen wird
          WRITE AT sy-linsz space.
* Farbdefinition abschalten
          FORMAT COLOR OFF.

* Generische Datenausgabe
* Strukturbeschreibung der akt. Archivstruktur
          DATA(o_desc) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name( lv_data_struct ) ).
* Komponenten
          DATA(gt_comp) = o_desc->get_components( ).
* generische Objekte für Zugriff
          FIELD-SYMBOLS: <row> TYPE any.
          ASSIGN o_data_ref->* TO <row>.

          DATA(lv_head) = ||.
          DATA(lv_data) = ||.

* Alle Felder der Struktur durchloopen
          LOOP AT gt_comp ASSIGNING FIELD-SYMBOL(<c>).
* Spaltenbreite
            DATA(lv_width) = strlen( <c>-name ).

* Prüfen, ob DDIC-Typ
            DATA(o_edesc) = CAST cl_abap_elemdescr( <c>-type ).
            IF o_edesc->is_ddic_type( ) EQ abap_true.
* Feld anhand des Komponentennamens aus der Struktur ermitteln und Feldsymbol zuweisen
              ASSIGN COMPONENT <c>-name OF STRUCTURE <row> TO FIELD-SYMBOL(<cell>).
              IF <cell> IS ASSIGNED.
* Spaltenbreite, falls Zellinhalt breiter
                IF strlen( condense( <cell> ) ) > lv_width.
                  lv_width = strlen( condense( <cell> ) ).
                ENDIF.

* Formatierung Daten
                lv_data = COND #( WHEN lv_data IS INITIAL THEN |{ condense( <cell> ) WIDTH = lv_width }| ELSE |{ lv_data }\|{ condense( <cell> ) WIDTH = lv_width }| ).
              ENDIF.
            ENDIF.

* Formatierung Kopf
            lv_head = COND #( WHEN lv_head IS INITIAL THEN |{ <c>-name WIDTH = lv_width }| ELSE |{ lv_head }\|{ <c>-name WIDTH = lv_width }| ).

          ENDLOOP.

* Ausgabe
          WRITE: / lv_head.
          WRITE: / lv_data.

          ULINE.
        ENDIF.

      ENDDO.
    ENDIF.
  ENDDO.

* Offene Archivdateien werden geschlossen
  CALL FUNCTION 'ARCHIVE_CLOSE_FILE'
    EXPORTING
      archive_handle = lv_handle.

ENDIF.

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