This document explains how to:
Download Excel from CRM Web UI
- Create a BSP Controller "downloadExcel" for Excel.
- Create a Controller class "ZCL_CRM_DOWNLOAD_EXCEL" with superclass CL_BSP_CONTROLLER2. Redefine the DO_REQUEST method with the below code.
METHOD do_request.
ENDMETHOD.
DATA:
lv_xls TYPE xstring.
lv_len TYPE i.
lv_len TYPE i.
* Get the excel file here. For more details, you can refer the definition of the following method in How to - Add Custom XML Parts to Microsoft Excel using ABAP
get_xls_download(
IMPORTING
ev_xml_xstring_xls = lv_xls
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_xls ).
IMPORTING
ev_xml_xstring_xls = lv_xls
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_xls ).
* Export response data
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_xls
length = lv_len.
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_xls
length = lv_len.
* Set response content-type as Excel
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
"content-type for XLSX
value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
"Content types
"Excel (*.xlsx) - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
"Excel (*.xlsm) - 'application/vnd.ms-excel.sheet.macroenabled.12'
ENDMETHOD.
3. Set the contoller class to the BSP Controller. Now you can use this controller to download the file.
Download Word from CRM Web UI
- Create a BSP Controller "downloadWordDoc" for Word.
- Create a Controller class "ZCL_CRM_DOWNLOAD_WORDDOC" with superclass CL_BSP_CONTROLLER2. Redefine the DO_REQUEST method with the below code.
METHOD do_request.
ENDMETHOD.
DATA:
lv_doc TYPE xstring.
lv_len TYPE i.
lv_len TYPE i.
* Get the word file here. For more details, you can refer the definition of the following method in How to - Add Custom XML Parts to Microsoft Word using ABAP
get_doc_download(
IMPORTING
ev_xml_xstring_doc = lv_doc
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_doc ).
IMPORTING
ev_xml_xstring_doc = lv_doc
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_doc ).
* Export response data
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_doc
length = lv_len.
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_doc
length = lv_len.
* Set response content-type as Word
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
"content-type for DOCX
value = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'.
value = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'.
"Content types
"Word (*.docx) - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document
"Word (*.docm) - 'application/vnd.ms-word.document.macroenabled.12'
ENDMETHOD.
3. Set the contoller class to the BSP Controller. Now you can use this controller to download the file.
Download PowerPoint from CRM Web UI
- Create a BSP Controller "downloadPowerPoint" for PowerPoint.
- Create a Controller class "ZCL_CRM_DOWNLOAD_POWERPOINT" with superclass CL_BSP_CONTROLLER2. Redefine the DO_REQUEST method with the below code.
METHOD do_request.
ENDMETHOD.
DATA:
lv_ppt TYPE xstring.
lv_len TYPE i.
lv_len TYPE i.
* Get the powerpoint file here. For more details, you can refer the definition of the following method in How to - Add Custom XML Parts to Microsoft PowerPoint using ABAP
get_ppt_download(
IMPORTING
ev_xml_xstring_ppt = lv_ppt
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_ppt ).
IMPORTING
ev_xml_xstring_ppt = lv_ppt
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_ppt ).
* Export response data
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_ppt
length = lv_len.
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_ppt
length = lv_len.
* Set response content-type as PowerPoint
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
"content-type for PPTX
value = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'.
value = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'.
"Content types
"PowerPoint (*.pptx) - 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
"PowerPoint (*.pptm) - 'application/vnd.ms-powerpoint.presentation.macroenabled.12'
ENDMETHOD.
3. Set the contoller class to the BSP Controller. Now you can use this controller to download the file.
Generic Approach: Download a file from CRM Web UI
- Create a BSP Controller "downloadFile".
- Create a Controller class "ZCL_CRM_DOWNLOAD_FILE" with superclass CL_BSP_CONTROLLER2. Redefine the DO_REQUEST method with the below code.
METHOD do_request.
ENDMETHOD.
DATA:
lv_ppt TYPE xstring.
lv_len TYPE i.
lv_len TYPE i.
* Get the file here.
get_file_download(
IMPORTING
ev_xml_xstring_file = lv_file
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_file ).
IMPORTING
ev_xml_xstring_file = lv_file
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_file ).
* Export response data
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_file
length = lv_len.
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_file
length = lv_len.
* Set response content-type for the file. Get the content-type using API Class method 'cl_mime_repository_api->get( )' while reading the file from the Mime repository
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
"content-type for file
value = 'set the content-type here read using the above mentioned API method'.
value = 'set the content-type here read using the above mentioned API method'.
ENDMETHOD.
3. Set the contoller class to the BSP Controller. Now you can use this controller to download the file.