Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
amy_king
Active Contributor

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.

1 Comment
Labels in this area