Skip to Content
Author's profile photo Rajwin Singh Sood

Custom Download To Excel Application In SAP CRM WEBUI


Applies to:

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

Company: Atos

Created on: 8th Dec 2015





Author Bio


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”.

Coding Logic

Firstly BSP component  BT115QS_SLSQ/SlsQuotSR  is enhanced. then redefine the method DO_PREPARE_OUTPUT and add the below code to add the button:-

METHOD do_prepare_output.

  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.


  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:-

METHOD eh_onopen_excel.

* Added by wizard: Handler for event ‘OPEN_EXCEL’

  DATA lv_string_xls.

  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’

              INTO lv_string_xls

              SEPARATED BY


*****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.



      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 ).



      ev_guid_32 = guid.

  “create the url

  CONCATENATE runtime->application_url ‘/’ guid ‘.xls’

  INTO gv_url.

  “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

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.

  CLEAR controller->gv_url.


<script type=”text/javascript”> “<%= lv_url%>”,”<%= sy-uzeit%>” );





Application testing

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 :-


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo vamshi naik
      vamshi naik

      Hi Rajwin,

      very nice post, I have a problem in displaying the window. I have done same code with the new URL created in the event of the button  & .html page but the window doesn't open in my case. I have executed all the steps as above. Please help me if i am missing anything. I have written exactly same code in .html page, it gets executed and nothing comes up.

      Author's profile photo Rajwin Singh Sood
      Rajwin Singh Sood
      Blog Post Author

      As discussed on Linkedin the issue is resolved for you.

      Author's profile photo vamshi naik
      vamshi naik

      Hi Rajwin,

      I am able to download the file now with all my required data. but the file value is coming with (GUID).xls.  Is their any way we can change the name of the file and is there any option to download as CSV file.

      I have tried giving filename in the URL part of the code then it gives dump. Please let me know your input to finish my task.