Sei sulla pagina 1di 27

Smartforms

Developing Smartforms using SAP Smartform layout


designer
Smartform

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

Smartform architecture:

Smatrtforms and SAP Scripts differences .


Smartforms

SAP Scripts

Smartforms are client independent.

SAP Scripts are client


dependent.

Smartforms

SAP Scripts

Main window is not compulsory.

Main window is compu

Smartforms generates a Function module when activated.

No Function Module w
generated.

Smartforms texts supports various colors.

Scripts allows black an


colors only.

There is no transfer of control between program and form, once the control is transfered
to Function Module, it will never come back.

Scripts has repeated t


of control.

Only single page format is possible.

Multiple page formats


available.

COMPONENTS OF SMARTFORMS.
There are two main nodes in Smartforms.
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 smartform.

Form Attributes:
It specifies the general attributes like who created,Date,time, package,translate options, default
smartstyle, 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 smartform.
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 smartform.
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 smartforms.
Address : It is used to display the address of customer or vendor or employe, 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.
When ever we create table by default HEADER, MAIN AREA, 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 Smartforms


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 Smartform GUI

Simple Smartform to Display Text


Go to SMARTFORMS T-code.

Provide form as ZSAPN_TEXT, click on create.

You will find screen below.

Expand page, right click on min window -> 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 Variables and


initialization in Smartforms
Using global definitions, structures and initialization in smartforms

Using global decelerations in smartforms.


Using user defined structures.
Using initialization of data.

Go to T-code, SMARTFORMS, provide name as ZSAPN_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 smartforms


using tables in smartforms using tables element.
Go to T-code SMARTFORM, provide name ZSAPN_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 smartforms 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 view, 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 icon, 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 SMARTFORMS


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 ZSAPN_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 icon 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.

Potrebbero piacerti anche