Register Login

What is Smartform?

Updated May 18, 2018

A Simple Smartform Tutorial

SAP Smartforms can be used for creating and maintaining forms for mass printing in SAP Systems. The output medium for Smartforms support printer, fax, e-mail, or the Internet (by using the generated XML output).

According to SAP, you need neither have any programming knowledge nor use a Script language to adapt standard forms. However, basic ABAP programming skills are required only in special cases (for example, to call a function module you created or for complex and extensive conditions).

1. Create a new smartforms

Transaction code SMARTFORMS
Create new smartforms call ZSMART

2. Define looping process for internal table, Pages and windows

  • First Page -> Header Window (Cursor at First Page then click Edit -> Node -> Create)
    Here, you can specify your title and page numbering &SFSY-PAGE& (Page 1) of &SFSY-FORMPAGES(Z4.0)& (Total Page)
  • Main windows -> TABLE -> DATA
  • In the Loop section, tick Internal table and fill in
  • ITAB1 (table in ABAP SMARTFORM calling function) INTO ITAB2

3. Define table in smartforms Global settings :

Form interface

Variable name Type assignment Reference type
ITAB1 TYPE Table Structure

Global definitions

Variable name Type assignment Reference type
ITAB2 TYPE Table Structure

4. To display the data in the form

Make used of the Table Painter and declare the Line Type in Tabstrips Table e.g. HD_GEN for printing header details, IT_GEN for printing data details.
You have to specify the Line Type in your Text elements in the Tabstrips Output options.
Tick the New Line and specify the Line Type for outputting the data.
Declare your output fields in Text elements Tabstrips - Output Options
For different fonts use this Style : IDWTCERTSTYLE
For Quantity or Amout you can used this variable &GS_ITAB-AMOUNT(12.2)&

5. Calling SMARTFORMS from your ABAP program

REPORT ZSMARTFORM.

* Calling SMARTFORMS from your ABAP program.
* Collecting all the table data in your program, and pass once to SMARTFORMS
* SMARTFORMS
* Declare your table type in :-
* Global Settings -> Form Interface
* Global Definintions -> Global Data
* Main Window -> Table -> DATA

TABLES: MKPF.

DATA: FM_NAME TYPE RS38L_FNAM.

DATA: BEGIN OF INT_MKPF OCCURS 0.
INCLUDE STRUCTURE MKPF.
DATA: END OF INT_MKPF.

SELECT-OPTIONS S_MBLNR FOR MKPF-MBLNR MEMORY ID 001.

SELECT * FROM MKPF WHERE MBLNR IN S_MBLNR.
MOVE-CORRESPONDING MKPF TO INT_MKPF.
APPEND INT_MKPF.

ENDSELECT.

* At the end of your program.
* Passing data to SMARTFORMS

call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'ZSMARTFORM'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
FM_NAME = FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.

if sy-subrc <> 0.
WRITE: / 'ERROR 1'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

call function FM_NAME

* EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
* CONTROL_PARAMETERS =
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* OUTPUT_OPTIONS =
* USER_SETTINGS = 'X'
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
TABLES
GS_MKPF = INT_MKPF
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.

Difference with SMARTFORMS vs. SapScript(SE71)

The Following are the differences :-

a) Multiple page formats are possible in smartforms which is not the case in SAPScripts

b) It is possible to have a smartform without a main window .

c) Labels cannot be created in smartforms.

d) Routines can be written in smartforms tool.

e) Smartforms generates a function module when activated.

Contributed by : SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

f) Unlike sapscripts (RSTXSCRP), you cannot upload/download Smartform to your local harddisk.

It was said that it was provided in CRM 3.0 version, but not available in SAP R/3 You can download smartforms into Local PC in a XML format. In the same way you can upload this XML format into Smartform. From the smartform editor itself you can call download option, if you are working in CRM 3.0 environment

In R3 also, you can download into XML format. However, it's not sure about uploading. Refer to the program 'SF_XSF_DEMO'.

In 4.7 Enterprise, other have seen this utlity which is completely missing in 4.6c. There is functionality to download a complete form or only a particular node. (Utilities -> Download form). It will create a XML file and save it in the hard disk.

For others, if you want to download/upload the Smartforms source, you will need the help from the Basis people. What you can do is to create a Transport and then FTP down to your local harddisk. When you need the Smartform source in another system, you have FTP up the Smartforms file back to the SAP server. Finally, the Basis team, will tp it into your system.

g) The protect and and protect command in sapscript doesn't work with smartforms. For example on an invoice: First data of position no 80. is printed on page one, other data of position no 80 is printed on page 2. And there's nothing you can do about it. Actually, there is something you can do about it. By using a folder node and checking the 'protect' checkbox, everything in that folder will be page protected.

A Sample Program Calling Smartforms

You should use 'SSF_FUNCTION_MODULE_NAME' & call function fm_name in your program & not others.

*&---------------------------------------------------------------------*

*& Report ZTACA_DRIVER_SMARTFORM *

*& *

*&---------------------------------------------------------------------*

*& *

*& *

*&---------------------------------------------------------------------*

REPORT ZTACA_DRIVER_SMARTFORM .

Tables : sflight.

Data : fm_name TYPE rs38l_fnam.

*data : Begin of it_flttab occurs 0,

* carrid type sflight-carrid,

* connid type sflight-connid,

* fldate type sflight-fldate,

* seatsmax type sflight-seatsmax,

* seatsocc type sflight-seatsocc,

* End of it_flttab.

data : it_flttab like table of sflight.

Data : g_salary type i .

* it_flttab type standard table of ty_flt.

g_salary = 1000.

select carrid connid fldate seatsmax seatsocc from sflight into

corresponding fields of table it_flttab.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZTACA_SMFORM2'

* VARIANT = ' '

* DIRECT_CALL = ' '

IMPORTING

FM_NAME = fm_name

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.

call function fm_name

Exporting

salary = g_salary

TABLES

it_flttab = it_flttab

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.

Display a contents of a table on SmartForm with LOOP

There's a DDIC Table called "Ugyfel" containing 5 rows. I'd like simply to display all the rows on a SF's Main window.

Please follow this process to display the value from your table "Ugyfel"

1. Go with a transaction code : smartforms
2. Enter the form name like : ysmart_forms1
3. Create
4. Enter the Description for the form
5. From the left side window there will be a form interface to provide table .....
6. Go for tables option
7. ugyfel like ugyfel(ref.type)
8. Pages and window---> page1---> main window
9. Go to the form painter adjust the main window.
10. Select main window and right click --> go for create loop
11. Name: loop1, desc: display loop.
12. Internal table ktab into ktab.
13. select loop right click -> create a text
14. name : text1, desc: display text.
15. Go to change editor.
16. Write the mater what ever you want and if you want to display data from the table write the table fields as follows:

&ktab-& &ktab-&

save & activate then execute ,, scripts will generate a function module like : '/ibcdw/sf0000031' copy this function module and call in executable program...

For that
1. go with abap editor se38.
2. table: ugyfel.
3. parameters: test like ugyfel-.
4. data itab like ugyfel occurs 0 with header line.
5. select * from ugyfel into table itab where field1 = test1.
6. call function '/ibcdw/sf0000031'
7. tables
ktab = itab.

Save and activate the program ( ^f 3).

Now run the program ( f 8)

Smart forms Frequently Asked Questions

Forcing a page break within table loop

Create a loop around the table. Put a Command node before the table in the loop that forces a NEWPAGE on whatever condition you want. Then only loop through a subset of the internal table (based on the conditions in the Command node) of the elements in the Table node.

Font style and Font size

Goto Transaction SMARTSTYLES.
There you can create Paragraph formats etc just like in sapscript.

Then in your window under OUTPUT OPTIONS you include this SMARTSTYLE and use the Paragraph and character formats.

Line in Smartform

Either you can use a window that takes up the width of your page and only has a height of 1 mm.

Then you put a frame around it (in window output options).
Thus you have drawn a box but it looks like a line.

Or you can just draw "__" accross the page and play with the fonts so that it joins each UNDER_SCORE.

Difference between 'forminterface' and 'global definitions' in global settings of smart forms

The Difference is as follows.

To put it very simply:

Form Interface is where you declare what must be passed in and out of the smartform (in from the print program to the smartform and out from the smartform to the print program).

Global defs. is where you declare data to be used within the smartform on a global scope.
ie: anything you declare here can be used in any other node in the form.

Smartforms function module name

Once you have activated the smartform, go to the environment -> function module name. There you can get the name of funtion module name.

The key thing is the program that calls it. for instance, the invoice SMARTFORM LB_BIL_INVOICE is ran by the program RLB_INVOICE.

This program uses another FM to determine the name of the FM to use itself. The key thing is that when it calls this FM (using a variable to store the actual name), that the parameters match the paramters in your smartform.

Another thing to note is that the FM name will change wherever the SF is transported to.

So you need to use the FM to determine the name of the SF.

Here is the code that can be use to determine the internal name of the function module:

Code:

if sf_label(1) <> '/'. " need to resolve by name
move sf_label to externalname.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = externalname
importing
fm_name = internalname
exceptions
no_form = 1
no_function_module = 2
others = 3.
if sy-subrc <> 0.
message 'e427'.
endif.
move internalname to sf_label.
endif.

It checks to see if the sf_label starts with a '/', which is how the internal names start. if it does, the name has already been converted. If not, it calls the FM and converts the name.

You would then CALL FUNCTION sf_label.

SmartForms System Fields

Within a form you can use the field string SFSY with its system fields. During form processing the system replaces these fields with the corresponding values. The field values come from the SAP System or are results of the processing.

System fields of Smart Forms

&SFSY-DATE&
Displays the date. You determine the display format in the user master record.

&SFSY-TIME&
Displays the time of day in the form HH:MM:SS.

&SFSY-PAGE&
Inserts the number of the current print page into the text. You determine the format of the page number (for example, Arabic, numeric) in the page node.

&SFSY-FORMPAGES&
Displays the total number of pages for the currently processed form. This allows you to include texts such as'Page x of y' into your output.

&SFSY-JOBPAGES&
Contains the total page number of all forms in the currently processed print request.

&SFSY-WINDOWNAME&
Contains the name of the current window (string in the Window field)

&SFSY-PAGENAME&
Contains the name of the current page (string in the Page field)

&SFSY-PAGEBREAK&
Is set to 'X' after a page break (either automatic [Page 7] or command-controlled [Page 46])

&SFSY-MAINEND&
Is set as soon as processing of the main window on the current page ends

&SFSY-EXCEPTION&
Contains the name of the raised exception. You must trigger your own exceptions, which you defined in the form interface, using the user_exception macro (syntax: user_exception ).


×