SAP CRM 7.0, EHP1, EHP2 and EHP3
There are umpteen ways of incorporating downloading the contents in SAP CRM WEBUI framework like using transformation to convert content from ABAP to XLS and then later using the converted content from transformation to be displayed on WEBUI framework using output stream. Although this approach is appropriate in case where we need output in excel sheet in particular format like specific font, background color, calculation fields and so on. But in some cases we may need simple download functionality which will be covered here. The scenario/requirement which I had encountered was simple download of data in the form of internal table populated from third party system using Remote function(RFC) enabled function module. I may not be able to showcase the complete scenario but will showcasing the approach to simply download the string content to excel. This particular step by step approach could be used to download any other application like PDF, MS Word and the mime type(MIME table SDOKMIME and SDOKMIME_C) supported in the system.
Rajwin Singh Sood
Created on: 8th Dec 2015
Rajwin Singh Sood is currently working as Team lead/Solution
Architect at Atos. He has got experience of about 10 years in SAP ABAP and SAP CRM web UI. He is also a
SAP CRM EHP2 Certified associated consultant. Prior to working with Atos he had worked with SAP India(SAP
Global Delivery), Capgemini , Accenture and Infosys. He worked in SAP CRM Web Ui in areas like BSP
enhancements, transaction launchers, BOL Programming, BRFPlus .
Button “Excel Download” will be added at the search result list view on click of that excel sheet will be opened with the text “Excel generation” and “this is automated generated excel sheet”.
Firstly BSP component BT115QS_SLSQ/SlsQuotSR is enhanced. then redefine the method DO_PREPARE_OUTPUT and add the below code to add the button:-
CALL METHOD super->do_prepare_output
iv_first_time = iv_first_time.
CONSTANTS lc_button_click TYPE string VALUE ‘OPEN_EXCEL’.
DATA: ls_button TYPE crmt_thtmlb_button.
READ TABLE gt_button TRANSPORTING NO FIELDS WITH KEY text = ‘Excel Download’. “#EC NOTEXT
IF sy-subrc IS NOT INITIAL.
ls_button-type = cl_thtmlb_util=>gc_icon_object_report.
ls_button-text = ‘Excel Download’. “#EC NOTEXT
ls_button-on_click = lc_button_click.
ls_button-enabled = abap_true.
APPEND ls_button TO gt_button.
Secondly add the event with name “OPEN_EXCEL” and the method EH_ONOPEN_EXCEL is created with below code added:-
* Added by wizard: Handler for event ‘OPEN_EXCEL’
DATA: guid TYPE guid_32.
DATA: lv_output TYPE string,
lr_response TYPE REF TO if_http_response,
lv_xls_len TYPE i,
lv_url TYPE string,
lv_buffer TYPE xstring.
CONCATENATE ‘Excel generation’
‘this is automated generated excel sheet’
*****generate the URL for excelsheet for be opened in .htm page
CREATE OBJECT lr_response TYPE cl_http_response
add_c_msg = 1.
lv_output = lv_string_xls.
“Convert the string into xstring.
CALL FUNCTION ‘SCMS_STRING_TO_XSTRING’
text = lv_output
mimetype = ‘APPLICATION/MSEXCEL’
buffer = lv_buffer.
“Find the length of the xls file.
lv_xls_len = xstrlen( lv_buffer ).
” Set parameter
data = lv_buffer
length = lv_xls_len ).
name = if_http_header_fields=>content_type
value = if_ai_attachment=>c_mimetype_excel ).
name = ‘expires’
value = ‘180’ ).
code = 200
reason = ‘OK’ ).
expires_rel = 180 ).
CALL FUNCTION ‘GUID_CREATE’
ev_guid_32 = guid.
“create the url
CONCATENATE runtime->application_url ‘/’ guid ‘.xls’
“upload the content into application server cache
cl_http_server=>server_cache_upload( url = gv_url
response = lr_response ).
Where gv_url is global variable created in the Implementation Class ZL_BT115QS__SLSQUOTSR_IMPL of type string to be used for opening the new window using java script code window.open.
and finally the code in .HTM page to open the excel application as give below:-
DATA lv_url TYPE string.
IF controller->gv_url IS NOT INITIAL.
lv_url = controller->gv_url.
window.open( “<%= lv_url%>”,”<%= sy-uzeit%>” );
Now open the WEBUI and go to the search page of quotation as per below screenshots:-
Once the Excel download button is clicked the new window opens with the POP UP asking to save the file:-
and the excel sheet is opened :-