Customer Relationship Management Blogs by Members
Find insights on SAP CRM and other customer relationship management products and topics in blog posts from community members and share your own perspective.
cancel
Showing results for 
Search instead for 
Did you mean: 





Applies to:



SAP CRM 7.0, EHP1, EHP2 and EHP3




Summary


 


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.


 


 


 



Author(s):


 

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 .






Scenario


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


    EXPORTING


      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.


  ENDIF.






ENDMETHOD.






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


              cl_abap_char_utilities=>horizontal_tab.




*****generate the URL for excelsheet for be opened in .htm page




  CREATE OBJECT lr_response TYPE cl_http_response


    EXPORTING


      add_c_msg = 1.








  lv_output = lv_string_xls.






  "Convert the string into xstring.




  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'


    EXPORTING


      text     = lv_output


      mimetype = 'APPLICATION/MSEXCEL'


    IMPORTING


      buffer   = lv_buffer.




  "Find the length of the xls file.




  lv_xls_len = xstrlen( lv_buffer ).




  " Set parameter




  lr_response->set_data(


    data   = lv_buffer


    length = lv_xls_len      ).




  lr_response->set_header_field(


  name  = if_http_header_fields=>content_type


  value = if_ai_attachment=>c_mimetype_excel ).




  lr_response->set_header_field(


  name  = 'expires'


  value = '180' ).




  lr_response->set_status(


    code = 200


    reason = 'OK' ).




  lr_response->server_cache_expire_rel(


    expires_rel = 180 ).


  CALL FUNCTION 'GUID_CREATE'


    IMPORTING


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




ENDMETHOD.





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.


  CLEAR controller->gv_url.


%>


<script type="text/javascript">


window.open( "<%= lv_url%>","<%= sy-uzeit%>" );


</script>


<%


  ENDIF.


%>







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





3 Comments