Skip to Content

Calling a smartform from the Webdynpro application.

  1. Summary…………………………………………………………………………………………2
  2. Introduction to Webdynpro………………………………………………………………. .2
  3. 2.1.        Main Web Dynpro Component parts. ………………………………………….2
  4. 2.2.        Three types of controller…………………………………………………………. .2
  5. 2.3.        Web Dynpro Application…………………………………………………………… 2
  6. Steps to create the Webdynpro component  and call the Smartform…………. 3
  7. 3.1.        Create View context in Webdynpro component. ……………………………..3
  8. 3.2.        Create View elements in Webdynpro component…………………………… 4
  9. 3.3.        View Methods in Webdynpro component. ……………………………………..6
  10. Create Smartform ZTEST_WD.. …………………………………………………………….9
  11. Create Webdynpo Application……………………………………………………………. 10
  12. Test the Webdynpro Application ZWD_PRINT_SMARTFORM………………….. 11


1. SummaryThis document explains how to print the Smartform as PDF output from a Webdynpro ABAP application.
2. Introduction to WebdynproWebdynpro ABAP is a revolutionary step in the development of web-based user interfaces. Webdynpro applications are built using declarative programming techniques based on the Model View Controller (MVC) design paradigm.


2.1. Main Web Dynpro Component parts

  • Windows
  • Views
    • UI elements
    • Layout
    • Controller
    • Context                                                          
  • Component Controllers
    • Context

2.2. Three types of controllerThere are 3 types of controller as explained below:

  • Custom / Component controller  :

     o Each Webdynpro component has at least one global controller – the component controller (default)    

     o Custom controllers are a kind of additional global controllers to capsulate sub function from the component controller – typically to structure bigger components _                They do not have a visual interface

  • View controller

     o Each view has exactly one view controller, which processes the actions performed by the user in the view

  • Window controller

     o Each window has exactly one window controller. It behaves like a view controller (plugs) and is usable from other controllers (like a custom /                                    component controller)


2.3. Web Dynpro Application

  • An application is an entry point into a Webdynpro component

3.     Steps to create the Webdynpro component  and call the Smartform

Go to SE80 and create and new Webdynpro ABAP component ZWD_PRINT_SMARTFORM

/wp-content/uploads/2014/01/1_368398.png

Provide the description as below

/wp-content/uploads/2014/01/2_368480.png

3.1. Create View context in Webdynpro component

In the MAIN view, go to context tab and create attribute as below

/wp-content/uploads/2014/01/3_368481.png

Enter the attribute details as below

/wp-content/uploads/2014/01/4_368482.png

3.2. Create View elements in Webdynpro component

Go to layout tab of MAIN view and insert 2 elements

/wp-content/uploads/2014/01/5_368483.png

3.2.1. Text editor :  to write the text for the pdf

Create a text editor

/wp-content/uploads/2014/01/6_368484.png

Do the binding by pressing the binding button in the text editor attribute as follows

/wp-content/uploads/2014/01/7_368485.png

In the popup select the context attribute ‘TEXT’

/wp-content/uploads/2014/01/8_368486.png

3.2.2. User action Button : to call the smartform within the webdynpro

Create a button as follows

/wp-content/uploads/2014/01/9_368487.png

Enter the Button attributes as below. Create event ‘PRINT’ by pressing the create button:

/wp-content/uploads/2014/01/10_368488.png

3.3. View Methods in Webdynpro component

Go to Actions tab of ‘MAIN’ view and write the code as follows:

/wp-content/uploads/2014/01/11_368489.png

The below code has to be written in the method ‘PRINT’

METHOD onactionprint .

DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_text TYPE wd_this->element_contexttext.

*   get element via lead selection
lo_el_context = wd_context->get_element( ).
*   @TODO handle not set lead selection
IF lo_el_context IS INITIAL.
ENDIF.

*   get single attribute
lo_el_context->get_attribute(
EXPORTING
name `TEXT`
IMPORTING
value = lv_text ).

DATA: fname                 TYPE rs38l_fnam,
pdf_tab               TYPE TABLE OF tline,
lv_bin_filesize       TYPE i,
lv_pdf_xstring        TYPE xstring,
lv_control_parameters TYPE ssfctrlop,
l_x                   TYPE c VALUE ‘X’,
lv_output_options     TYPE ssfcompop,
tab_otf_data          TYPE ssfcrescl,
lt_otfdata            TYPE TABLE OF itcoo.

CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING
formname           = ‘ZTEST_WD’
*     VARIANT            = ‘ ‘
*     DIRECT_CALL        = ‘ ‘
IMPORTING
fm_name            = fname
EXCEPTIONS
no_form            = 1
no_function_module = 2
OTHERS             = 3.
IF sysubrc <> 0.
* Implement suitable error handling here
ENDIF.

lv_control_parametersgetotf    = l_x. “OTF output
lv_control_parametersno_dialog = space. “No print dialog
lv_control_parameterspreview   = l_x. “SPACE. “No preview
lv_output_optionstdprinter     = ‘ZPDF1’.

CALL FUNCTION fname
EXPORTING
control_parameters = lv_control_parameters
output_options     = lv_output_options
user_settings      = ‘X’
gv_text            = lv_text
IMPORTING
job_output_info    = tab_otf_data.

lt_otfdata[] = tab_otf_dataotfdata[].

CALL FUNCTION ‘CONVERT_OTF’
EXPORTING
format                = ‘PDF’
max_linewidth         = 132
IMPORTING
bin_filesize          = lv_bin_filesize
bin_file              = lv_pdf_xstring
TABLES
otf                   = lt_otfdata
lines                 = pdf_tab
EXCEPTIONS
err_max_linewidth     = 1
err_format            = 2
err_conv_not_possible = 3
err_bad_otf           = 4
OTHERS                = 5.

CHECK lv_pdf_xstring IS NOT INITIAL.
* — Open the PDF
cl_wd_runtime_services=>attach_file_to_response(

  i_filename       = ‘Test_print.pdf’
i_content        = lv_pdf_xstring
i_mime_type      = ‘application/pdf’ ).

ENDMETHOD.

4.     Create Smartform ZTEST_WD

Create a importing parameter GV_TEXT in the form interface. This will be populated from the Webdynpro text editor value

/wp-content/uploads/2014/01/12_368490.png

Output the GV_TEXT in the main window as shown below./wp-content/uploads/2014/01/13_368491.png

5. Create Webdynpo Application

Go to SE80 webdynpro component ZWD_PRINT_SMARTFORM and create an webdynpro application as follows :

/wp-content/uploads/2014/01/14_368492.png

Save and Activate

/wp-content/uploads/2014/01/15_368493.png

6. Test the Webdynpro Application ZWD_PRINT_SMARTFORM

Press the execute button

/wp-content/uploads/2014/01/16_368494.png

Enter the desired text to come on the Smartform PDF output, and press button ‘Print form’

/wp-content/uploads/2014/01/17_368495.png

After pressing the ‘Print form’ button, the PDF file will appear as below:

/wp-content/uploads/2014/01/18_368496.png

The text entered in the Webdynpro  text editor field is on the PDF output file

/wp-content/uploads/2014/01/19_368497.png

To report this post you need to login first.

2 Comments

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

Leave a Reply