Skip to Content

This blog documents the solution to use the base64binarydata/xstring fetched using RFC or webservice to show a PDF version of document, i.e. Invoices, in a new popup window on user action.

For example, when the user click on the field Document No. as shown in the screenshot below, we want the respective PDF to be shown in a pop up.

assign_block.PNG

The essence of the development will be to feed the HTTP framework with the xtring data and application type using an object of HTTP response class and creating a popup using standard component GSURLPOPUP and passing it the URL of the view contoller from where the pop up will be triggered.

Step1: Add component GSURLPOPUP in the component usage of the component you are working on i.e. component containing the view from where you need to open PDF. You need to go to the Runtime repository editor and create a Z usage ID adding GSURLPOPUP/MainWindow as the interface view. (Refer to the screenshot below)

RRE.PNG

Step2: For making the PDF open on clicking on field of a record of a table in a assignment block, enhance the GET_P method for the field making the field type as event_link and calling the event handler which we will creating in next step when its clicked. Sample code follows :

   method GET_P_DOCNUMBER.

     CASE iv_property.
       WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
         rv_value = cl_bsp_dlc_view_descriptor=>field_type_event_link.
      WHEN if_bsp_wd_model_setter_getter=>fp_onclick.
         rv_value = ‘OPENPDF’.
    ENDCASE.

   endmethod.

Step3: Create an event handler method EH_ONOPENPDF, the same name as used in GET_P method,where we will convert base64binary data to xstring, set it to HTTP, create popup and load it with view controller’s URL.

Get the document number user has clicked on using the method GET_EVENT_INFO exporting the HTMLB_EVENT_EX which is the default parameter of your event and importing the index of user selection. This index will help us to find the current entity being accessed among the collection (i.e. the row being selected among all the table records)

   cl_thtmlb_util=>get_event_info(

    EXPORTING iv_event = htmlb_event_ex

    IMPORTING ev_index = lv_index ).

   lr_entity ?= me->………->collection_wrapper->find( iv_index = lv_index ).

Use the document number in this entity to fetch the related base64binary data or xtsring.

Since, we will be using xstring to load PDF, so if your data is not xtsring, get the Base64binary number from your source using WS/RFC as per your design and convert it into xtsring using the FM SSFC_BASE64_DECODE.

Set the xstring fetched above to the HTTP response class object, and also set the content type to PDF to make the application type clear to your web Browser.

  CREATE OBJECT cached_response TYPE cl_http_response
    EXPORTING
      add_c_msg = 1.

  cached_response->set_data( data = xstring
  length = pdf_len  ).     “pdf_len is the length of xstring

  cached_response->set_header_field( name = if_http_header_fields=>content_type
  value = ‘APPLICATION/PDF’ ).

  cached_response->set_status( code = 200 reason = ‘OK’ ).

To create a popup, declare object of type if_bsp_wd_popup and use it to create popup using the CREAT_POPUP method.

  gr_ggl_popup =  me->comp_controller->window_manager->create_popup(
                                                    iv_interface_view_name = ‘GSURLPOPUP/MainWindow’
                                                    iv_usage_name          = ‘ZCUGSURLPOPUP’
                                                    iv_title               = ”RELATED PDF’ ).

  lr_context_node = gr_ggl_popup->get_context_node( ‘PARAMS’ ).

  lr_obj = lr_context_node->collection_wrapper->get_current( ).

Fill the URL, height width parameters of the popup.

CALL FUNCTION ‘GUID_CREATE’

  IMPORTING

  ev_guid_32 = lv_guid.

  CONCATENATE runtime->application_url ‘/’ lv_guid ‘.PDF’ INTO popup_url.

  lw_url_params-url = popup_url.

  lw_url_params-height = ‘700’.                            

  lr_obj->set_properties( lw_url_params ).

Call the OPEN method to show related PDF in new popup on clicking on document number

  gr_ggl_popup->open( ).

Step4: Execute and see the PDF opening in a popup window.

PDF.png

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Filipe .

    Hi Latif,

    Thanks for sharing!

    I went through the steps in this blog which help me a lot on my purpose but i came across an error.

    when the popup is called it throws the following exception:

    BSP Exception: Das Objekt 00155D018C251ED3A0BFA022E4722387.PDF in der URL /sap

    (bD1QVCZjPTEwMCZpPTEmZT1RMDlOVUZSQlgwMU9WRjlmTVY5Zk1UTTVBQlZkQVl3bEh0T2d2NTQxclRmamh3JTNkJTNk)/bc/bsp/sap/crm_ist nicht gültig.

    I think this error occurs because there´s no default.htm page under the BSP application GSURLPOPUP.

    Is there any additional steps done to the component usage GSURLPOPUP so the proper flow logic page will be called with success? Have you face this situation in your example?

    Thanks in advance.

    Regards,

    Filipe

    (0) 
  2. Daniel Mac

    Hi,

    I use the code and appears “Error occurs in Smart Form” in popup.

    Any suggestion of what might be happening?

    Best regards,

    Daniel

    (0) 
  3. Vivek Myadam

    Hi Latif,

    Thanks for the info. This was useful but we encountered BSP error while implementing your logic just like Filipe. I used below statement after “cached_response->set_status( code = 200 reason = ‘OK’ )” to get through BSP error. Hope this would be useful to others if they get BSP error.

        cached_response->server_cache_expire_rel( expires_rel = 300 ).

    Regards

    Vivek

    (0) 

Leave a Reply