Skip to Content
0
Sep 21, 2012 at 09:27 AM

Downloading MS Office 2007 file using Business Document Services (BDS)

526 Views

Hello experts,

In SAP CRM 7.0 EhP1 environment we are using BDS to store some Excel files (for calculatoin tasks) in CRM without any relation to a transaction. Our approach uses the transaction launcher to call a link that links to a URL customized in the service configuration (Tx. SICF). A handler class implementing the interface IF_HTTP_EXTENSION in that service is used to download the file from BDS, when the users triggers a certain event in WebUI. After downloading the file from BDS we set the data of the file and the content type (Excel with macros) in the server response.

METHOD if_http_extension~handle_request.

DATA:

lt_signature TYPE STANDARD TABLE OF bapisignat,

ls_signature LIKE LINE OF lt_signature,

lt_tab_content TYPE sbdst_content,

ls_tab_content LIKE LINE OF lt_tab_content,

lv_excel_content_as_xstring TYPE xstring,

lv_content_type TYPE string,

lv_attachment TYPE string,

lv_not_found_message TYPE string.

FIELD-SYMBOLS:

<ls_excel_content_line> LIKE LINE OF lt_tab_content.

* find the document

CLEAR lt_signature.

CALL METHOD cl_bds_document_set=>get_info

EXPORTING

classname = 'ZMY_CLASSNAME'

classtype = 'OT'

object_key = 'test.xlsm'

CHANGING

signature = lt_signature

EXCEPTIONS

nothing_found = 1

error_kpro = 2

internal_error = 3

parameter_error = 4

not_authorized = 5

not_allowed = 6

OTHERS = 7.

IF sy-subrc <> 0.

RAISE document_read_error.

ENDIF."sy-subrc <> 0.

CLEAR lt_tab_content.

REFRESH lt_signature.

APPEND ls_signature TO lt_signature.

* read the calculation chart from bds

CALL METHOD cl_bds_document_set=>get_with_table

EXPORTING

classname = 'ZMY_CLASSNAME'

classtype = 'OT'

object_key = 'test.xlsm'

CHANGING

content = lt_tab_content

signature = lt_signature

EXCEPTIONS

error_kpro = 1

internal_error = 2

nothing_found = 3

no_content = 4

parameter_error = 5

not_authorized = 6

not_allowed = 7

OTHERS = 8.

IF sy-subrc <> 0.

RAISE document_read_error.

ENDIF.

* create Excelsheet

LOOP AT lt_tab_content ASSIGNING <ls_excel_content_line>.

CONCATENATE lv_excel_content_as_xstring <ls_excel_content_line>-line INTO lv_excel_content_as_xstring IN BYTE MODE.

ENDLOOP.

* Prepare HTML Export

IF lv_excel_content_as_xstring IS NOT INITIAL.

server->response->set_data( data = lv_excel_content_as_xstring ).

lv_content_type = 'application/vnd.ms-excel.sheet.macroEnabled.12;'.

server->response->set_header_field( name = 'Content-Type' value = lv_content_type ).

lv_attachment = 'attachment; filename=test.xlsm'

server->response->set_header_field( name = if_http_header_fields=>content_disposition value = lv_attachment ).

server->response->set_status( code = 200 reason = 'OK' ).

ELSE.

lv_not_found_message = 'File not found.'.

server->response->set_cdata( data = lv_not_found_message ).

server->response->set_status( code = 200 reason = 'OK' ).

ENDIF.

ENDMETHOD.

With XLS files this works fine but when we try to use XLSM files (Excel 2007 file with macros) or also XLSX files it appears as if the file is corrupted during download, because when we open this file, Excel prompts the message that this file must be repaired.

We use the Business Document Navigator (BDN) to upload the XLSM files to CRM. In BDN you also can download a uploaded file and when we download a uploaded XLSM file from BDN and open it, Excel has no problems and doesn't promts the message that this file must be repaired. I think that uploading a XLSM file to BDS and downloading a file from BDS works fine.

Do you have any suggestion what we can do that the file will be downloaded correctly?

Thanks in advance,

Sebastian