Webdynpro ABAP 系列: How to display smartform in WDA

1> Create smart form in Tcode: SMARTFORMS

YTEST_SF_001

clip_image002

Preview:

clip_image004

2> Create WDA Component

clip_image006

3> Assign UI elements to V_MAIN view:

Download file button and Interactive Form for displaying pdf

clip_image008

4> Design view context

clip_image010

Set supply function for Node N_PDF.

clip_image012

Db click SUPPLY_PDF

method supply_pdf .
data: l_x         type char01 value 'X',
        l_message   type string,
        l_form_name type tdsfname value 'YTEST_SF_001',
        l_fm_name   type rs38l_fnam.
data: ls_control_parameters type ssfctrlop,
        ls_output_options     type ssfcompop,
        ls_ssf_output         type ssfcrescl.
data: lt_otfdata            type table of itcoo.
* 1. get smartform
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
      formname           = l_form_name
importing
      fm_name            = l_fm_name
exceptions
      no_form            = 1
      no_function_module = 2
others             = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into l_message.
return.
endif.
* Set relevant control parameters
  ls_control_parameters-getotf    = l_x.    "OTF output
  ls_control_parameters-no_dialog = l_x.    "No print dialog
  ls_control_parameters-preview   = space.  "No preview
* Set relevant output options
  ls_output_options-tdnewid       = l_x.     "Print parameters,
  ls_output_options-tddelete      = space.   "Print parameters,
  ls_output_options-tddest        = 'LP01'.
"!!!Check your print device to ensure support UNICODE.

call function l_fm_name
exporting
*     ARCHIVE_INDEX
*     ARCHIVE_INDEX_TAB
*     RCHIVE_PARAMETERS
      control_parameters         =  ls_control_parameters
*     MAIL_APPL_OBJ
*     MAIL_RECIPIENT
*     MAIL_SENDER
      output_options             = ls_output_options
      user_settings              = space
*      pernr                      = stru_input1-zpernr
*      reinr                      = stru_input1-zreinr
*      pdvrs                      = stru_input1-zpdvrs
importing
*     DOCUMENT_OUTPUT_INFO
    job_output_info            =  ls_ssf_output
*     JOB_OUTPUT_OPTIONS
exceptions
     formatting_error           = 1
     internal_error             = 2
     send_error                 = 3
     user_canceled              = 4
others                     = 5
            .
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into l_message.
return.
endif.
refresh lt_otfdata.
  lt_otfdata[] = ls_ssf_output-otfdata[].
*2. Convert to PDF
data: l_dummy    type standard table of tline,
        l_pdf_data type xstring,
        l_pdf_size type i.
clear: l_pdf_data, l_pdf_size.
* convert otf to pdf
call function 'CONVERT_OTF'
exporting
format                = 'PDF'
importing
      bin_filesize          = l_pdf_size
      bin_file              = l_pdf_data
tables
      otf                   = lt_otfdata[]
lines                 = l_dummy
exceptions
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
others                = 4.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into l_message.
return.
endif.
*  3. Bind pdf conent to node
** data declaration
data: ls_n_pdf type wd_this->element_n_pdf,
       elem_pdf    TYPE REF TO  if_wd_context_element.
  ls_n_pdf-file_name = l_form_name.   " sample only !
  ls_n_pdf-content   = l_pdf_data.   " sample only !
*** bind a single element
  node->bind_structure(
    new_item             = ls_n_pdf
    set_initial_elements = abap_true ).
endmethod.

5> Design button action to DOWNLOAD FILE.

clip_image014

Action source:

data: lo_nd_n_pdf type ref to if_wd_context_node,
          lo_el_n_pdf type ref to if_wd_context_element.
data: ls_n_pdf    type wd_this->element_n_pdf,
          lv_content  type wd_this->element_n_pdf-content.
*   navigate from <CONTEXT> to <N_PDF> via lead selection
    lo_nd_n_pdf = wd_context->get_child_node( name = wd_this->wdctx_n_pdf ).
*   get element via lead selection
    lo_el_n_pdf = lo_nd_n_pdf->get_element( ).
*   @TODO handle not set lead selection
if lo_el_n_pdf is initial.
return.
endif.
*   get single attribute
    lo_el_n_pdf->get_attribute(
exporting
        name =  `CONTENT`
importing
value = lv_content ).
call method cl_wd_runtime_services=>attach_file_to_response
exporting
      i_filename      = 'YTEST001_FORM'
      i_content       = lv_content
      i_mime_type     = 'PDF'
*      i_in_new_window = ABAP_FALSE
*      i_inplace       = ABAP_FALSE
      .

6> Test Application

clip_image016

你可能感兴趣的:(UI)