0% found this document useful (0 votes)
732 views11 pages

WD4A - Smartforms

This document explains step by step how to display a smartform as a PDF document in Web Dynpro for ABAP. It explains how to create the Web Dynpro application and the code for displaying smartform as PDF document.

Uploaded by

sciucci
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
732 views11 pages

WD4A - Smartforms

This document explains step by step how to display a smartform as a PDF document in Web Dynpro for ABAP. It explains how to create the Web Dynpro application and the code for displaying smartform as PDF document.

Uploaded by

sciucci
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

How to Display a Smartform as PDF document in Web Dynpro for ABAP

How to Display a Smartform as PDF document in Web Dynpro


for ABAP

Applies to:
SAP NetWeaver 2004s.

Summary
This document explains step by step how to display a smartform as a PDF document in Web Dynpro for
ABAP. It explains how to create the Web Dynpro application and the code for displaying smartform as PDF
document.
Author(s): Nanda Kondagunta
Company: Consultantgurus Inc.
Created on: 1st February 2007

Author Bio
Nanda Kondagunta is an independent SAP consultant and President of Consultantgurus Inc. an SAP
Solution Provider.He has over 12 years of SAP consulting experience in Design, Development and support
of SAP applications. Photo should be in 65 pixels in width and 85 pixels in height.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 1
How to Display a Smartform as PDF document in Web Dynpro for ABAP

Table of Contents
Create Web Dynpro Application ...................................................................................................... 3
Convert OTF to PDF .................................................................................................................... 6
Create Application and Test ..................................................................................................... 7
Related Content............................................................................................................................. 10
Disclaimer and Liability Notice....................................................................................................... 11

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 2
How to Display a Smartform as PDF document in Web Dynpro for ABAP

Create Web Dynpro Application


This document describes how to show a smartform as PDF in WDA. Familiarity with creating web dynpro
applications is assumed. Also It is assumed that the smartform has already been created . This document
only deals with how to display smartform as PDF in WDA.
1) Create a Web Dynpro component Z_WD_TEST_FORM

2) Go to component controller context and create a context node PDF with cardinality 1..1 and properties
as shown.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 3
How to Display a Smartform as PDF document in Web Dynpro for ABAP

3) Create attribute SOURCE of Type XSTRING as shown.

4) Create View PDFVIEW

Go to the view Layout and create Interactive Form element. This is available in the ADOBE elements.
As shown.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 4
How to Display a Smartform as PDF document in Web Dynpro for ABAP

Change the height and width in the properties of the Interactive form to 1000px.
5) Go to the context of PDFVIEW and drag and drop the controller context PDF to the View context and
map it.

Click yes on the message The PDFVIEW Context should look like this:

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 5
How to Display a Smartform as PDF document in Web Dynpro for ABAP

5) Go to the layout and select the Source attribute from the context node PDF for the PDF source property.

Convert OTF to PDF


6) Go to the component controller and create a method DISPLAYPDF. This method will contain the code to
display the PDF. The code consists of
i) Call smartform function and pass data to it.
ii) Pass the output of the smartform function call to function module CONVERT_OTF to convert it to
PDF data.
iii) Set the attribute SOURCE data to PDF_DATA.

7) Go to the method WDDOINIT of the PDFVIEW and call the just created component controller method
DISPLAYPDF. As shown:
method WDDOINIT .
wd_Comp_Controller->Displaypdf(
).

endmethod.
8) Select the window Z_WD_TEST_FORM and drag and drop the view PDFVIEW on to it on the left side
as shown.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 6
How to Display a Smartform as PDF document in Web Dynpro for ABAP

Create Application and Test


9) Activate the component. Create the application and test it. The PDF will be displayed in WD.

Following is the code in the DISPLAYPDF method:


method displaypdf .
data : l_x(1) value 'X'.
data: lv_text type char3,
lv_syucomm type char1,
ls_pdf type xstring,
lv_fm_name type rs38l_fnam,
lv_control_parameters type ssfctrlop,
lv_output_options type ssfcompop,
lv_ssf_output type ssfcrescl,
lt_otfdata type table of itcoo.
data:
node_input1 type ref to if_wd_context_node,
elem_input1 type ref to
if_wd_context_element,
stru_input1 type
ig_componentcontroller=>element_zinput.

* navigate from <CONTEXT> to <INPUT1> via lead selection


node_input1 = wd_context->get_child_node( name
ig_componentcontroller=>wdctx_zinput ).

* get element via lead selection


elem_input1 = node_input1->get_element( ).

* get all declared attributes

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 7
How to Display a Smartform as PDF document in Web Dynpro for ABAP

elem_input1->get_static_attributes(
importing
static_attributes = stru_input1 ).

call function 'SSF_FUNCTION_MODULE_NAME'


exporting
formname = 'ZFFG_TRAVEL_COVERSHEET'
importing
fm_name = lv_fm_name
exceptions
no_form = 1
no_function_module = 2
others = 3
.
if sy-subrc <> 0.
* Error MESSAGE
endif.

* Set relevant control parameters


lv_control_parameters-getotf = l_x. "OTF output
lv_control_parameters-no_dialog = l_x. "No print dialog
lv_control_parameters-preview = space. "No preview

* Set relevant output options


lv_output_options-tdnewid = l_x. "Print parameters,
lv_output_options-tddelete = space. "Print parameters,

call function lv_fm_name


exporting
* ARCHIVE_INDEX * ARCHIVE_INDEX_TAB *
ARCHIVE_PARAMETERS control_parameters =
lv_control_parameters
* MAIL_APPL_OBJ * MAIL_RECIPIENT *
MAIL_SENDER
output_options = lv_output_options
user_settings = space
pernr = stru_input1-zpernr
reinr = stru_input1-zreinr
pdvrs = stru_input1-zpdvrs
importing
* DOCUMENT_OUTPUT_INFO job_output_info =
lv_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.
endif.
refresh lt_otfdata.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 8
How to Display a Smartform as PDF document in Web Dynpro for ABAP

lt_otfdata[] = lv_ssf_output-otfdata[].

call function 'SSFCOMP_PDF_PREVIEW'


exporting
i_otf = lt_otfdata
exceptions
convert_otf_to_pdf_error = 1
cntl_error = 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.
endif.

data: l_dummy type standard table of tline,


pdf_data type xstring,
pdf_size type i.

clear: pdf_data, pdf_size.

* convert otf to pdf


call function 'CONVERT_OTF'
exporting
format = 'PDF'
importing
bin_filesize = pdf_size
bin_file = 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.
endif.

data:
node_pdf type ref to if_wd_context_node,
elem_pdf type ref to
if_wd_context_element,
stru_pdf type
if_componentcontroller=>element_pdf ,
item_source like stru_pdf-source.
* navigate from <CONTEXT> to <PDF> via lead selection
node_pdf = wd_context->get_child_node( name if_componentcontroller=>wdctx_pdf
).

* get element via lead selection


elem_pdf = node_pdf->get_element( ).

* set single attribute

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 9
How to Display a Smartform as PDF document in Web Dynpro for ABAP

elem_pdf->set_attribute(
exporting
name = `SOURCE`
value = pdf_data ).

endmethod.

Related Content
Please include at least three references to SDN documents or web pages.
• Webdynpro for ABAP : Tutorials for Beginners
• Web Dynpro for ABAP : Getting Started
• Web Dynpro for ABAP Help Portal

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 10
How to Display a Smartform as PDF document in Web Dynpro for ABAP

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or
seek to hold, SAP responsible or liable with respect to the content of this document.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2006 SAP AG 11

You might also like