0% found this document useful (0 votes)
1K views

Getting Started With Smart Forms

The document provides instructions on how to build a simple smart form application in multiple steps: 1. Create a new smart form, add a main page and window, and insert text to print simple text. 2. Additional features covered include adding an address, graphics, passing parameters from a driver program, using global definitions and program lines to calculate values, working with secondary windows, and using copies windows. 3. Each section walks through the necessary transactions and steps to incorporate the given functionality into a smart form.

Uploaded by

mandalprabir
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Getting Started With Smart Forms

The document provides instructions on how to build a simple smart form application in multiple steps: 1. Create a new smart form, add a main page and window, and insert text to print simple text. 2. Additional features covered include adding an address, graphics, passing parameters from a driver program, using global definitions and program lines to calculate values, working with secondary windows, and using copies windows. 3. Each section walks through the necessary transactions and steps to incorporate the given functionality into a smart form.

Uploaded by

mandalprabir
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 77

Getting started with Smart Forms (Building a simple application)

Go to transaction “Smartforms”.

 
Enter a name for the form and click on Create.  
Enter a short description for the form. 

 
In this example, we will print a simple text using our form. To create a text, expand “Pages and
Windows”  New Page. Select Main Window and Right click on that. Select Create  Text

 
Give a name to the text and short description. 
Also enter the text you want to see on the form. 
 
SAVE and Activate the Smart form. 
To know the function module that is generated upon activation of this smart form, click on
Environment  Function module name. 

 
Following popup with the function module would appear. 

 
Test the smart form by clicking on Test. You would be navigated to the function builder with the
function module defaulting to the one that is generated earlier. 

 
Click on execute. 
 
Since we do not have any parameters to pass on, click on Execute. 
Printing Address using Smart Forms

Go to transaction “Smartforms”.

 
Enter a name for the form and click on Create.  
Enter a short description for the form.

 
Expand “Pages and Windows” and click on “%PAGE1”. Rename the page to your needs and add a
short description to the same.

 
To display the address on the form, right click on “Main Window”, select Create  Address

 
Following screen appears. 

 
Enter a name to the Address and add a short description for the same. 
You all might be aware that Addresses are stored in the table ADRC. Now pick an address number
from that table, add provide the same in the “Address Number” as shown below:

Save and Activate the form. 


Now execute the Smart form. The output would be similar as shown below:  
Calling Smart Form using Driver Program

Let us prepare a driver program for the Smart Form that displays the address. This is a
simple demo and doesn’t contain any parameter passing in this example.  
Check the function module that is generated when the Smart Form is activated by clicking on
Environment  Function Module Name. 

 
A pop up would appear displaying the function module name. 

 
We would use this function module in our driver program to call this function module.
Let us create a driver program with a simple call to the above generated function module:
REPORT Zcall_smartform.
* To call a smart form, we would need to call the function module that
* is generated.
CALL FUNCTION '/1BCDWB/SF00000359'
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Execute the program for the output.
Displaying Graphics using Smart Forms

Go to transaction SE78 (Administration of Form Graphics). 

 
Double-click on “GRAPHICS” node and click on “Import (F5)” to import the image. 

 
Select the file name by using the F4 functionality available. Name your graphic and enter a short
description. If you have color image, select the radio button “Color Bitmap image”.  Click on tick mark
to proceed. 
 
The graphic is imported and is stored in “Business Document Server”. 
You can test this by selecting print preview:

 
Now go to transaction SMARTFORM. 
Create a new form and give a short description for the same.

 
To display an image, right click on Main Window  Create  Graphic
 

 
Use F4 help to fill the fields.

 
Save and activate the workflow. 
Test run the smart form, to check the appearance of the graphic.
Passing data to the Smart Forms

Scenario: Let us take a simple scenario of passing Material Number and Material description from
Driver program to the Smart Form. 
Go to transaction SMARTFORMS and create a Smart Form. 
To pass the values from the driver program to Smart Form, we need to define the form interface with
the parameters to be passed on. 
Click on Global Settings  Form Interface. 

 
Now define the import parameters for MATNR and MAKTX (From table MAKT) 

 
Now create a Text in the Main window to display the above two parameters.

 
To add a field, we need to click on “Insert Field”. 

 
Enter the field names between the ‘&’ (Ampersand) as shown below:

 
Similarly create for Description. 

 
Save and Activate the Smart Form. Test run the Smart Form by clicking on Execute.
 
Enter the values as shown below and click on execute. 

Working with Global Definitions and Program Lines

Scenario: To calculate the total seats available using the values “Maximum seats available” and the
“Occupied seats”. In this case, we would be defining Maximum Seats and Occupied Seats in the form
interface and Seats Available in the Global definitions. We would write some code to calculate Seats
available and then print the same.  
Procedure: Create a new smart form and, in the Form Interface, define the following two fields:

 
Now click on “Global definitions” :

 
Now define a variable, SEATS_AVAIL

 
Now to calculate Seats Available, select Global Defination  Initialization

Now mention the input parameters as SEATS_MAX and SEATS_OCC and the output parameter as
SEATS_AVAIL. Write the code to calculate SEATS_AVAIL. 

 
Now to print these values on the layout, create a text by selecting Main Window  Create  Text: 
 
Save and do the syntax check. Activate the Smart Form. 
Test the smart form by clicking on F8. Enter some values for max_seats and avail_seats 

 
Execute the function module. 

 
Working with Secondary Window

Create a Smart Form using the transaction SMARTFORMS. 


To create a Secondary Window, 
Right click on Page  Create  Window (as shown below) 

 
A secondary window is created. 

 
To position the secondary window to meet our needs, click on Form Painter.

 
Following screen appears: 

 
The highlighted window in the above screenshot is the secondary window. 
Move the secondary window (and even stretch) according to your needs. 
 
To close the above page design, click on Form Painter again. 
Now let us write some content in these areas. 
Now select the Page à Secondary Window 
Right click on Secondary Window à C

reate à Text  
 
Write some text inside. 

 
Similarly, create some text in the Main window as well. 
 
Save and activate the Smart Form. Test run the Smart Form; you would get the following output: 

Demo on Copies Window (Real time scenario)

Scenario: To print three copies of a particular document and the first copy should mention
as Customer copy, second one as Bank copy and the third one say College copy. 
Create a Smart Form using the transaction SMARTFORMS. 
In this demo, we would print in the Copies window whether it is bank copy, company copy or others. 
Create a secondary window as shown below:

 
Select Window type as “Copies Window” as shown below: 
 
Also name your window and give it a proper description. Do not change any other settings. 

 
Adjust the window size using the Form Painter available on the application toolbar.

 
The variable SFSY-COPYCOUNT would provide us count of the copy whether it is a first copy,
second copy and others. We would use this field to print the owner of the copy. 
We would define a string, which would hold the name of the copy (bank copy and others) depending
on the value of SFSY-COPYCOUNT. Define a variable in the global definition as shown below:
 
Now select your Copies window, right click – Select Create  Flow Logic  Program Lines 

 
Enter the following code:

Do not forget to enter the variable TEXT in the output parameters. 


Now create a text by selecting the Copies window, right click Create  Text.
In this, just enter the field name as shown below by selecting insert field.  
 
Now include a text in the Main window as well with some content.

 
Save and activate. Test your Smart Form.
In the print preview screen, enter the number of copies as 3 

 
Check the output:

 
Working with Smart Styles

Scenario: In this demo, we would create a small text as shown below with outline numbering as
shown below

 
Go to transaction “SmartStyles”

 
Enter a style name and click on Create. 
Following screen appears:

 
To create a paragraph, click on folder “Paragraph Formats” and click on Create (as shown in the
above screenshot). 
Following pop-up appears: Enter a paragraph format name.
 
Enter a suitable description for your graph and enter the left margin value as 2 CH.

 
Now select the tab “Numbering and Outline”:
Enter the Top Outline Paragraph as the current paragraph name and select “1,2,3..” from the list for
the Numbering Type. 

 
Now create another paragraph format P2 as per the above method. 
In the tab “Numbering and Outline” of P2, do the following:
Select the “Top Outline Paragraph” as “P1” and put the left delimiter as “.”. If the left delimiter is not
mentioned, the values would be displayed as “11, 12, 13...” instead of “1.1, 1.2, 1.3…”
 
Also, in the same window, check the “Number Chaining” Box. If this is selected, the parent value
would be displayed (like 1.1, 1.2, 2.1,2.2..). If this is not checked, only numbering would appear like 1,
2,3 without the parent number prefixing. 
Save and activate your Smart Style. 
Now go to transaction “SmartForms”. 
Create a Smart Form and create a text in the Main Window: 

 
Select the tab “Output Options” to mention the Smart Style to be used.

Now go to tab “General Attributes”. 


Select the icon “Txt Editor” (Though the text could be written directly on this screen, we are avoiding
this method for easy understanding to the consultants who are used with SAP Script editor)

 
Now to change the editor, Click on “Goto” -> Change Editor

 
Here enter the desired text:

 
Return to the main screen of the Text. The screen would appear as follows:

 
Save and activate the Smart Form. Test run the Smart Form. Following would be the output:
Smart Forms - Working with Loop

Step1: Provide the name of the smart form is YDEMO_LOOP on the initial screen of the smart form
and meaningful description. 
Step2: Now go to Global definitions where we can define the Global data, Types, Initialization and etc.
Define Structure using Types Parameter as shown below. In Types parameters we usually define user
defined data types. 

 
Step3:  Now define the internal table and work area in Global Data parameter. 

 
Step4: In Initialization parameter, we can write a code as shown below. We have to mention the
output result in the output parameter so that we can use it further. Here in this case we are outputting
IT_TAB and we are going to use this IT_TAB further in the LOOP in the Flow Logic. 

 
Step5: Create a LOOP statement as shown below. 
 
Step6: Now Loop the internal table. 

 
Step7: To create the character, paragraph formats and Tabs, we use the smart style. The transaction
for create smart style is SMARTSTYLE or we can be created the initial screen of SMARTFORMS.
Here SMART STYLE is created to define Tab positions for the columns. 

 
Step8: Create a node for PARAGRAPH FORMAT as shown below. 

 
The following screen appears. 

 
Step9: Now define the Tabs as shown below. 
 
Step10: Now Import SMART STYLE in to the SMART FORM as shown below. 

 
Step11: Now create a text element for the loop statement. 

 
Step12: Save and activate the smart form. The output is as shown below. 
Designing Tables in Smart Forms
Step1: T-code for smart forms is “SMARTFORMS”. Provide the name of the smart form.

 
And provide the short text for this smart form “YDEMO_TABLE”. 
Step2: Now go to Global definitions where we can define the Global data, Types, Initialization and etc.
Define Structure using Types Parameter as shown below. In Types parameters we usually define user
defined data types. 

 
Step3:  Now define the internal table and work area in Global Data parameter. 

 
Step4: In Initialization parameter, we can write a code as shown below. We have to mention the
output result in the output parameter so that we can use it further. Here in this case we are outputting
IT_TAB and we are going to use this IT_TAB further in the Table painter. 
 
Step5:  Now we create a Table painter as shown below. 

 
Step6: Now we define number of table columns in %LTYPE1. Here, %LTYPE1 is renamed as LINE
as shown below. 
 
Here, in this scenario we have to divide the LINE area into 4 columns as we have to display 5
columns. To draw a line we have to select Draw lines and columns button as shown above. 
Step7: Now we have to create Table line for Header and Main area of Table painter as shown below. 

 
Here we have to provide line type. Here, the line type is LINE. 
Step8: Provide the text for all columns. 

 
Step9: Repeat the same process to the Main Area too. 
Step10: Now Loop the internal table data as shown below. 

 
Step11: Save and activate the smart form. Execute the smart form now. The output is as shown
below.

Using Text Modules in Smart Forms

Step1: Go to transaction smart forms. 

 
Step 2: Click on create. The following screen appears: 

 
Step 3: Enter the required text and save.
Now this text can be included in our smart form.
Go back to smart forms initial screen, and create a smart form.
 
Step 4: In the Main window create a text box.

 
Step 5:In the text box general attributes TAB select Text module from the drop down list

 
Step 6: Give the name of the Text Module created and click on COPY button.

 
Step 7: The text in the text Module will be copied into the Text Editor.

 
Step 9: Save and activate. Execute and check the print preview.

Using MS Word as Editor in SAP Script and Smart Forms

This document details the procedure in using Microsoft Word as editor in SAP Script / Smart Forms. 
In normal case, when you try opening the editor in Smart Forms, the following editor would appear:

 
Click on the editor button. The following editor appears: 

 
Now to change the above editor to MS Word, do the following: 
Go to transaction I18N  (Internationalization). 
Click on I18N Menu  I18N Customizing  I18N System Configuration (as shown in the screenshot
below) 

 
The following screen appears:

 
If you would like to use MS Word Editor in both Script and Smartforms, then check the both
checkboxes as shown below:

 
Click on Activate. 
The following popup appears (related to SAPScript Editor):

 
Click on Yes. Now the following popup appears (related to Smartforms Editor):

 
Click on Yes to proceed. 
Now the MS Word editor is available for both SAP Script and Smartforms. 
Result: In the SmartForms: 

 
In SAP Script:

 
You can anytime revert to old editor by deactivation MS Word editor option using the transaction I18N.
Achieving control-break statements functionality in Smart Forms

Step1: T-code for smart forms is “SMARTFORMS”. Provide the name of the smart form. 

Step2: we can define user-defined structure in TYPES tab in the Global Definitions.  

Step3: Define the field string, internal table and global variables in Global Data tab. 

 
Step4: In the Initialization tab,  

 
Step5: In main window, create the loop as shown below. 
 
Step6: Now Loop the internal table.  

 
Create text element in this loop as show below. 

 
Step7: Execute the smart form, the output would be

Step8: suppose, if we want to know the item details sales document wise. To achieve this, we have to
write the events in the loop as shown below.
 
And in the event on sort begin, 

 
In the text element, 

 
Step9: Now execute the smart form, the output would be 

 
Step10: Now the requirement is to sum the net price of all items of sales document. To achieve this,
 
And in the program lines, we have to add the net price. 

 
In the event on sort end, 

 
In program lines, 

 
Step11: Now execute the smart form, the output would be 
Assigning a transport request for the translations related to the text in Smart Forms

Scenario: To assign a transport request for the translations related to the text in Smart Forms. 
Procedure: For our demo purpose, let us create a Smart Form with a simple text as shown below: 

 
Now let us maintain a translation for the above text in French. To do the same, go to translation
SE63. 
Click on Translation -> ABAP Objects -> Other Long Texts 

 
Select Smart Forms from the list, as shown below:
 
In the following screen, enter the name of the Smart Form created earlier. Also provide the source
language and Target Language to be maintained: 

 
Enter the translation for the text in French.

 
Now to assign a transport request for the above transaction, execute the program
RS_LXE_RECORD_TORDER. 
Enter the target language, Short Description for the transport request, object type as SSF.

 
Click on Execute.

 
As shown in the above screen shot, a transport request is created for the required translations. To
check the same, go to transaction SE09 and provide the transport request number: 
Converting SMART FORMS output to PDF format

REPORT zsuresh_test.

* Variable declarations
DATA:
w_form_name TYPE tdsfname VALUE 'ZSURESH_TEST',
w_fmodule TYPE rs38l_fnam,
w_cparam TYPE ssfctrlop,
w_outoptions TYPE ssfcompop,
W_bin_filesize TYPE i, " Binary File Size
w_FILE_NAME type string,
w_File_path type string,
w_FULL_PATH type string.

* Internal tables declaration

* Internal table to hold the OTF data 


DATA:
t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

* Internal table to hold OTF data recd from the SMARTFORM


t_otf_from_fm TYPE ssfcrescl,

* Internal table to hold the data from the FM CONVERT_OTF


T_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

* This function module call is used to retrieve the name of the Function
* module generated when the SMARTFORM is activated

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'


EXPORTING
formname = w_form_name
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = w_fmodule
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.
ENDIF.

* Calling the SMARTFORM using the function module retrieved above


* GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
* format of the output

w_cparam-no_dialog = 'X'.
w_cparam-preview = space. " Suppressing the dialog box
                                                    " for print preview
w_cparam-getotf = 'X'.
* Printer name to be used is provided in the export parameter
* OUTPUT_OPTIONS
w_outoptions-tddest = 'LP01'.

CALL FUNCTION w_fmodule


EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = w_cparam
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = w_outoptions
* USER_SETTINGS = 'X'
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = t_otf_from_fm
* 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.

t_otf[] = t_otf_from_fm-otfdata[].

* Function Module CONVERT_OTF is used to convert the OTF format to PDF

CALL FUNCTION 'CONVERT_OTF'


EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
* PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = W_bin_filesize
* BIN_FILE =
TABLES
otf = T_OTF
lines = T_pdf_tab
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 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.

* To display File SAVE dialog window


CALL METHOD cl_gui_frontend_services=>file_save_dialog
* EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
* DEFAULT_FILE_NAME =
* FILE_FILTER =
* INITIAL_DIRECTORY =
* WITH_ENCODING =
* PROMPT_ON_OVERWRITE = 'X'
CHANGING
filename = w_FILE_NAME
path = w_FILE_PATH
fullpath = w_FULL_PATH
* USER_ACTION =
* FILE_ENCODING =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 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.

* Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
* presentation server

CALL FUNCTION 'GUI_DOWNLOAD'


EXPORTING
BIN_FILESIZE = W_bin_filesize
filename = w_FULL_PATH
FILETYPE = 'BIN'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = T_pdf_tab
* FIELDNAMES =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Passing Select-Options to Smart Forms

Step1: Create a Structure ZSELECTION in SE11 with following fields. 

 
This structure is similar to the selection-option internal table. 
Step2: In smart form ‘ZSELECT_FORM’, create an entry in to TABLES in the Form Interface. 

 
Step3: Define Structures in TYPES tabs in GLOBAL DEFINITIONS.

 
Step4: In Global Data, 

 
Step5: In program line, write the following code. 
 
Step6: The PERNRS given in the select-option in the driver program is captured in T_SELECT. In
program lines, T_SELECT is input to SELECT query and the results are captured in internal table
T_0002. We have to mention resulted internal table T_0002 in output parameters for further use. 

Step7:  Now, loop the internal table T_0002 as shown below. 

 
Step8: Create driver program ‘ZSELECT_FORM_REP’. Write the following code in report.
 

Displaying a Smart form as PDF in Enterprise portal using WebDynpro for Java

I have seen many questions on how a smart form should be displayed in portal. To answer
this question a person should have both Portal and ABAP knowledge. By giving this basic
information I want to make sure that displaying a smart form as PDF is a simple task. 
Let me start from R/3 side 
Create a smart form. Here I have created a simple smart form which displays “Welcome to
SAP Smart forms”. 

 
Now create a function module with the following export parameter:

 
Place the following code in the function module 
data :
  lv_fnam type RS38L_FNAM,
  gs_control                 TYPE ssfctrlop,
  gs_output_options   TYPE ssfcompop,
  gs_otfdata  TYPE itcoo,
  gs_job_output_info  TYPE ssfcrescl,
   gt_otfdata    TYPE STANDARD TABLE  OF itcoo  INITIAL SIZE 0. 
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname                 = 'YNAG_TEST_PDF'
IMPORTING
   FM_NAME                  = lv_fnam
 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.
ENDIF. 
CLEAR gs_job_output_info.
CLEAR gs_job_output_info-otfdata.
MOVE :
  'X' TO gs_control-no_dialog,
  'X' TO gs_control-getotf,
  'LOCL'(047) TO GS_OUTPUT_OPTIONS-TDDEST. 
CALL FUNCTION lv_fnam
 EXPORTING
   CONTROL_PARAMETERS         = gs_control
   OUTPUT_OPTIONS             = gs_output_options
   USER_SETTINGS              = space
 IMPORTING
   JOB_OUTPUT_INFO            = gs_job_output_info
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. 
*Populate OTF data table
LOOP AT gs_job_output_info-otfdata INTO gs_otfdata.
  APPEND gs_otfdata TO gt_otfdata.
  CLEAR gs_otfdata.
ENDLOOP.                           " LOOP AT t_outtab-otfdata
DATA: lv_bytes TYPE p,
      lv_bin_file type xstring,
      gt_pdfdata       TYPE STANDARD TABLE
                                  OF tline
                             INITIAL SIZE 0. 
*   Convert OTF into PDF
    CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format                = 'PDF'
        max_linewidth         = 255
      IMPORTING
        bin_filesize          = lv_bytes
        BIN_FILE              = bin_file
      TABLES
        otf                   = gt_otfdata
        lines                 = gt_pdfdata
      EXCEPTIONS
        err_max_linewidth     = 1
        err_format            = 2
        err_conv_not_possible = 3
        OTHERS                = 4. 
Make sure that the function module is marked remote enabled. 
 
With this we are done on the R/3 side.
In NWDS (Net Weaver Developer Studio) create an Adaptive RFC model which
points to the FM created in R/3. 

 
Give model name 
 

 
 
Now create an application to display the PDF

 
Insert a frame inside the view 

 
Internal is a value node and url is value attribute of type string. 
Place the following code in Init method 
  public void wdDoInit()
 {
    //@@begin wdDoInit()    
    Ynag_Test_Pdf_1_Input input = new Ynag_Test_Pdf_Input();
    wdContext.nodeYnag_Test_Pdf_Input().bind(input);      
    try {                       
            wdContext.currentYnag_Test_Pdf_InputElement().modelObject().execute();
            } catch (WDDynamicRFCExecuteException e) {
                        e.printStackTrace();
                        wdContext.currentContextElement().setSdfgdsfsd(e.getMessage());
            }           
wdContext.currentInternalElement().setUrl(convertXStringToUrl(wdContext.currentOutputElement().g
etBin_File()));          
    //@@end
  } 
  //@@begin others
  public String convertXStringToUrl(byte[] doc_content){
            String url = "";
            WDWebResourceType webResType = WDWebResourceType.PDF;
            IWDWebResource webResource = WDWebResource.getWebResource(doc_content,
webResType);
            try {
                        url = webResource.getURL();
            } catch (WDURLException e) {
                        e.printStackTrace();
            }          
            return url;
 }
  //@@end 

 
If you are using single sign on make sure to enable User authentication in the application parameters.
User details are required for this as it is using Single sign on to connect to R/3. 
In this case we have hard coded the Smart form to be used.
If you want it in dynamic way FM interfaces need to be changed accordingly.
Label printing using Smart forms

It is believed that SAP has not provided any functionary to create labels in Smart form and this is
considered as one of its disadvantage. In this document we will learn how to create labels using
Smart form. 
To understand this document you should have fair idea about how Smart form works. Also this
document will not explain the programming part required to fetch the data which is used to create
labels.  
Below is the kind of output we expect form this label printing form.  

Step1:-
Suppose we have all the data used to create labels available in our Smart form in table IT_FINAL
which is exported thorough driver program to Smart form.
Now our requirement is to print the labels in the manner shown below.
Label1   Label2  
Label3   Label4  
Label5   Label6    
i.e. odd labels on left side and even on right. Your requirement might vary from this one and you need
to do the changes in layout and logic accordingly.  
To implement this requirement cerate 5 secondary window and a main window all of the size of label
box, in 1st page of Smart form as shown below.  
Last window which print the last label on the page should be the main window, so that the next page
will be triggered if more labels needs to be printed.  

Step2:-
In the Global Data Initialization section of the smart form  
Every row in the table IT_FINAL represents 1 label.
As per the current requirement every 6th row will cerate last label on the page and any further row if
exist will trigger the next page.  
Move every 6th row from IT_FINAL to IT_MAIN and delete the same from IT_FINAL.

Now we have IT_FINAL which contain data to be printed in 5 secondary windows and IT_MAIN which
contain data for main window.  
Step3:-
Create 5 work areas wa_1, wa_2, wa_3, wa_4, wa_5 of the type of line of IT_FINAL in the global
declaration area.  
Write code to move 1st 5 rows from IT_FINAL to the above declared work areas and then delete those
5 rows form internal; table as shown in the below screen-shot.  

 
Step 4:-
Now create a text node in every window and pass the label data from wa_1 to text node of 1st
secondary window and so on.  
Every Node has a condition that it will execute only if the corresponding work area value is not initial.  

 And instead of
window for every node tick the checkbox to draw frame lines, so that frame is printed only if the text
node has data to print.  

Step 5:-
Now in the Main window create a table node in the table painter create a line type with one row whose
width is equal to the width of label to be printed.  

Under the data tab pass IT_MAIN.  


.
Step 6:-
Now in the Main WindowMain Area of table create a row with line type created above and in the cell
create a text node and pass the corresponding data which needs to be printed in the label.  

Step 7:-
Create a command line after table node which will call page1 itself
On the condition that IT_FINAL is not initial.  
 

The reason why command line is used is suppose we have 15 labels to be printed then it will be like
Page1->6 Page2-> 6 and Page3->3 labels respectively.  
Initially IT_FINAL will have 13 and IT_MAIN will have 2 rows which are for 6 th and 12th label. After 12th
label is printed main table will not have any more data to print. The command line will check if any
more labels are yet to be printed by checking entries in IT_FINAL table. If yes it will trigger 3 rd page
which print the last three labels.  
Output Page1:-
Dunning using Smartforms

Configure the BTE - Business Transaction Events


Transaction code - FIBF - Maintenance transaction BTE
Click on Settings-->P/S Modules--->...of an SAP Application

 
Press

 
Press

Change the Function module name for the selected entry - FI_PRINT_DUNNING_NOTICE to
FI_PRINT_DUNNING_NOTICE_SMARTF as shown below.

Configure the Dunning note Smart Form


Transaction code - FBMP - Maintain Dunning Procedure
Goto Environment --> Company Code Data
Click on  and enter the below fields with the below values.
CoCd Company Code  
 
By dun.ar. Check the flag
 
Ref.CoCod Company Code
 
e  
Sort.MHNK K1

 Sort.MHND P1

Click Save

Create a custom dunning procedure, click on

Go back  and Save . Select


Go back  and Save . 
Click on . Enter the currency

   
click

Go back  and Save


Configure the Smartforms details
Transaction code - SPRO
Path:
Financial Accounting - Account Receivables and Account Payables - Business Transaction - Interest
Calculation - Print - Define Sender details for Interest Forms
Click on  and enter your company code

Enter the below values

Click on
Attach the smartform to the Dunning Procedure

Transaction code - FBMP. Click on dunning procedure '0001'. Click on

Enter the below smartform names to the dunning levels.

Now the dunning can be tested using transaction F150.


Using 'COMMAND' to achieve page break

In some cases user will ask only specific number of records should be displayed per page, but based
on space availability of main window data will populate. To restrict manually the number of records
displayed per page we can use COMMAND.
1. Go to smartforms tcode and create a smartform, in global definition part declare the variables and
tables as shown in above

2. Click on initialization tab, write the query and pass that internal table to output parameters

3.Click on main window and create table & also table line with 4 columns

4. Create assign table line for header and create text for each column
Cell1 = S.No
Cell2 = Customer No
Cell3 = City
Cell4 = Country Key
5. Click on main area and create a loop, give internal table & workarea as shown

6. Right click on loop and create command, followed by table line Create table line for the loop. we will
get four columns now. Create text for every column
7. In cell 5 i.e first column, create a code by right clicking on that cell->create->flow logic-
>programming lines

8. In that code, write the following code and pass variables to output parameters
Cell5 = &GV_NO&
Cell6 = &GS_KNA1-KUNNR&
Cell7 = &GS_KNA1-ORT01&
Cell8 = &GS_KNA1-LAND1&

9. Right click on page1 and create page2


10. Now go to command in page1-main window, click on condition tab in that command and give
condition as shown

11. Click on general Attributes tab , check Go to New Page Box and choose page2 in the dropdown
given next.

12.Go to page1 copy main window


13. Paste this main window in page2

Now our form should look like this


14. Check, Save, Activate & Execute it. Op will be

Only ten records per page will be displayed.


15. Comment our code which sets flag for page break
16. Save, Activate & Execute it , Output Will be

Summary
Using this command we manually control numbers of records displayed per page based on some
condition. in the above example our condition was only ten recods per page. we can implement  the
same for other conditions also.
Using ALTERNATIVE in Smart forms

This tutorial is describes how to use Alternative Condition in smartforms. In this form we will get
country code as input, if the country code is 'IN' text part relevant to that will be displayed. if country
code is other than 'IN' text part relevant to false part will be displayed.
1. Go to Transaction 'SMARTFORMS' and give your new form name and click on create

2. Select Form interface and declare a variable called 'COUNTRY', Data type is CHAR, Length 2.

3. Right click on main window and Create->Flow Logic->Alternative


4.  After creating Alternative your form will look like this

5. In General Attributes of the alternate give condition COUNTRY = 'IN' as shown below

6. Right Click on True and create text and write some text in that, likewise create text and
write something for false condition also. Now our screen will appear as shown below
(In this case I have written ‘Alternate Condtion True – Country is India’ for the text in true
condition and ‘Alternate Condtion True – Country is India’ for text in false condition)
7. Check, Save, Activate & Execute the form.

8. First we will execute without giving country value & the output is
 

9. Now if we give Country value as 'IN' then the output will be

10. Output for 'IN' is

Summary
In this Alternative, we will give some condition. if the condition is true, only the elements
within true node will be executed if its false only the elements within false node will be
executed.

You might also like