---
title: "Webdynpro ABAP 系列: How to display smartform in WDA"
author: "王三"
date: "2011-03-20T17:59:06Z"
tags: []
categories: ["编程语言"]
slug: "webdynpro-abap-how-to-display-smartform-in-wda"
draft: false
lastmod: "2011-03-20T17:59:06Z"
id: 968609
url: "https://sapjava.iteye.com/blog/968609"
---

1&gt; Create smart form in Tcode: SMARTFORMS

YTEST\_SF\_001

[![clip_image002](http://s5.sinaimg.cn/middle/7057e52449ee705591974&amp;690 "clip_image002")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee705591974&bid=7057e5240100q4v3&uid=1884808484)

Preview:

[![clip_image004](http://s10.sinaimg.cn/middle/7057e52449ee7059941a9&amp;690 "clip_image004")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee7059941a9&bid=7057e5240100q4v3&uid=1884808484)

2&gt; Create WDA Component

[![clip_image006](http://s11.sinaimg.cn/middle/7057e52449ee705ccff4a&amp;690 "clip_image006")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee705ccff4a&bid=7057e5240100q4v3&uid=1884808484)

3&gt; Assign UI elements to V\_MAIN view:

Download file button and Interactive Form for displaying pdf

[![clip_image008](http://s4.sinaimg.cn/bmiddle/7057e52449ee7062b6c63&amp;690 "clip_image008")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee7062b6c63&bid=7057e5240100q4v3&uid=1884808484)

4&gt; Design view context

[![clip_image010](http://s10.sinaimg.cn/middle/7057e52449ee70651c139&amp;690 "clip_image010")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee70651c139&bid=7057e5240100q4v3&uid=1884808484)

Set supply function for Node N\_PDF.

[![clip_image012](http://s8.sinaimg.cn/middle/7057e52449ee7069cb3c7&amp;690 "clip_image012")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee7069cb3c7&bid=7057e5240100q4v3&uid=1884808484)

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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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-&gt;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-&gt;bind\_structure(  
    new\_item             = ls\_n\_pdf  
    set\_initial\_elements = abap\_true ).  
endmethod.

5&gt; Design button action to DOWNLOAD FILE.

[![clip_image014](http://s14.sinaimg.cn/middle/7057e52449ee706e943fd&amp;690 "clip_image014")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee706e943fd&bid=7057e5240100q4v3&uid=1884808484)

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-&gt;element\_n\_pdf,  
          lv\_content  type wd\_this-&gt;element\_n\_pdf-content.  
*   navigate from &lt;CONTEXT&gt; to &lt;N\_PDF&gt; via lead selection  
    lo\_nd\_n\_pdf = wd\_context-&gt;get\_child\_node( name = wd\_this-&gt;wdctx\_n\_pdf ).  
*   get element via lead selection  
    lo\_el\_n\_pdf = lo\_nd\_n\_pdf-&gt;get\_element( ).  
*   @TODO handle not set lead selection  
if lo\_el\_n\_pdf is initial.  
return.  
endif.  
*   get single attribute  
    lo\_el\_n\_pdf-&gt;get\_attribute(  
exporting  
        name =  \`CONTENT\`  
importing  
value = lv\_content ).  
call method cl\_wd\_runtime\_services=&gt;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&gt; Test Application

[![clip_image016](http://s15.sinaimg.cn/middle/7057e52449ee6fd33249e&amp;690 "clip_image016")](http://photo.blog.sina.com.cn/list/blogpic.php?pid=7057e52449ee6fd33249e&bid=7057e5240100q4v3&uid=1884808484)