Skip to Content

Overview

Using method CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE, it is possible to open a smartform PDF in a Web Dynpro ABAP application without the need for an InteractiveForm UI element.

Scenario

You need to open a smartform PDF when the user clicks a custom print button on a view.

Procedure

1.0 Add a Custom Print Button to the View

On your view, create a button UI element with onAction event, PRINT.

2.0 The PRINT Action Code

In the action handler method for action PRINT, write the following code.

  DATA lv_smartform       TYPE rs38l_fnam.
  DATA ls_ssfctrlop       TYPE ssfctrlop.
  DATA ls_output_options  TYPE ssfcompop.
  DATA ls_job_output_info TYPE ssfcrescl.
  DATA lt_lines           TYPE STANDARD TABLE OF tline.
  DATA lv_bin_filesize    TYPE i.
  DATA lv_pdf_xstring     TYPE xstring.
* -- Get the name of the smartform function module
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname = 'ZMY_SMARTFORM'
    IMPORTING
      fm_name  = lv_smartform.
* -- Call the smartform
  ls_ssfctrlop-no_dialog = abap_true.
  ls_ssfctrlop-getotf    = abap_true.
  ls_output_options-tdprinter = 'PDF1'.
  CALL FUNCTION lv_smartform
    EXPORTING
      control_parameters = ls_ssfctrlop
      output_options     = ls_output_options
      custom_input       = ls_your_custom_smartform_input
    IMPORTING
      job_output_info    = ls_job_output_info
    EXCEPTIONS
      OTHERS             = 0.
* -- Convert the OTF data to xstring
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format       = 'PDF'
    IMPORTING
      bin_filesize = lv_bin_filesize
      bin_file     = lv_pdf_xstring
    TABLES
      otf          = ls_job_output_info-otfdata[]
      lines        = lt_lines
    EXCEPTIONS
      OTHERS       = 0.
  CHECK lv_pdf_xstring IS NOT INITIAL.
* -- Open the PDF
  cl_wd_runtime_services=>attach_file_to_response(
    i_filename       = 'mypdf.pdf'
    i_content        = lv_pdf_xstring
    i_mime_type      = 'application/pdf'
  ).

Result

After saving and activating the Web Dynpro Component and running the application, clicking the new custom print button opens the smartform PDF.

demo_smart.JPG

To report this post you need to login first.

1 Comment

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

  1. Janagar Sundaramoorthy

    Hi Amy king,

    how to use the below code if we want to print it via printer

    1.   cl_wd_runtime_services=>attach_file_to_response( 
    2.     i_filename       = ‘mypdf.pdf’ 
    3.     i_content        = lv_pdf_xstring 
    4.     i_mime_type      = ‘application/pdf’ 

    Any inputs are appreciated.

    Regards

    S.Janagar

    (0) 

Leave a Reply