CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Loading PDF document from CRM Web UI or Interaction center(IC) is a common use-case across different services. Here in this document we will go through all the steps involved in creating a PDF display from CRM UI/ IC.

There are two ways in which we can load the PDF:

  •      PDF URL
  •      PDF content using BSP page.

Loading PDF URL

The first option is the simplest, where you have URL for the PDF file and you would like to load it from Web UI. If the URL is static we can use a URL based transaction launcher and load in the UI. There are many articles available in SDN which talks about this topic so I will not elaborate on this. Alternatively, you can also load the URL’s using the get_p_<attr> method of the context node attribute. This approach will be useful in cases where the URL is dynamic. Again I am not going into the details as there are multiple documents published in SDN on this.

Loading PDF content

The second approach, loading the PDF content from web UI / IC is a common scenario in migration project. Let us take an example where the customer legacy system uses a third party archive tool for storing all the historical bills of customers. More often than not after migration, customers would like to retain the third party tool and just have a display view for those bills in CRM. Let us assume in this case the bills are stored in PDF form and the third party can send us the PDF content in the XSTRING format.

Below are the steps to load PDF on click of a hyperlink from the view.

Create a new controller Billdoc.pdf under your BSP component.

Now create a handler class and set it to the controller.

For the above created controller redefine do_request( ) method and set the response data. Let us assume in our case we are going to get PDF content through an RFC and below is the sample code for setting the response.

DATA: ebc_t_raw_data     TYPE  TABLE OF tbl1024,

      xdata              TYPE  xstring.

*Get PDF content

    CALL FUNCTION 'ZGET_PDF_DOCUMENT'
      DESTINATION rfc_dest
     
EXPORTING
        im_opbel             
= lv_opbel
     
TABLES
        t_pdf_data           
= ebc_t_raw_data
        t_return             
= return
     
EXCEPTIONS
        communication_failure
=
        system_failure       
=
        general_fault        
= 3
       
OTHERS                = 4.

*   Build xstring from itab format (dependent on itab type)
   
IF ebc_t_raw_data IS NOT INITIAL.
     
LOOP AT ebc_t_raw_data INTO ebc_line.
       
CONCATENATE xdata ebc_line-line INTO xdata IN BYTE MODE.
     
ENDLOOP.
   
ENDIF.

*   Determine data length
   
size = xstrlen( xdata ).

*   Export response data
   
CALL METHOD response->if_http_entity~append_data
     
EXPORTING
       
data   = xdata
        length
= size.

*   Set response content-type as PDF
   
CALL METHOD response->if_http_entity~set_header_field
     
EXPORTING
        name 
= 'content-type'                              "#EC NOTEXT
       
value = 'application/pdf'.                          "#EC NOTEXT

There are two key things to note in the above code:

  • Set the xstring content to response.
  • Set the header field content-type as PDF.

Also note that we can play around with the content type to load different types of files.

And the last step is to load this BSP page on click of a hyperlink in the UI view.

Redefine get_p method and load the BSP page. Below is the sample code.

      CALL METHOD cl_bsp_runtime=>get_runtime_instance
        RECEIVING
          runtime
= lr_runtime.

*     create url using runtime
     
CALL METHOD lr_runtime->construct_bsp_url
       
EXPORTING
          in_application
= 'ZIUICINVOICE'       "BSP component name
          in_page       
= 'Billdocument.pdf'      "bsp controller created above
          in_parameters 
= lt_params
       
IMPORTING
          out_local_url 
= rv_value.

Thus we are all set to load the PDF, click on the hyperlink and a new browser window containing PDF will be loaded. Below is the sample screen shot.

3 Comments