Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

Smart forms

 Smart form is a GUI Tool (Graphical User Interface) which is used to design the business
legal documents such as Delivery note, Purchase order, Invoice etc.
 The transaction code is SMARTFORMS.
 Smart forms are client independent objects.
 Smart forms are advanced version of SAP Scripts.
 It is a GUI tool and it is user friendly.

Smart form architecture:

Smart forms and SAP Scripts differences.


Smart forms SAP Scripts
Smart forms are client independent. SAP Scripts are client dependent.
Main window is not compulsory. Main window is compulsory.
Smartforms generates a function module when activated. No Function Module will be generated.
Smartforms texts supports various colors. Scripts allows black and white colors only.
Only single page format is possible. Multiple page formats are available.

COMPONENTS OF SMARTFORMS.
There are two main nodes in Smart forms.
1. Global Settings
 Form Attribute.
 Form Interface.
 Global Definition.

2. Pages and Windows.

Global settings:
It is used to provide the basic settings for the smart form.
Form Attributes:
It specifies the general attributes like who created, Date, time, package, translate options, default
smart style, Page format (DINA4/DINA5).
Form interface:
It acts as a mediator between a driver program and a smart form.
The main functionality of form interface is, it will import the parameters which are exported by driver
program.
The parameters can be variables, work areas, internal tables...etc.
Global definition:
It will contain the variables to be used within the smart form.
We can define variables, user defined data types, field symbols, initialization code, Subroutine,
currency/quantity fields.
It is mainly used for declaring or defining the above variables.
Pages and Windows

 Page.
 Window.
 Graphic.
 Address.
 Text.
 Table.
o Header.
o Body.
o Footer.
 Template.
 Folder.
 Program Lines.
 Alternative.
 Command.
 Loop.

Pages and windows


This will contain all the pages and the windows, which are used in the smart form.
By default, a page will be created by name %page1.
By default, a window will be created by name 'Main' under the page1.
For each page, we need to specify the next page.
Eg: page = %page1 
Next page = %page1 or %page2 
Nodes under pages
Page : It is used to define the layout of a smart form.
We can have different pages with different layouts.
Window: it is used to display information or text at a particular place on a page.
Graphic: it is used to display logos or images on the smart forms.
Address: It is used to display the address of customer or vendor or employee, organization
address , workplace address etc.
Just provide address no, it will automatically display the address as per the country formats.
Nodes under the window
Text : it is used to display the information or text in a window.
Table : It is used to display the information in the form of table.
Whenever we create table by default HEADER, MAIN AREA (BODY), FOOTER will be displayed.
The main functionality of a table is, it expands automatically depending on the internal table data.
We need to provide the name of the internal table for a table.
Template: template is also like a table which does not expand. That means it will have fixed number
of rows and columns.
Program lines: it is used to write some lines of abap code.

Window Types in Smart forms


Main window: For continuous output.
Secondary window: For output with a fixed length.
Final window: Special type of secondary window for outputting the information that is not known
until the end of form processing.
Copies window: Special type of secondary window for marking pages as copy or original. 

Example Smart form GUI


Go to SMARTFORMS T-code.

Provide form as ZSAP_TEXT, click on create.

You will find screen below.


Expand page, right click on main window -> create -> Text.

(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 )

Go to general attributes tab, add some text.


Click save, save it in a local object, activate and click on execute.

Whenever we activate a smartfrom, one function module will be generated, when we execute it, it
will go to function module.

Just click execute (F8).


And again press F8, execute.

Provide output device as LP01, click on print preview.


Smartform output will be displayed.

Using global definitions, structures and initialization in smart forms


In the below example we will learn.

 Using global decelerations in smartforms.


 Using user defined structures.
 Using initialization of data.

Go to T-code, SMARTFORMS, provide name as ZSAP_GLOBAL_INIT and click create.

Double click on global definitions, go to types tab and add below code.
types: BEGIN OF ty_mara,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
matkl type mara-matkl,
meins type mara-meins,
END OF ty_mara.

Go to global data tab, create a variable of type ty_mara.


Go to initialization tab, add output parameter as wa_mara, add below code to get material details.

select SINGLE * FROM mara


into CORRESPONDING FIELDS OF wa_mara
WHERE matnr = '000002-000'.
**Material no must be in MARA

Expand page, double click on main window, right click on main window -> create -> text.

Go to general attributes tab.


Add a label, click on insert field, a popup will come provide variable name by adding '&' at beginning
and ending.

In the same way add other fields also.

Save, activate and execute(F8).


You will go to a function module.
Just execute.
Execute again.
Provide output device as LP01.
Smartform is displayed.

Using tables in smart forms using tables element.


Go to T-code SMARTFORM, provide name ZSAP_TABLE and click on create.

Click on global definitions; add a structure under types tab.


Click on global data and add parameters as below.

Go to initialization tab, add output parameter as IT_MARA and add below code get materials.

Expand page, right click on main window -> create -> table.
Whenever we create a table, header, main area, footer for the table will be created automatically.
Now we need to draw columns, we know smart forms is a GUI designer, we need to design table
columns, to create table columns go to table tab, click on pencil icon and draw five vertical lines( no
of lines = internal table fields).

Click on details to specify size of column.


Specify sizes as below.

Go main window, output options and specify width, height as below.

Right click on header -> create -> table line

Select line type from drop down.


Right click on each cell, create -> text to create column headers.

Go to general attributes tab and provide text as Material No.


Similarly create column header texts for all cells as below.
Industry Sector
Material Type
Material Group
Base Unit of measure
Double click on main area, create -> table line.

Select a table line  %LTYPE1 from drop down.


Click on insert field icon from General Attribute, a popup will come and provide variable as
&wa_mara-matnr&, enter.

Similarly create text for all cells and insert respective variables as below.
&wa_mara-mbrsh&
&wa_mara-mtart&
&wa_mara-matkl&
&wa_mara-meins&
Double click on table, go to tab data and loop internal table as below.
Save, activate and execute (F8).

Using loops in smart forms


Sometimes, we may need to use loops in smart forms to display data, below is the example of using
loop s to display data.
Go to T-code SMARTFORMS, provide name as ZSAP_LOOPS and click on create.

Double click on global definitions, go to types tab and add below code.
types: BEGIN OF ty_mara,
matnr type mara-matnr,
mtart type mara-mtart,
meins type mara-meins,
end of ty_mara.

Go to global data tab and create table and work area.

Go to initialization tab and add below code to get material details.

select * FROM mara


into CORRESPONDING FIELDS OF TABLE it_mara
UP TO 50 ROWS.
Double click on main window, right click -> create -> flow logic -> loop.

Add internal table IT_MARA and work area WA_MARA as looping parameters.

Right click on loop, create -> text.


Click on insert field icon in General Attribute tab and insert work area fields.

Similarly insert all work area fields.


Save, activate and execute (F8).
It will go to function module, execute.
Again execute and provide OutputDevice as LP01, print preview.
Add LOGO in smart forms:
Logo should be in BMP format only.
Goto SE78 transaction
Expand GRAPHICS --> select BMAP images
Click Import (F5) icon.

Select location of picture and provide any Name


Click OK
Now click Transport icon
Goto Transaction SMARTFORMS

Click create
Create LOGO window and Add Graphic
Save and Activate, then Execute

SMARTFORM creation with Driver Program:


Select transaction code SMARTFORMS, provide name ZSALES_ORDER_FORM, and create
From global settings click on form interface (form interface have function module - import, export…)
Select Tables tab means internal table, declare internal tables for customer window, sales order
window and line item window.

Go to global definition to define variables for actual price calculation and for changing date format.
Below variables for actual price calculation
These variables to change Date format

Select pages and windows, from that click on %page1


Maintain name & description to the page

Select page1 right click  create  window


Provide below details

Select page1 right click  create  window


Provide below details

Repeat same procedure for Customer window, Sales order window, Barcode window and Telno
window.
Adjust 7 windows properly in page1 (drag and drop)

Select Form Painter to adjust windows in page as graphical


Select form painter again to close graphical format
SAVE form design
Now, select tcode SMARTFORM and select STYLE option then provide name ZSTYLE, create

Maintain Description
Select paragraph format --> right click then select create Node
Provide paragraph format : P1 , maintain description
Select Font option, provide font family COURIER , font size 12, font style BOLD
Select character format right click Create Node
Provide character format: C1, maintain description
Select Standard settings, in that provide BARCODE name : BC_EAN8 (sap provided)
Select font maintain font family COURIER , font size 12, font style BOLD
Select Header Data double click
In Standard Paragraph field provide Paragraph format : P1
SAVE and ACTIVATE Style
 In smartforms Paragraph format and Character formats are reusable. Bcoz those are
maintain separately in Style. Where as in scripts this is not possible bcoz in scripts
Paragraph format and Character formats are maintain with in form itself.

Go back to Smart form ZSALES_ORDER_FORM and click CHANGE


Select Page and Windows, expand Page1
Select LOGO window, Right click Create  Graphic
In name field provide predefined Logo name by selecting to F4
Name: IDES_LOGO
Select DATE window , right click Create  Flow Logic  Program Lines
 To customize logic for changing date format
Input parameters to change date format are: V_DD V_MM V_YYYY
Output parameter is : V_DATE
 Logic to change Date format
V_DD = SFSY-DATE+6(2). SFSY-DATE is smart form’s System Variable for Date
V_MM = SFSY-DATE+4(2).
V_YYYY = SFSY-DATE+0(4).
CONCATINATE V_DD’/’V_MM’/’V_YYYY INTO V_DATE.
Select DATE window from that select program lines customized, Right click, Create, Text
From General Attributes, select Text editor, GOTOChange editor

‘*’ Means SAP provided Paragraph format.


BACK (F3)

Select Customer window Right click, Create -> Flow logic -> Loop
Provide Internal Table : ITAB INTO ITAB ( equal to: Loop at ITAB .. Endloop.)

Select customer window, from that select %loop customized, Right click->Create->Text
to maintain variables with in loop.. endloop for customer window
from General Attributes, select Text editor, GOTO -> Change editor
BACK (F3)
Select Sales window, Right click -> Create -> Flow logic -> Loop

Select sales window then %loop customize, Right click -> create-> Text
to maintain variables with in loop.. endloop for sales window
from General Attributes, select Text editor, GOTO -> Change editor

BACK (F3)
Select MAIN window ,Right click-> create -> Table
Select Table , put cursor on %LTYPE1, Right click -> Split -> Line , %LTYPE2 will be added
automatically.
select LTYPE1 -> Right click -> Split -> Cell
select LTYPE1 -> Right click -> Split -> Cell
select LTYPE1 -> Right click -> Split -> Cell
select LTYPE1 -> Right click -> Split -> Cell
it will create 5 columns.
Repeat same procedure for LTYPE2 ( 5 columns)
Select Details provide Description for LTYPE1 and LTYPE2 as LABELS and DATA
Select Table Painter , Select Pattern, choose one of pattern from this list to Main window

From table select Header Right click -> create -> Table line

provide Line type : LABELS

click on cell1 Right click ->Create -> Text, from General Attributes,
Text editor, GoTo -> Change editor
BACK (F3)
click on cell2, cell3, cell4, cell5 repeate same procedure and keep labels MATERIAL, QUANTITY, PRICE
and DISCOUNT
From Tables select MAIN Area, to keep variables for Data, Right click -> Create-> Flow logic-> Loop

select %loop customized in Main Area, Right click -> create -> Table Line

provide Line type : DATA


select cell6 , Right click-> create->Text. from General Attributes, Text editor, GoTo -> Change editor

BACK(F3)
select cell7, Right click-> create->Text. from General Attributes, Text editor, GoTo -> Change editor

* &ktab-MATNR& BACK(F3)
select cell8, Right click-> create->Text. from General Attributes, Text editor, GoTo -> Change editor

* &ktab-kwmeng& BACK(F3)
select Text customize of cell8, Right click-> create->Flow Logic->Program Lines.

to maintain logic for discount calculation based on Quantity of customer purchased.


(Discount is given based on Quantity so we write in cell8)
price = ktab-netwr.
total_price = total_price + ktab-netwr.
if ktab-kwmeng <= '2'.
  discount = ktab-netwr * 10 / 100.
  else.
    discount = ktab-netwr * 20 / 100.
    endif.
 total_discount = total_discount + discount.
 actual_price = total_price - total_discount.
BACK(F3)
select cell9, Right click-> create->Text. from General Attributes, Text editor, GoTo -> Change editor
* &Price& (erlier we assign NETWR to ktab so we take only price) BACK(F3)
select cell10, Right click-> create->Text. from General Attributes, Text editor, GoTo -> Change editor
* &Discount& BACK(F3)
Select BARCODE window , Right click -> Text
select output options, provide style name which is already created

from General Attributes, Text editor, GoTo -> Change editor

BACK(F3)
Select Tele No window , Right click -> Text. from General Attributes, Text editor, GoTo -> Change
editor

BACK(F3)
From Main window, click on Table, select DATA tab

Uncheck the Loop statement


Uncheck the loop to display the data in main window for one time only.
SAVE and ACTIVATE the FORM.
Execute Form. system generated one Function Module, in this smartform logic kept.
------
Print Program or Driver program Creation as per Form Customized.
Select Editor se38 and create executable program. ZSO_PRINT_PROGRAM
REPORT  ZSO_PRINT_PROGRAM.

Tables: kna1, vbak,vbap.

* selection screen logic to enter sales order number
parameters: sorder type vbak-vbeln OBLIGATORY.

*Declare internal tables for customer window, sales order window and Line It
em window
data: it_itab type STANDARD TABLE OF kna1,
      it_jtab type STANDARD TABLE OF vbak,
      it_ktab type STANDARD TABLE OF vbap.

data: fm_name type rs38l_fnam. "rs38l_fnam is predefined data element for na
me of Function module

data: v_spool type ssfcrescl. "ssfcrescl is a predefined database structure 
to print parameters in smartforms

data: v_spoolno type rspoid. "rspoid is predefined data element to generates 
spool request number

* SQL statement to check and extract sales order number entered in selecctio
n screen
select * from vbak into table it_Jtab where vbeln = sorder.

*SQL statement to extract customer data and line item data based on sorder 
no having in IT_JTAB
If not it_jtab is initial.

  select * from kna1 into table it_itab FOR ALL ENTRIES IN it_Jtab
    where kunnr = it_Jtab-kunnr.

 select * from vbap into table it_ktab FOR ALL ENTRIES IN it_Jtab
   where vbeln = it_Jtab-vbeln.

Endif.

*select pattern select call function : SSF_FUNCTION_MODULE_NAME    click ent
er
     CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING
         FORMNAME                 = 'ZSALES_ORDER_FORM'
*        VARIANT                  = ' '
*        DIRECT_CALL              = ' '
      IMPORTING
       FM_NAME                  = FM_NAME  " system generated function module 
              .
     IF SY-SUBRC <> 0.
* Implement suitable error handling here
     ENDIF.

     CALL FUNCTION FM_NAME  "is used to pass data into the form based on inp
ut value entered by user
     IMPORTING
       sorder = sorder
       job_out_info = v_spool
       TABLES
         itab = it_itab
         jtab = it_jtab
         ktab = it_ktab.
* logic to generate spool request number (it is used to send from FORM to P
rint program)
     loop at v_spool-spoolids into v_spoolno.
       endloop.

*     logic to support FORM in PDF
       submit rstxpdft4 with spoolno = v_spoolno.

Execute the Program.

OR
How to Debugg the SMARTFORM?
In Program Lines maintain Break-Point before code to switch on debugging.

NACE Transaction:
NACE is the Tcode used to link the Application type, Output Types and its processing Routines like (
Driver programs and attached Script forms or Smart forms).
You should know the Application of a document first Like:
for PO it is EF, for sales Doc's it is V1, for Delivery docs it is V2, for billing Doc's it is V3 etc
NACE is used for Output Type Configuration.
Goto Transaction NACE --> Select Application V1(Sales) --> Click on Output Types --> Select the
output type as BA00 (as generally BA00 is the output type associated with Sales Order ) --> Double
click on the Processing Routines folder on the left and it will display the Form name and the
corresponding driver programs name.

Practice below Examples:


http://www.saptechnical.com/Tutorials/Smartforms/Exercises/SolutionEx1/Page1.htm

You might also like