Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Purpose

To provide Print Preview with SAP Adobe forms of the any Business Transaction (here I have taken Service Contract)

 

 

 

 

 

 

 

 

 

 

Print & Print Preview is supported by SAP only for SAP Smartforms.  It’s  really strange for me why SAP does not have any standard approach for providing Adobe forms on WebUi, some how it works in SAPGUI.

 Adobe forms are more interactive and much intuitive and easy to create, modify, update forms.  It has slighe edge over smart forms. May be SAP will come up in future to support adobe forms in CRM webui. But as of CRM 7.0 EHP1 this is not available.

I did put up my own efforts to crack through this requirement and finally came up with impressive solution which is quiet easy to implement.

The actual SAP Smart form required Actions to be defined and implemented, where as in my approach of adobe forms action definitions are NOT required.

 

 Here we go…..

Steps in nutshell:

  1. Enhance the underlying Event Handler method of the Print Preview Button, UI Component BT112H_SC (service contract)
  2. Create a BSP ICF Service, similar to the standard print service CRM_PDF_PRINT, call it as ZCRM_PDF_PRINT
  3. In the even handler method (Step 1), construct the URL based on the Service defined in Step 2 and call the popup.
  4. Set up a Handler class for the service defined in Step 2, call it as ZCL_CRM_PREVIEW_PDF (Prototype CL_CRM_PREVIEW_PDF)
  5. In its handler method, call the method which is responsible to bring the pdf output in Xstring format.
  6. Set the pdf content to the response of the service with the application as ‘pdf’.

Let’s discuss the above steps in more detail fashion…..

1. Enhance Print Preview Button Event Handler method.

Enhance the UI Component BT112H_SC (Service Contract Header) in component Work Bench. Please choose your own component header according to the transaction type.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 View & Event handler class are shown above.

2. Construct URL and Trigger POPUP window

Make use of method create_url in the class cl_crm_web_utility to construct URL

   concatenate 'scenario=P&guid=' lv_adminh_guid into lv_query.
* get URL
  lv_url = cl_crm_web_utility=>create_url(
            iv_path            = '/sap/crm/zcrm_pdf_print'
            iv_query           = lv_query
            iv_in_same_session = 'X' ).

 URL will have to set up in the ICF service, this we will see in further steps.  

 Create a popup with the help of window controller and make use of standard URL POPUP Interface View.

   lr_popup =  me->comp_controller->window_manager->create_popup(
          iv_interface_view_name = 'GSURLPOPUP/MainWindow'
          iv_usage_name          = 'CUGSURLPopup'
          iv_title               = lv_title ).

 Set the URL paramaters like Header_guid which will be retrived in the service handler class later.

lr_cn = lr_popup->get_context_node( 'PARAMS' ).

 Set up Popup configuration Settings like

  ls_params-url = lv_url.
  ls_params-height = '800'.
  ls_params-width = '800'.
  lr_obj->set_properties( ls_params ).
  lr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_plain ).
  lr_popup->set_window_width( 820 ).
  lr_popup->set_window_height( 800 ).
  lr_popup->open( ).

 3. Define ICF Service for PDF PRINT PREVIEW.

 Now, it is required to define a custom  BSP ICF (Internet Communication Framework) Service.

 Tx: SICF 

Copy the standard ICF service for CRM_PDF_PRINT to the ZCRM_PDF_PRINT.

 

 

 Define a Handler class to it like ZCL_CRM_PREVIEW_PDF, make of template method in standard class CL_CRM_PREVIEW_PDF

 

 

 4. Populate the PDF data to the URL

 Now, we need to bring up the PDF data to populate as PDF Xstring and applicantion type as ‘pdf’, which will eventually open as PDF file in the popup.

 Method               IF_HTTP_EXTENSION~HANDLE_REQUEST

 Get the URL Params using the below method.

     ls_header_guid = server->request->get_form_field( 'guid' ).

 Now, the header_guid is available. Using the header_guid, we need to call a custom built method to bring the PDF Xstring data. I will show how to achieve this in next step.

      call method me->get_output_data
        exporting
          i_header_guid = ls_header_guid
        importing
          fpcontent     = lv_pdf_xstring.

 Get the length of the PDF String.
      call function 'SCMS_XSTRING_TO_BINARY'
        exporting
          buffer        = lv_pdf_xstring
        importing
          output_length = lv_pdf_length
        tables
          binary_tab    = l_bin.

Define the application as PDF.

        lv_file_size = lv_pdf_length.
        lv_contenttype = 'application/pdf'.
        ls_guid_str = ls_header_guid.
        concatenate ls_guid_str '.pdf' into lv_filename.
        lv_file_name = lv_filename.

        server->response->append_data(
                            data   = lv_pdf_xstring
                            length = lv_pdf_length ).

 Set the response parameters

  concatenate 'inline; filename=' lv_filename
    into lv_contentdisposition.

  call method server->response->set_header_field
    exporting
      name  = 'content-disposition'
      value = lv_contentdisposition.

  call method server->response->set_header_field
    exporting
      name  = 'content-type'
      value = lv_contenttype.

  call method server->response->set_header_field
    exporting
      name  = 'content-filename'
      value = lv_filename.

  server->response->delete_header_field(
           name = 'Cache-Control' ).                        "#EC NOTEXT

  server->response->delete_header_field(
           name = 'Expires' ).  

 5. Method: GET_OUTPUT_DATA to fetch the PDF DATA

 With Header guid, read all the Service contract information and pass on the same to the Adobe PDF Forms.

Get the Output parameters, most importantly, getpdf = X,

    fp_outputparams-nodialog      = 'X'.
    fp_outputparams-getpdf      = 'X'.
    fp_outputparams-preview      = 'X'.

    call function 'FP_JOB_OPEN'
      changing
        ie_outputparams = fp_outputparams
      exceptions
        cancel          = 1
        usage_error     = 2
        system_error    = 3
        internal_error  = 4
        others          = 5.

 Get the form related FM

          call function 'FP_FUNCTION_MODULE_NAME'
            exporting
              i_name     = lv_formname
            importing
              e_funcname = fm_name.

Call the FM and export the form related data. This is usual way of calling Adobe forms. Output will not go to spool, rather it gives in XString format.  

 call function fm_name
        exporting
          /1bcdwb/docparams  = fp_docparams

        importing
          /1bcdwb/formoutput = fp_result.

 

Import the PDF XSTING DATA

fp_1 = fp_result-pdf.

IF it is required to attach more PDF forms to the same output file, then,

 

 Call multiple forms in desired order of sequence and attach the same using the following class:

   p_dest = cl_fp=>get_ads_connection( ).
* Get FP reference.
  l_fp = cl_fp=>get_reference( ).

*     Create PDF Object.
              l_pdfobj = l_fp->create_pdf_object( connection = p_dest ).

*     Set document.
              l_pdfobj->set_document( pdfdata = fp_out ).

 *     Set attachment.
              concatenate 'Attachment' sy-uzeit into l_attachment-name
                  separated by space.
            concatenate 'Cover_letter' 'pdf' into l_attachment-filename
                separated by '.'.
              l_attachment-mimetype    = 'application/pdf'.
              l_attachment-description = l_attachment-name.
              l_attachment-data        = fp_2.
              insert l_attachment into table l_attachments.
              l_pdfobj->set_attachments( attachments = l_attachments ).

*     Execute, call ADS.
              l_pdfobj->execute( ).

*     Get result.
              l_pdfobj->get_document( importing pdfdata = fp_out ).

 Finally, export the PDF data in Xstring to the Handler method defined above.

11 Comments