You are on page 1of 7

A Step By Step SmartForms Tutorial

Today I want to teach you how to create a simple SmartForms. SmartForms its a very robust
program which I think is far much better than the good old SAP script, its very recommended to
use SmartForms when creating print out form such as Invoice, Sales Order, Delivery Order, etc.
Okay now lets start our training today.
1. First execute TCODE smartforms
2. Create a new smartform program, just name it as ZSFEXERCISE and click CREATE.

3. On Global Settings, click Form Interface and on your right select the TABLES tab. Here you
can define internal table to use for the report fields structure, you can define more than 1 table
depending on your program requirements. In this example lets create 1 internal table named ITAB
using table SPFLI field structure.

4. Next go to Pages and Windows section (Below Global Settings), open the %PAGE1 New Page
folder until you find MAIN Main Window folder, after that Right click > Create > Table This will
create an internal table that can get the query result from the report interface.

5. In this next screen, you will see an empty box that will act as the main body of your report to
display the report data.
But first we need to define how many columns we want to have on this report, to do this just click
Draw Lines And Columns (Pencil button) button and draw a vertical lines on the box to create
the report columns. In this example, I drew 3 vertical lines that will create 4 report columns.

6. Now go to Main Area (below the header), right click the Main Area > Create > Table Line. This
will one new line 1 just below the main area section, on the right screen you can see the Output
Table section, now select the Line Type selection box and click on %LTYP1. After that, you can
see that all 4 columns we created earlier in step 5.

7. Now we need to attach internal table columns to display on this smartforms columns, right click
the first column > Create > Text this will create a new text icon just below the first CELL Column.

8. Click on the TEXT1 icon we just created earlier, select the General Attributes tab, and click the
EDITOR button (The pencil)

9. Now this is very important, to define internal table field column on smartforms, you must type
&itab-columnname& (begin and ended with a &).
In this example I want this first column to dispaly the connid column in the SPFLI table, then I will
write &itab-connid&

10. Now repeat step 8 and 9 to display these other 3 columns.

&itab-connid& (on Cell2)


&itab-cityfrom& (on Cell3)
&itab-cityto& (on Cell4)

11. On the Main Window, click on the TABLE section. In this part you have to define the internal
table name used to display the data. In this example were using ITAB.

See picture below for a clearer view.

12. After that Click Activate


Now the last step would be to create a program that will be the interface to call this smartform.
13. Execute SE38, create a program ZRPTEXERCISE

14. Now copy and paste this code below.


01.REPORT ZRPTEXERCISE.
02.
03.DATA T_SPFLI TYPE TABLE OF SPFLI WITH HEADER LINE.
04.DATA FUNC_NAME TYPE RS38L_FNAM.
05.DATA ITAB LIKE STANDARD TABLE OF SPFLI WITH HEADER LINE.
06.
07.START-OF-SELECTION.
08.
09.SELECT * INTO TABLE ITAB FROM SPFLI.
10.
11.CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
12. EXPORTING
13.
formname
= 'ZSFEXERCISE'
14.*
VARIANT
= ' '
15.*
DIRECT_CALL
= ' '
16. IMPORTING
17.
FM_NAME
= FUNC_NAME
18.* EXCEPTIONS
19.*
NO_FORM
= 1
20.*
NO_FUNCTION_MODULE
= 2
21.*
OTHERS
= 3
22.
.
23.IF sy-subrc <> 0.
24.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

25.*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
26.ENDIF.
27.
28.CALL FUNCTION FUNC_NAME
29.* EXPORTING
30.*
ARCHIVE_INDEX
=
31.*
ARCHIVE_INDEX_TAB
=
32.*
ARCHIVE_PARAMETERS
=
33.*
CONTROL_PARAMETERS
=
34.*
MAIL_APPL_OBJ
=
35.*
MAIL_RECIPIENT
=
36.*
MAIL_SENDER
=
37.*
OUTPUT_OPTIONS
=
38.*
USER_SETTINGS
= 'X'
39.* IMPORTING
40.*
DOCUMENT_OUTPUT_INFO
=
41.*
JOB_OUTPUT_INFO
=
42.*
JOB_OUTPUT_OPTIONS
=
43. TABLES
44.
itab
= ITAB
45.* EXCEPTIONS
46.*
FORMATTING_ERROR
= 1
47.*
INTERNAL_ERROR
= 2
48.*
SEND_ERROR
= 3
49.*
USER_CANCELED
= 4
50.*
OTHERS
= 5
51.
.
52.IF sy-subrc <> 0.
53.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
54.*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
55.ENDIF.

15. Now run the program. Heres the Smartforms beautiful report display.

You might also like