Currently Being Moderated

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

Comments

Actions

Filter Blog

By author:
By date:
By tag: