***Attaching files to documentum using GOS services can have two ways either manual or automatic (early or late archival). Recently I came across some requirement where my customer wanted to download the attachments of an invoice for auditing purpose. This is something very rare and you would not find a straight away solution for it.
***In my requirement the invoice document could have both archived and non-archived files which was needed to be downloaded. Here is how I achieved it.
***
***Non-Archived /Manually attached Files
* Local Data Declartions
DATA l_i_rel TYPE obl_t_relt.
DATA l_wa_rel TYPE obl_s_relt.
DATA l_wa_object TYPE sibflporb.
DATA l_v_sys TYPE logsys.
DATA l_i_links TYPE obl_t_link.
DATA l_v_documnt TYPE so_entryid.
DATA l_wa_document_data TYPE sofolenti1.
DATA l_i_header TYPE STANDARD TABLE OF solisti1.
DATA l_wa_text TYPE text200.
DATA l_v_filenam TYPE cacl_string.
DATA l_v_filetyp TYPE sychar10.
DATA l_v_var TYPE cacl_string.
DATA l_v_sortfi TYPE sychar30.
DATA l_wa_documntid TYPE sofmk.
DATA l_i_content TYPE swftlisti1.
DATA l_v_extct TYPE so_extct.
DATA l_v_doc_siz TYPE so_doc_len.
DATA l_v_flename TYPE cacl_string.
DATA: l_i_tbl1024 TYPE STANDARD TABLE OF tbl1024,
l_i_toa02 TYPE STANDARD TABLE OF toa02,
l_v_length TYPE syindex,
l_v_mime TYPE sychar132,
l_cnt TYPE belnr_d,
l_v_archived_filename TYPE sychar132.
FIELD-SYMBOLS: <l_fs_tab> TYPE toa02 ."toav0.
FIELD-SYMBOLS <l_fs_links> TYPE obl_s_link.
FIELD-SYMBOLS <l_fs_header> TYPE solisti1.
FIELD-SYMBOLS <l_fs_content> TYPE solisti1.
CONSTANTS l_c_i TYPE ddsign VALUE 'I'.
CONSTANTS l_c_eq TYPE ddoption VALUE 'EQ'.
CONSTANTS l_c_atta TYPE oblreltype VALUE 'ATTA'.
CONSTANTS l_c_note TYPE oblreltype VALUE 'NOTE'.
CONSTANTS l_c_dot TYPE sychar01 VALUE '.'.
CONSTANTS l_c_slas TYPE sychar01 VALUE '\'.
CONSTANTS l_c_equ TYPE sychar01 VALUE '='.
CONSTANTS l_c_k TYPE so_extct VALUE 'K'.
CONSTANTS l_c_und TYPE sychar01 VALUE '_'.
l_wa_rel-sign = l_c_i.
l_wa_rel-option = l_c_eq.
l_wa_rel-low = l_c_atta.
APPEND l_wa_rel TO l_i_rel.
CLEAR l_wa_rel-low.
l_wa_rel-low = l_c_note.
APPEND l_wa_rel TO l_i_rel.
CLEAR l_wa_rel.
l_wa_object-instid = 510000062009(Your Object key e.g. Doc No+DocYear).
l_wa_object-typeid = 'BUS2081' (For Invoice Document)
l_wa_object-catid = 'BO' (Keep it as it is)
* Download NON-ARCHIVED Files.
TRY.
CALL METHOD cl_binary_relation=>read_links
EXPORTING
is_object = l_wa_object
ip_logsys = l_v_sys
it_relation_options = l_i_rel
IMPORTING
et_links = l_i_links.
CATCH cx_obl_parameter_error
cx_obl_internal_error
cx_obl_model_error.
RAISE no_link_found.
ENDTRY.
TRY.
LOOP AT l_i_links ASSIGNING <l_fs_links>.
MOVE <l_fs_links>-instid_b TO l_v_documnt.
IF l_v_documnt IS NOT INITIAL.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = l_v_documnt
IMPORTING
document_data = l_wa_document_data
TABLES
object_header = l_i_header
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
RAISE no_link_found.
ELSE.
CONCATENATE l_wa_document_data-obj_descr l_c_dot
l_wa_document_data-obj_type
INTO l_v_filenam.
ENDIF.
MOVE l_wa_document_data-obj_type TO l_v_filetyp.
READ TABLE l_i_header ASSIGNING <l_fs_header> INDEX 2.
IF sy-subrc IS INITIAL.
SPLIT <l_fs_header>-line AT l_c_equ INTO l_v_var l_v_filetyp.
ENDIF.
CONDENSE l_v_filetyp.
l_wa_documntid = <l_fs_links>-instid_b.
CONCATENATE l_wa_documntid-doctp
l_wa_documntid-docyr
l_wa_documntid-docno INTO l_v_sortfi.
IMPORT objcont_tab TO l_i_content
FROM DATABASE soc3(dt) ID l_v_sortfi.
IF sy-subrc IS INITIAL.
READ TABLE l_i_content ASSIGNING <l_fs_content> INDEX 1.
IF sy-subrc IS INITIAL.
IF <l_fs_content>-line CP 'KPro'
l_v_extct = l_c_k.
ELSE.
CLEAR l_v_extct.
ENDIF.
ENDIF.
ENDIF.
MOVE l_wa_document_data-doc_size TO l_v_doc_siz.
CALL FUNCTION 'SO_OBJECT_DOWNLOAD'
EXPORTING
bin_filesize = l_v_doc_siz
filetype = l_v_filetyp
path_and_file = l_v_filenam
extct = l_v_extct
no_dialog = abap_true
IMPORTING
act_filename = l_v_flename
TABLES
objcont = l_i_content
EXCEPTIONS
file_write_error = 1
invalid_type = 2
x_error = 3
kpro_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
RAISE no_link_found.
ENDIF.
ENDIF.
CLEAR: l_i_content, l_v_extct.
ENDLOOP.
CATCH cx_sy_conversion_no_number
cx_sy_conversion_overflow
cx_sy_move_cast_error
cx_sy_conversion_codepage
cx_sy_import_format_error
cx_sy_import_mismatch_error.
RAISE no_link_found.
ENDTRY.
* Download Archived Files
*We need the SAP to Documentum link, this is available in TOA* tables, and it depends in which table you find the relation. For me its TOA02, it may not be same for you.
*In case you dont find use Function module ARCHIV_CONNECTINFO_GET_META and use the parameters sap_object and object_id as in below select.
*
*I am using table TOA02 to get all Archive ids.
SELECT * FROM toa02 INTO TABLE l_i_toa02 WHERE
sap_object = 'BUS2081' AND
object_id = 5100000062009. (for me its Invoice document)
IF sy-subrc NE 0.
RETURN.
ELSE.
LOOP AT l_i_toa02 ASSIGNING <l_fs_tab>.
l_cnt = l_cnt + 1.
CLEAR: l_v_archived_filename, l_v_length, l_i_tbl1024.
CONCATENATE ' C:\DATA\DOCUMENTUM' '\' '_Arc_' l_cnt '.' <l_fs_tab>-reserve
INTO l_v_archived_filename.
CONDENSE l_v_archived_filename.
CALL FUNCTION 'SCMS_AO_TABLE_GET'
EXPORTING
arc_id = <l_fs_tab>-archiv_id
doc_id = <l_fs_tab>-arc_doc_id
IMPORTING
length = l_v_length
TABLES
data = l_i_tbl1024
EXCEPTIONS
error_http = 1
error_archiv = 2
error_kernel = 3
error_config = 4
OTHERS = 5.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
CALL FUNCTION 'SCMS_DOWNLOAD'
EXPORTING
filename = l_v_archived_filename "'C:\DATA\DOCUMENTUM\....
filesize = l_v_length
mimetype = l_v_mime
TABLES
data = l_i_tbl1024
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
ENDLOOP.
ENDIF.
This complete code will create a folder C:\Data\Documentum in your PC and you will find all downloaded attachments there. Happy Downloading
***In my requirement the invoice document could have both archived and non-archived files which was needed to be downloaded. Here is how I achieved it.
***
***Non-Archived /Manually attached Files
* Local Data Declartions
DATA l_i_rel TYPE obl_t_relt.
DATA l_wa_rel TYPE obl_s_relt.
DATA l_wa_object TYPE sibflporb.
DATA l_v_sys TYPE logsys.
DATA l_i_links TYPE obl_t_link.
DATA l_v_documnt TYPE so_entryid.
DATA l_wa_document_data TYPE sofolenti1.
DATA l_i_header TYPE STANDARD TABLE OF solisti1.
DATA l_wa_text TYPE text200.
DATA l_v_filenam TYPE cacl_string.
DATA l_v_filetyp TYPE sychar10.
DATA l_v_var TYPE cacl_string.
DATA l_v_sortfi TYPE sychar30.
DATA l_wa_documntid TYPE sofmk.
DATA l_i_content TYPE swftlisti1.
DATA l_v_extct TYPE so_extct.
DATA l_v_doc_siz TYPE so_doc_len.
DATA l_v_flename TYPE cacl_string.
DATA: l_i_tbl1024 TYPE STANDARD TABLE OF tbl1024,
l_i_toa02 TYPE STANDARD TABLE OF toa02,
l_v_length TYPE syindex,
l_v_mime TYPE sychar132,
l_cnt TYPE belnr_d,
l_v_archived_filename TYPE sychar132.
FIELD-SYMBOLS: <l_fs_tab> TYPE toa02 ."toav0.
FIELD-SYMBOLS <l_fs_links> TYPE obl_s_link.
FIELD-SYMBOLS <l_fs_header> TYPE solisti1.
FIELD-SYMBOLS <l_fs_content> TYPE solisti1.
CONSTANTS l_c_i TYPE ddsign VALUE 'I'.
CONSTANTS l_c_eq TYPE ddoption VALUE 'EQ'.
CONSTANTS l_c_atta TYPE oblreltype VALUE 'ATTA'.
CONSTANTS l_c_note TYPE oblreltype VALUE 'NOTE'.
CONSTANTS l_c_dot TYPE sychar01 VALUE '.'.
CONSTANTS l_c_slas TYPE sychar01 VALUE '\'.
CONSTANTS l_c_equ TYPE sychar01 VALUE '='.
CONSTANTS l_c_k TYPE so_extct VALUE 'K'.
CONSTANTS l_c_und TYPE sychar01 VALUE '_'.
l_wa_rel-sign = l_c_i.
l_wa_rel-option = l_c_eq.
l_wa_rel-low = l_c_atta.
APPEND l_wa_rel TO l_i_rel.
CLEAR l_wa_rel-low.
l_wa_rel-low = l_c_note.
APPEND l_wa_rel TO l_i_rel.
CLEAR l_wa_rel.
l_wa_object-instid = 510000062009(Your Object key e.g. Doc No+DocYear).
l_wa_object-typeid = 'BUS2081' (For Invoice Document)
l_wa_object-catid = 'BO' (Keep it as it is)
* Download NON-ARCHIVED Files.
TRY.
CALL METHOD cl_binary_relation=>read_links
EXPORTING
is_object = l_wa_object
ip_logsys = l_v_sys
it_relation_options = l_i_rel
IMPORTING
et_links = l_i_links.
CATCH cx_obl_parameter_error
cx_obl_internal_error
cx_obl_model_error.
RAISE no_link_found.
ENDTRY.
TRY.
LOOP AT l_i_links ASSIGNING <l_fs_links>.
MOVE <l_fs_links>-instid_b TO l_v_documnt.
IF l_v_documnt IS NOT INITIAL.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = l_v_documnt
IMPORTING
document_data = l_wa_document_data
TABLES
object_header = l_i_header
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
RAISE no_link_found.
ELSE.
CONCATENATE l_wa_document_data-obj_descr l_c_dot
l_wa_document_data-obj_type
INTO l_v_filenam.
ENDIF.
MOVE l_wa_document_data-obj_type TO l_v_filetyp.
READ TABLE l_i_header ASSIGNING <l_fs_header> INDEX 2.
IF sy-subrc IS INITIAL.
SPLIT <l_fs_header>-line AT l_c_equ INTO l_v_var l_v_filetyp.
ENDIF.
CONDENSE l_v_filetyp.
l_wa_documntid = <l_fs_links>-instid_b.
CONCATENATE l_wa_documntid-doctp
l_wa_documntid-docyr
l_wa_documntid-docno INTO l_v_sortfi.
IMPORT objcont_tab TO l_i_content
FROM DATABASE soc3(dt) ID l_v_sortfi.
IF sy-subrc IS INITIAL.
READ TABLE l_i_content ASSIGNING <l_fs_content> INDEX 1.
IF sy-subrc IS INITIAL.
IF <l_fs_content>-line CP 'KPro'
l_v_extct = l_c_k.
ELSE.
CLEAR l_v_extct.
ENDIF.
ENDIF.
ENDIF.
MOVE l_wa_document_data-doc_size TO l_v_doc_siz.
CALL FUNCTION 'SO_OBJECT_DOWNLOAD'
EXPORTING
bin_filesize = l_v_doc_siz
filetype = l_v_filetyp
path_and_file = l_v_filenam
extct = l_v_extct
no_dialog = abap_true
IMPORTING
act_filename = l_v_flename
TABLES
objcont = l_i_content
EXCEPTIONS
file_write_error = 1
invalid_type = 2
x_error = 3
kpro_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
RAISE no_link_found.
ENDIF.
ENDIF.
CLEAR: l_i_content, l_v_extct.
ENDLOOP.
CATCH cx_sy_conversion_no_number
cx_sy_conversion_overflow
cx_sy_move_cast_error
cx_sy_conversion_codepage
cx_sy_import_format_error
cx_sy_import_mismatch_error.
RAISE no_link_found.
ENDTRY.
* Download Archived Files
*We need the SAP to Documentum link, this is available in TOA* tables, and it depends in which table you find the relation. For me its TOA02, it may not be same for you.
*In case you dont find use Function module ARCHIV_CONNECTINFO_GET_META and use the parameters sap_object and object_id as in below select.
*
*I am using table TOA02 to get all Archive ids.
SELECT * FROM toa02 INTO TABLE l_i_toa02 WHERE
sap_object = 'BUS2081' AND
object_id = 5100000062009. (for me its Invoice document)
IF sy-subrc NE 0.
RETURN.
ELSE.
LOOP AT l_i_toa02 ASSIGNING <l_fs_tab>.
l_cnt = l_cnt + 1.
CLEAR: l_v_archived_filename, l_v_length, l_i_tbl1024.
CONCATENATE ' C:\DATA\DOCUMENTUM' '\' '_Arc_' l_cnt '.' <l_fs_tab>-reserve
INTO l_v_archived_filename.
CONDENSE l_v_archived_filename.
CALL FUNCTION 'SCMS_AO_TABLE_GET'
EXPORTING
arc_id = <l_fs_tab>-archiv_id
doc_id = <l_fs_tab>-arc_doc_id
IMPORTING
length = l_v_length
TABLES
data = l_i_tbl1024
EXCEPTIONS
error_http = 1
error_archiv = 2
error_kernel = 3
error_config = 4
OTHERS = 5.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
CALL FUNCTION 'SCMS_DOWNLOAD'
EXPORTING
filename = l_v_archived_filename "'C:\DATA\DOCUMENTUM\....
filesize = l_v_length
mimetype = l_v_mime
TABLES
data = l_i_tbl1024
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
ENDLOOP.
ENDIF.
This complete code will create a folder C:\Data\Documentum in your PC and you will find all downloaded attachments there. Happy Downloading
No comments:
Post a Comment
Note: only a member of this blog may post a comment.