Skip to Content
Author's profile photo shitanshu sahai

Triggering Smart Forms using Web dynpro ABAP Component

Summary

The arcticle will guide to trigger a Smartform using a Web-Dynpro ABAP. The End User will Be able to download The smartform in PDF format and print it whenever required. It is assumed that reader knows about creating SMARTFORMS in SAP.

Creation Of WDA component

Create a WDA component in SE80 Transaction Code As shown Below.

New Bitmap Image.jpg

Creation Of layout in the component

After Creation of the component Go to view and in Layout tab insert a button element as shown below.Name this button “Print”.

New Bitmap Image.jpg

New Bitmap Image.jpg

Code written on the action

After creating the action write the below provided code on the action of this button. It is assumed here that you know creating a smart form; if not so kindly follow the link shared in the related content section.In the code shown below, the smart form I created is named ‘ZTEST_WDA’.

New Bitmap Image.jpg

method ONACTIONA_PRINT .

DATA FM_NAME TYPE RS38L_FNAM.
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING
FORMNAME                 =
‘ZTEST_WDA’
IMPORTING
FM_NAME                  = FM_NAME
.
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: JOB_OUPUT
TYPE SSFCRESCL,
LT_OTFDATA
TYPE TABLE OF ITCOO.

DATA: LA_CTRL_FORM TYPE SSFCTRLOP,
LA_OUTPUT_OPT
TYPE SSFCOMPOP.

** Spool Parameters
LA_OUTPUT_OPT-TDIMMED =
‘X’.
LA_OUTPUT_OPT-TDDELETE =
‘X’.
LA_OUTPUT_OPT-TDLIFETIME =
‘X’.
LA_OUTPUT_OPT-TDDEST =
‘LOCL’.

*    ****************************************************************************
* Parameters passes to get the output in PDF format
****************************************************************************
LA_CTRL_FORM-NO_DIALOG =
‘X’.
LA_CTRL_FORM-PREVIEW =
‘X’.
LA_CTRL_FORM-GETOTF =
‘X’.
LA_CTRL_FORM-LANGU =
‘EN’.
LA_CTRL_FORM-DEVICE =
‘PRINTER’.

CALL FUNCTION FM_NAME
EXPORTING
CONTROL_PARAMETERS         =  LA_CTRL_FORM
OUTPUT_OPTIONS             = LA_OUTPUT_OPT
IMPORTING
JOB_OUTPUT_INFO            = JOB_OUPUT
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.

LT_OTFDATA[] = JOB_OUPUT-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’
MAX_LINEWIDTH         =
255
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.

WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
*    *path to the word file
I_FILENAME =
‘WDA_SMARTFORMS.pdf’
*     String Variable
I_CONTENT =  PDF_DATA
*     File Type
I_MIME_TYPE =
‘PDF’ ).
endmethod.

Testing of Application

Save and activate the component and test the application. The Result is shown in screenshots below.

New Bitmap Image.jpg

New Bitmap Image.jpg

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Are you sure that class WDR_TASK was released to be used in custom development?

      Author's profile photo shitanshu sahai
      shitanshu sahai
      Blog Post Author

      WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(

      *    *path to the word file
      I_FILENAME =
      'WDA_SMARTFORMS.pdf'
      *     String Variable
      I_CONTENT =  PDF_DATA
      *     File Type
      I_MIME_TYPE =
      'PDF' ).

      This will download the smartform into PDF format on screen and the default name of the PDF file is termed as WDA_SMARTFORMS
      Regards,
      Sahai.S