*&

---------------------------------------------------------------------*
*& Include
ZBDS_TEST1_F01
*
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form Create_BDS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM create_bds_entry .
CLEAR: wa_bds_signature, wa_bds_components, wa_bds_uris, s_doc_url.
CLEAR: i_bds_signature, i_bds_components, i_bds_uris.
IF s_doc_descr IS INITIAL.
s_doc_descr = 'Noname'.
ENDIF.
wa_bds_signature-DOC_VER_NO = v_doc_ver_no.
wa_bds_signature-DOC_VAR_ID = v_doc_var_id.
wa_bds_signature-prop_name = 'BDS_KEYWORD'.
wa_bds_signature-prop_value = 'Key1'.
APPEND wa_bds_signature TO i_bds_signature.
wa_bds_signature-prop_name = 'BDS_KEYWORD'.
wa_bds_signature-prop_value = 'Key2'.
APPEND wa_bds_signature TO i_bds_signature.
wa_bds_signature-prop_name = 'BDS_KEYWORD'.
wa_bds_signature-prop_value = 'Key3'.
APPEND wa_bds_signature TO i_bds_signature.
wa_bds_signature-prop_name = 'BDS_DOCUMENTCLASS'.
wa_bds_signature-prop_value = 'MS Word Application'.
APPEND wa_bds_signature TO i_bds_signature.
wa_bds_signature-prop_name = 'DESCRIPTION'.
wa_bds_signature-prop_value = s_doc_descr.
APPEND wa_bds_signature TO i_bds_signature.
wa_bds_signature-prop_name = 'BDS_DOCUMENTTYPE'.
wa_bds_signature-prop_value = 'BDS_ATTACHMENT'.
* wa_bds_signature-prop_value = 'BDS_TEXT'.
APPEND wa_bds_signature TO i_bds_signature.
wa_bds_components-doc_count = 1.
wa_bds_components-comp_count = 1.
wa_bds_components-mimetype = i_bds_mimetype.
wa_bds_components-comp_id = v_comp_id.
APPEND wa_bds_components TO i_bds_components.
CALL METHOD obj_bds->create_with_url
EXPORTING
classname
= s_bds_classname
classtype
= s_bds_classtype
CHANGING
components
= i_bds_components
object_key
= s_bds_object_key
signature
= i_bds_signature
uris
= i_bds_uris
EXCEPTIONS

IF sy-subrc NE 0 AND sy-subrc NE 5. ENDFORM. CLEAR i_bds_signature. ENDIF. " Create_BDS *&---------------------------------------------------------------------* *& Form Delete_BDS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM delete_bds . * READ TABLE i_bds_signature INTO wa_bds_signature INDEX 1. ENDIF. MESSAGE e018. MESSAGE e016. READ TABLE i_bds_signature INTO wa_bds_signature INDEX 1. CLEAR: wa_bds_signature. MESSAGE e018.error_kpro = 1 internal_error = 2 parameter_error = 3 not_authorized = 4 not_allowed = 5. IF sy-subrc = 6. IF sy-subrc = 1. MESSAGE e017. s_doc_url = wa_bds_uris-uri. APPEND wa_bds_signature TO i_bds_signature. ENDIF. CLEAR i_bds_signature. IF sy-subrc = 5. IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 6. " Delete_BDS *&---------------------------------------------------------------------* *& Form Open_BDS *&---------------------------------------------------------------------* . CLEAR: wa_bds_signature. ENDFORM. MESSAGE e016. CALL METHOD obj_bds->delete EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key x_force_delete = 'X' CHANGING signature = i_bds_signature EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 parameter_error = 4 not_authorized = 5 not_allowed = 6. ENDIF. READ TABLE i_bds_uris INTO wa_bds_uris INDEX 1. ENDIF.

wa_bds_components. oleline(128) TYPE c. * extracting: IF sy-subrc = 0. IF sy-subrc = 1. CALL FUNCTION 'RS_VALUES_BOX' EXPORTING . LOOP AT i_bds_signature INTO wa_bds_signature WHERE prop_name = 'DESCRIPTION'. l_nr LIKE sy-tabix. wa_field_desc TYPE rsvbfidesc. APPEND s_doc_descr TO i_descriptions. DATA: oletype TYPE typeline. i_bds_signature_2. s_doc_descr. ENDIF. DATA: oletypes TYPE TABLE OF typeline. CALL METHOD obj_BDS->get_info EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key CHANGING components = i_bds_components signature = i_bds_signature EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 parameter_error = 4 not_authorized = 5 not_allowed = 6. MESSAGE e017.. s_doc_descr. CLEAR: field_desc. APPEND wa_bds_signature TO i_bds_signature_2. wa_field_desc-display = 'X'. i_bds_uris.* text *----------------------------------------------------------------------* form Get_BDS_Entry . ENDIF. CLEAR: i_bds_signature. wa_field_desc-fieldnum = 1. wa_bds_uris. version(10) TYPE c VALUE ' '. APPEND wa_field_desc TO field_desc. MESSAGE e016. i_bds_components. * selecting DATA: DATA: DATA: the required document: field_desc TYPE TABLE OF rsvbfidesc. IF sy-subrc NE 0 AND sy-subrc NE 1. ENDLOOP. l_nr = 0. i_descriptions. CLEAR: wa_bds_signature. CONCATENATE wa_bds_signature-prop_value ' Version:' wa_bds_signature-doc_ver_no ' Variante:' wa_bds_signature-doc_var_id INTO s_doc_descr SEPARATED BY ' '. *-------------------------------------------------------------CLEAR: wa_bds_signature. END OF typeline. TYPES: BEGIN OF typeline. wa_field_desc.

MESSAGE e018. CALL METHOD obj_BDS->get_info EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key CHANGING components = i_bds_components signature = i_bds_signature EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 parameter_error = 4 not_authorized = 5 . MESSAGE e017. * retrieving the choosen document: CALL METHOD obj_BDS->get_with_url EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key CHANGING uris = i_bds_uris signature = i_bds_signature EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 parameter_error = 4 not_authorized = 5 not_allowed = 6. READ TABLE i_bds_signature_2 INTO wa_bds_signature INDEX l_nr. MESSAGE w010. MESSAGE e016. ENDIF. CLEAR i_bds_signature. IF l_nr = 0. CLEAR i_bds_signature_2. EXIT. APPEND wa_bds_signature TO i_bds_signature. i_bds_components. IF sy-subrc = 1. CLEAR: i_bds_signature. ENDIF. * Get the correct 'doc_component'-Data that correspond to the choosen * 'i_bds_signature': CLEAR i_bds_components. CLEAR wa_bds_signature.left_upper_col left_upper_row pagesize title IMPORTING linenumber TABLES field_desc value_tab EXCEPTIONS OTHERS = = = = 5 5 10 'Select document'(sdo) = l_nr = field_desc = i_descriptions = 1. IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 6. IF sy-subrc = 6. ENDIF. ENDIF. i_bds_signature_2.

WHEN 'application/msword'.ms-excel'. ENDCASE. document_format = soi_docformat_rtf. CALL METHOD c_oi_container_control_creator=>mime_to_ole EXPORTING mimetype = i_bds_mimetype version = version IMPORTING oletypes = oletypes. MESSAGE e016. a * special component had to be selected: READ TABLE i_bds_signature INTO wa_bds_signature INDEX 1. i_bds_mimetype = wa_bds_components-mimetype. s_doc_url = wa_bds_uris-uri. Perform Close_DOI_Document. IF sy-subrc = 1. document_format = soi_docformat_native. CASE i_bds_mimetype. WHEN 'application/x-oleobject'. WHEN 'application/vnd. .visio'. ENDLOOP. WHEN 'application/vnd. " Get_BDS_Entry *&---------------------------------------------------------------------* *& Form Create_DOI_Document *&---------------------------------------------------------------------* * Create a document using the SAP DOI framework *----------------------------------------------------------------------* form Create_DOI_Document . document_format = soi_docformat_compound. document_format = soi_docformat_compound. * Just to put the right description on the dynpro: LOOP AT i_bds_signature INTO wa_bds_signature WHERE prop_name = 'DESCRIPTION'.not_allowed = 6. READ TABLE i_bds_components INTO wa_bds_components INDEX 1. document_format = soi_docformat_compound. s_doc_descr = wa_bds_signature-prop_value. WHEN 'application/x-rtf' OR 'text/rtf'. ENDIF. ENDIF. IF sy-subrc NE 0 AND sy-subrc NE 1. READ TABLE i_bds_uris INTO wa_bds_uris INDEX 1. WHEN 'text/plain'. WHEN OTHERS. * We have only documents that consist of one component! So the * simple case 'INDEX 1' is adequate. MESSAGE e017. endform. document_format = soi_docformat_compound. READ TABLE oletypes INTO document_type INDEX 1. document_format = soi_docformat_text. ENDIF. But in more general terms.

endform. EXIT. CALL METHOD h_proxy->close_document EXPORTING do_save = '' IMPORTING retcode = s_retcode. IF NOT h_proxy IS INITIAL. EXIT. CALL METHOD h_control->set_focus. s_retcode = c_oi_errors=>ret_document_not_open. ENDIF.CALL METHOD h_control->get_document_proxy EXPORTING document_type = document_type document_format = document_format IMPORTING document_proxy = h_proxy retcode = s_retcode. i_bds_signature_2. i_bds_uris. i_bds_components. ENDIF. CALL METHOD obj_bds->get_info "_newest_only "alternativly . * set handler me->on_close_document for proxy. " Create_DOI_Document *&---------------------------------------------------------------------* *& Form Close_DOI_Document *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* form Close_DOI_Document . wa_bds_uris. ELSE. CLEAR: wa_bds_signature. IF s_retcode NE c_oi_errors=>ret_ok. IF s_retcode NE c_oi_errors=>ret_ok. * Force a reinitialization of document interface Clear h_proxy. EXIT. IF s_retcode NE c_oi_errors=>ret_ok. CALL METHOD c_oi_container_control_creator=>ole_to_mime EXPORTING oletype = document_type IMPORTING mimetype = i_bds_mimetype. CALL METHOD h_proxy->release_document IMPORTING retcode = s_retcode. CALL METHOD h_proxy->create_document EXPORTING open_inplace = 'X' IMPORTING retcode = s_retcode. ENDIF. ENDIF. wa_bds_components. endform. * set handler me->on_close_document for proxy activation ' '. CLEAR: i_bds_signature. s_doc_descr. " Close_DOI_Document *&---------------------------------------------------------------------* *& Form GetInfo *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* form GetInfo .

IF s_retcode NE c_oi_errors=>ret_ok. MESSAGE e017. Perform Close_DOI_Document. Set Screen 0. EXIT. " GetInfo *&---------------------------------------------------------------------* *& Form Open_DOI_Document *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* form Open_DOI_Document . ENDIF. endform.EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key CHANGING components = i_bds_components signature = i_bds_signature EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 parameter_error = 4 not_authorized = 5 not_allowed = 6. IF sy-subrc NE 0 AND sy-subrc NE 1. Call Screen '0100'. ENDIF. CALL METHOD h_proxy->open_document EXPORTING document_url = s_doc_url open_inplace = 'X' * open_readonly = 'X' IMPORTING retcode = s_retcode. MESSAGE e016. CALL METHOD h_control->set_focus. CALL METHOD h_control->get_document_proxy EXPORTING document_type = document_type document_format = document_format IMPORTING document_proxy = h_proxy retcode = s_retcode. EXIT. ENDIF. " Open_DOI_Document *&---------------------------------------------------------------------* *& Form Open_Document *&---------------------------------------------------------------------* * Retrieve the BDS stored document and open inside . break-point. ENDIF. endform. IF s_retcode NE c_oi_errors=>ret_ok. IF sy-subrc = 1.

Perform Create_DOI_Document. ENDIF. * Required before the confirm create can take place CALL METHOD h_proxy->save_document_to_url EXPORTING url = s_doc_url IMPORTING . * * * * * * * * * * * CALL METHOD cl_bds_document_set=>call_navigator EXPORTING LOGICAL_SYSTEM = classname = s_bds_classname classtype = s_bds_classtype CLIENT = DISPLAY_SINGLE_DOC = DISPLAY_DOC = CHANGING OBJKEY = SIGNATURE = EXCLUDING = FIXED_ATTRIBUTES = EXCEPTIONS PARAMETER_ERROR = 1 INTERNAL_ERROR = 2 NOTHING_FOUND = 3 ERROR_KPRO = 4 NOT_ALLOWED = 5 NOT_AUTHORIZED = 6 others = 7 . *----------------------------------------------------------------------* form Call_Navigator. IF sy-subrc <> 0. Perform Get_BDS_Entry. Perform Create_BDS_Entry.* of SAP through the DOI interface *----------------------------------------------------------------------* form Open_Document . Perform Open_DOI_Document. " Open_Document *&---------------------------------------------------------------------* *& Form Call_Navigator *&---------------------------------------------------------------------* * Call the Business Document Navigator for our application * specific class. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endform. endform. " Call_Navigator *&---------------------------------------------------------------------* *& Form Create_Document *&---------------------------------------------------------------------* * Create a MS Word document through SAP DOI and store the document * on the SAP BDS application server *----------------------------------------------------------------------* form Create_Document .

retcode = s_retcode. MESSAGE e016. IF sy-subrc = 7. CALL METHOD obj_bds->confirm_create EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key x_force_confirm = 'X' CHANGING signature = i_bds_signature uris = i_bds_uris components = i_bds_components EXCEPTIONS nothing_found = 1 error_kpro = 2 error_dp = 3 internal_error = 4 parameter_error = 5 not_authorized = 6 not_allowed = 7. endform. MESSAGE e018. CALL METHOD obj_bds->update_with_url EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key doc_id = wa_bds_signature-doc_id doc_ver_no = wa_bds_signature-doc_ver_no doc_var_id = wa_bds_signature-doc_var_id x_force_update = 'X' CHANGING components = i_bds_components uris = i_bds_uris signature = i_bds_signature EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 . READ TABLE i_bds_signature INTO wa_bds_signature INDEX 1. IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 7. IF NOT h_proxy IS INITIAL. " Create_Document *&---------------------------------------------------------------------* *& Form Update_Document *&---------------------------------------------------------------------* * Update_BDS_Enrty * Save DOI document * Confirm_BDS_Update *----------------------------------------------------------------------* form Update_Document . CLEAR: i_bds_uris. CLEAR i_bds_signature. wa_bds_signature. MESSAGE e017. IF sy-subrc = 1. CLEAR: wa_bds_uris. ENDIF. ENDIF. ENDIF.

IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 6.parameter_error = 4 not_authorized = 5 not_allowed = 6. IF sy-subrc = 6. ENDIF. CALL METHOD obj_bds->confirm_update EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key x_force_confirm = 'X' CHANGING signature = i_bds_signature uris = i_bds_uris components = i_bds_components EXCEPTIONS nothing_found = 1 error_kpro = 2 error_dp = 3 internal_error = 4 parameter_error = 5 not_authorized = 6 not_allowed = 7. ENDIF. IF sy-subrc = 1. endform. MESSAGE e018. READ TABLE i_bds_uris INTO wa_bds_uris INDEX 1. s_retcode = c_oi_errors=>ret_document_not_open. ENDIF. IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 7. ELSE. IF sy-subrc = 1. * Documentation says Close the document in the office application *(using the method close_document) before calling this method. " Update_Document *&---------------------------------------------------------------------* . MESSAGE e016. CALL METHOD h_proxy->save_document_to_url EXPORTING url = s_doc_url IMPORTING retcode = s_retcode. ENDIF. ENDIF. ENDIF. MESSAGE e018. MESSAGE e016. IF sy-subrc = 7. s_doc_url = wa_bds_uris-uri. MESSAGE e017. ENDIF. MESSAGE e017.

s_doc_url = wa_bds_uris-uri. DATA: new_ver_no TYPE sbdst_doc_ver_no. APPEND wa_bds_signature TO i_bds_signature. ENDIF. CLEAR: wa_bds_signature. MESSAGE e017. IF sy-subrc = 6. READ TABLE i_bds_signature INTO wa_bds_signature INDEX 1. CALL METHOD h_proxy->save_document_to_url EXPORTING url = s_doc_url IMPORTING retcode = s_retcode. CLEAR i_bds_signature. wa_bds_properties. wa_bds_uris. MESSAGE e016. s_doc_url.*& Form Create_Version *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* form Create_Version . IF sy-subrc = 1. CALL METHOD obj_bds->create_version_with_url EXPORTING classname = s_bds_classname classtype = s_bds_classtype object_key = s_bds_object_key doc_id = wa_bds_signature-doc_id doc_ver_no = wa_bds_signature-doc_ver_no doc_var_id = wa_bds_signature-doc_var_id IMPORTING new_doc_ver_no = new_ver_no CHANGING components = i_bds_components uris = i_bds_uris properties = i_bds_properties EXCEPTIONS nothing_found = 1 error_kpro = 2 internal_error = 3 parameter_error = 4 not_authorized = 5 not_allowed = 6. i_bds_uris. ENDIF. CALL METHOD obj_bds->confirm_create EXPORTING classname = s_bds_classname classtype = s_bds_classtype . ENDIF. IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 6. wa_bds_signature-doc_ver_no = new_ver_no. READ TABLE i_bds_uris INTO wa_bds_uris INDEX 1. i_bds_properties. MESSAGE e018.

ENDIF. MESSAGE e016. IF sy-subrc NE 0 AND sy-subrc NE 1 AND sy-subrc NE 7.object_key = s_bds_object_key x_force_confirm = 'X' CHANGING signature = i_bds_signature uris = i_bds_uris components = i_bds_components EXCEPTIONS nothing_found = 1 error_kpro = 2 error_dp = 3 internal_error = 4 parameter_error = 5 not_authorized = 6 not_allowed = 7. MESSAGE e017. ENDIF. IF sy-subrc = 7. IF sy-subrc = 1. MESSAGE e018. " Create_Version . endform. ENDIF.