Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
FredericGirod
Active Contributor

The goal of this doc, is to give some tools to access to file store using GOS & ArchiveLink

The big problem of GOS is: you could store documents in different places. You will need to use different method / functions to read the document depending of the location.

Lets take an example, a Sales Order :

At first you could think all the documents are stored in the same place, but it's not. A detail could give you this information quickly. There is no creator for object post on a HTTP Content Server.





1. Get the list of document store in the HTTP Content Server.



Code


DATA : lw_objecttype  TYPE saeanwdid ,
        lw_object_id   TYPE saeobjid ,

        lt_connections TYPE toav0_t .


MOVE : '0000009122' TO lw_object_id ,
       'VBAK'       TO lw_objecttype .

CALL FUNCTION 'ARCHIV_GET_CONNECTIONS'
   EXPORTING
     objecttype    = lw_objecttype
     object_id     = lw_object_id
   TABLES
     connections   = lt_connections
   EXCEPTIONS
     nothing_found = 1
     OTHERS        = 2.



The result in debug is



5 documents store in the Content Repository Z1

1 document store in the Content Repository Z2




Sample code to read the content of the last file.


Code
DATA : lw_objecttype  TYPE saeanwdid ,
        lw_object_id   TYPE saeobjid  ,
        lw_file        TYPE string ,
        lw_path        TYPE string ,
        lw_fullpath    TYPE string ,
        lw_doctype     TYPE saedoktyp ,
        lw_length      TYPE num12 ,
        lw_offset      TYPE num12 ,
        lw_size        TYPE i ,
        ls_connection  TYPE toav0 ,

        lt_connections TYPE toav0_t ,
        lt_data        TYPE tabl1024_t .


MOVE : '0000009122' TO lw_object_id ,
       'VBAK'       TO lw_objecttype .


* Get the list of documents link to the Sales Order
CALL FUNCTION 'ARCHIV_GET_CONNECTIONS'
   EXPORTING
     objecttype    = lw_objecttype
     object_id     = lw_object_id
   TABLES
     connections   = lt_connections
   EXCEPTIONS
     nothing_found = 1
     OTHERS        = 2.



* Get the last entry.
LOOP AT lt_connections
      INTO ls_connection.
ENDLOOP.


* Change the type of the field for Document Type (=PDF)
MOVE ls_connection-reserve TO lw_doctype.


* Get the Content of the entry in Binary Mode (more simple for PDF)
CALL FUNCTION 'ARCHIVOBJECT_GET_BYTES'
   EXPORTING
     archiv_id                = ls_connection-archiv_id
     archiv_doc_id            = ls_connection-arc_doc_id
     document_type            = lw_doctype
     length                   = lw_length
     offset                   = lw_offset
   IMPORTING
     binlength                = lw_length
   TABLES
     binarchivobject          = lt_data
   EXCEPTIONS
     error_archiv             = 1
     error_communicationtable = 2
     error_kernel             = 3
     OTHERS                   = 4.
CHECK sy-subrc EQ space.



* Ask user for the name and the location of the file
CALL METHOD cl_gui_frontend_services=>file_save_dialog
   CHANGING
     filename             = lw_file
     path                 = lw_path
     fullpath             = lw_fullpath
   EXCEPTIONS
     cntl_error           = 1
     error_no_gui         = 2
     not_supported_by_gui = 3
     OTHERS               = 4.


MOVE lw_length TO lw_size.


* Save the file.
CALL METHOD cl_gui_frontend_services=>gui_download
   EXPORTING
     bin_filesize            = lw_size
     filename                = lw_file
     filetype                = 'BIN'
   CHANGING
     data_tab                = lt_data
   EXCEPTIONS
     OTHERS                  = 24.





2. Get the list of document store in the default SAP tables.



Code


DATA : w_file_type  TYPE fileformat ,

        is_role      TYPE obl_s_rolt ,
        is_object    TYPE sibflporb  ,
        is_relation  TYPE obl_s_relt ,

        it_objects   TYPE sibflporbt,
        it_link_a    TYPE obl_t_link ,
        it_roles     TYPE obl_t_rolt ,
        it_relations TYPE obl_t_relt.


* The object Key
MOVE : '0000009122' TO is_object-instid ,
        'BUS2032'    TO is_object-typeid ,
        'BO'         TO is_object-catid .
APPEND is_object TO it_objects.


* The kind of object
MOVE : 'I'          TO is_role-sign ,
        'EQ'         TO is_role-option ,
        'GOSAPPLOBJ' TO is_role-low.
APPEND is_role TO it_roles.
MOVE : 'I'          TO is_relation-sign ,
        'EQ'         TO is_relation-option ,
        'ATTA'       TO is_relation-low .
APPEND is_relation TO it_relations.

MOVE : 'BIN' TO w_file_type.



* Extraction des liens.
TRY.
     CALL METHOD cl_binary_relation=>read_links_of_objects
       EXPORTING
         it_objects          = it_objects
*       ip_logsys           =
         it_role_options     = it_roles
         it_relation_options = it_relations
*       ip_no_buffer        = SPACE
       IMPORTING
         et_links_a          = it_link_a.
   CATCH cx_obl_model_error .
   CATCH cx_obl_parameter_error .
   CATCH cx_obl_internal_error .
ENDTRY.


The result in debug mode will be :



To read the data, we will used a SAP Office function. Because the file are stored in the SAP Office table SOO*


Code
DATA : lw_file_type  TYPE fileformat ,
        lw_file       TYPE string ,
        lw_path       TYPE string ,
        lw_fullpath   TYPE string ,
        lw_doc_id     TYPE so_entryid ,

        ls_role      TYPE obl_s_rolt ,
        ls_object    TYPE sibflporb  ,
        ls_relation  TYPE obl_s_relt ,
        ls_link_a    TYPE obl_s_link ,
        ls_doc_data  TYPE sofolenti1 ,

        lt_objects   TYPE sibflporbt ,
        lt_link_a    TYPE obl_t_link ,
        lt_roles     TYPE obl_t_rolt ,
        lt_relations TYPE obl_t_relt ,
        lt_content   TYPE TABLE OF solisti1  ,
        lt_contentx  TYPE solix_tab.


* The object Key
MOVE : '0000009122' TO ls_object-instid ,
        'BUS2032'    TO ls_object-typeid ,
        'BO'         TO ls_object-catid .
APPEND ls_object TO lt_objects.


* The kind of object
MOVE : 'I'          TO ls_role-sign ,
        'EQ'         TO ls_role-option ,
        'GOSAPPLOBJ' TO ls_role-low.
APPEND ls_role TO lt_roles.
MOVE : 'I'          TO ls_relation-sign ,
        'EQ'         TO ls_relation-option ,
        'ATTA'       TO ls_relation-low .
APPEND ls_relation TO lt_relations.

MOVE : 'BIN' TO lw_file_type.



* Extraction des liens.
TRY.
     CALL METHOD cl_binary_relation=>read_links_of_objects
       EXPORTING
         it_objects          = lt_objects
         it_role_options     = lt_roles
         it_relation_options = lt_relations
       IMPORTING
         et_links_a          = lt_link_a.
   CATCH cx_obl_model_error .
   CATCH cx_obl_parameter_error .
   CATCH cx_obl_internal_error .
ENDTRY.



LOOP AT lt_link_a
      INTO ls_link_a.
ENDLOOP.

MOVE ls_link_a-instid_b TO lw_doc_id .


CALL FUNCTION 'SO_DOCUMENT_READ_API1'
   EXPORTING
     document_id                = lw_doc_id
   IMPORTING
     document_data              = ls_doc_data
   TABLES
     object_content             = lt_content
     contents_hex               = lt_contentx
   EXCEPTIONS
     document_id_not_exist      = 1
     operation_no_authorization = 2
     x_error                    = 3
     OTHERS                     = 4.





* Ask user for the name and the location of the file
CALL METHOD cl_gui_frontend_services=>file_save_dialog
   CHANGING
     filename             = lw_file
     path                 = lw_path
     fullpath             = lw_fullpath
   EXCEPTIONS
     cntl_error           = 1
     error_no_gui         = 2
     not_supported_by_gui = 3
     OTHERS               = 4.



* Save the file.
CALL METHOD cl_gui_frontend_services=>gui_download
   EXPORTING
*   bin_filesize = lw_size
     filename     = lw_file
     filetype     = 'BIN'
   CHANGING
     data_tab     = lt_contentx
   EXCEPTIONS
     OTHERS       = 24.