Sie sind auf Seite 1von 49

A Step-by-Step Approach to Create SAP Script

1. Introduction
Purpose of document: This document is all about creation of SAP
Script. This document will help in –
 To familiarize with SAP Script
 Elements of SAP Script
 Processing of SAP Script
 Step-by-Step method to create a simple script
 Some advanced control commands in brief.

Who will benefit: All ABAPers.

Prerequisite: Knowledge of ABAP.

2. Introduction to SAP Script

Business uses several forms in day-to day activities. These forms can be
a–
 Purchase Orders
 Sales Orders
 Credit Memos
 Debit Memos
 Invoices
 Salary Slips etc.
To facilitate design, build and printing of these forms, SAP provides a
tool which is known as SAP Script. In addition to it, R/3 comes with a
set of pre-designed forms that can be easily customized to fit the needs
of individual business.
For e.g. - MEDRUCK is a SAP Script layout which is available in R/3
system which can be used to generate Purchase Order. This is a
standard layout available in R/3 for generation of Purchase Order which
can be customized according to individual business needs.

A SAP Script layout is not alone capable of printing these various


business forms; it’s merely a structure which defines areas within a page
that is populated with data specific to business needs. The collection of
data and passing it to script layout is done through its FORM Routine.
This FORM Routine is an ABAP program which involves some standard
function modules to pass business data to SAP Script layout. Thus,
combination of SAP Script layout and its FORM Routine together
responsible for generation of these business forms.
For e.g. – The associated FORM Routine for above mentioned SAP Script
Layout is SAPFM06P available in R/3.

This document is mainly intended to demonstrate the basic steps to


create a SAP Script Layout. Since, its associated FORM Routine is
basically an ABAP program which can be coded according to business
demand to collect desired data, however the standard function modules
needed to invoke Script layout and to pass business data will be
discussed in brief.

3. SAP Script Layout Elements

A SAP Script Layout consists of following elements –


 Pages
 Windows
 Page windows
 Paragraphs Formats
 Character Formats
Let’s discuss them in short –

Pages: Pages are general layout of script. A page would normally be


divided into three parts –
 Header
 Body
 Footer

HEADER

BODY

FOOTER

A script can consist of many pages where the first page can be in
different format and second page onwards can be in different formats.

Windows: To specify position of contents on the page, windows are


created.
WINDOWS

LOGO COMPANY NAME

CONTENT

ADDRESS

Page Windows: Page windows are used to specify sizes and to determine
position of each window.

Paragraph Formats: Paragraph formats are used for formatting


paragraphs. Font and tabs are important paragraph format. If we do not
specify font, form uses default font.

Character Formats: Character formats are basically used to override


paragraph formats for specific words in a paragraph. For e.g. if we want to
bold a specific word within a paragraph, we make use of character formats.

4. How SAP Script Processed


The SAP Script runtime environment co-ordinates the processing of SAP
Script as shown below –
As shown above the SAP Script layout environment retrieves layout and
content data from SAP Script form. Also it retrieves necessary business
data according to business logic defined in Form Routine from the R/3
database.
Thus, combining both of these, finally it generates the SAP Script form.

This generated SAP Script form can be –


 Printed
 Faxed
 E-mailed
 Displayed on terminal
as per requirement.

5. Steps to create SAP Script Layout

 Go to Transaction SE71 and give name of script you want.


 Press Create and the following pop-up will appear. Don’t forget to
see that the form is created in the client and not in the
application server.
 Just Press Enter and save the layout after giving a short
description.
 Now click on tab Pages. The following screen will appear -
 Create a page called PAGE1 and press Enter. Give next page as
PAGE1 only and press Enter.

 Now click on tab Windows. The following screen will appear –


 Apart from existing Main window, create Header and Footer for
this page.
 Now click on tab Paragraph Formats where you can create your
own paragraph formats which can be used while writing text
elements for windows. The following four paragraph formats has
been created as shown below –
The various parameters such as
o Margins
o Alignment,
o Font type
o Font size etc.
should be entered as per requirement.
 Now click on tab Page Windows and associate previously created
windows to PAGE1. This can be done by clicking on Edit from
menu bar and choosing option Create Element, where previously
created all windows will be shown up. Double click on those
windows which you want to associate with this page and
assigning following four parameters for all windows –
o Left Margin
o Upper Margin
o Window Width
o Window Height
The resulting screen will look as –
 Select Header window and click on Icon for text elements.
The shown editor can be chosen by clicking option Go to from
menu bar and selection option Change Editor. Enter desired text
as shown below –
 Now go back to previous screen, select Main window and press

Icon for text elements. Enter following texts as shown –


Note- All variable names must be enclosed in ampersands (&).
 Now go back to previous screen, select Footer window and press

Icon for text elements. Enter following texts as shown –

 Now go back & save it. Click on Header Icon , the following
screen will appear –
 Click on Basic Settings and assign First Page as PAGE1 and
Default Paragraph as P2 and save it as shown –
 Now check for Definition and Activate the script. Script Layout is
complete now.
6. Creation of Form Routine
Once Script Layout is complete, now we will create its Form Routine.
This Form Routine is an ABAP Program through which SAP Script Layout
is invoked using three function modules viz.
 OPEN_FORM
 WRITE_FORM
 CLOSE_FORM
These function modules are used in the same manner as listed above.
Out of
all these, OPEN_FORM and CLOSE_FORM are used only once while
WRITE_FORM can be used any number of times in between OPEN_FORM
and CLOSE_FORM depending on requirement. Create a report program
using transaction SE38 and copy following code snippets and activate it.

Code Snippet:

REPORT ZTESTSCRIPT_FORMROUTINE .

*-----------------------------------------------------------------------
* Database tables
*-----------------------------------------------------------------------

TABLES: kna1.

*-----------------------------------------------------------------------
* Contants
*-----------------------------------------------------------------------

CONSTANTS: co_mulgrave(8) VALUE 'MULGRAVE'.

*-----------------------------------------------------------------------
* Internal Tables
*-----------------------------------------------------------------------

DATA: BEGIN OF tb_kunnr OCCURS 0,


name1 LIKE kna1-name1,
ort01 LIKE kna1-ort01,
pstlz LIKE kna1-pstlz,
regio LIKE kna1-regio,
END OF tb_kunnr.

*-----------------------------------------------------------------------
* START OF PROCESSING
*-----------------------------------------------------------------------
START-OF-SELECTION.

* Select details of customer of Mulgrave city


SELECT name1
ort01
pstlz
regio
INTO TABLE tb_kunnr
FROM kna1
WHERE ort01 = co_mulgrave.

*-----------------------------------------------------------------------
* END OF PROCESSING
*-----------------------------------------------------------------------
END-OF-SELECTION.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
* DEVICE = 'PRINTER'
* DIALOG = 'X'
FORM = '/DCSEA/ZTESTSC'
LANGUAGE = SY-LANGU
* OPTIONS =
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
* EXCEPTIONS
* CANCELED =1
* DEVICE =2
* FORM =3
* OPTIONS =4
* UNCLOSED =5
* MAIL_OPTIONS =6
* ARCHIVE_ERROR =7
* INVALID_FAX_NUMBER =8
* MORE_PARAMS_NEEDED_IN_BATCH =9
* SPOOL_ERROR = 10
* OTHERS = 11
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT tb_kunnr.

* Write header
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT =''
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'HEADER'.
* IMPORTING
* PENDING_LINES =
* EXCEPTIONS
* ELEMENT =1
* FUNCTION =2
* TYPE =3
* UNOPENED =4
* UNSTARTED =5
* WINDOW =6
* BAD_PAGEFORMAT_FOR_PRINT =7
* SPOOL_ERROR =8
* OTHERS =9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

* Write main contents


CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'MAIN'
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'MAIN'.
* IMPORTING
* PENDING_LINES =
* EXCEPTIONS
* ELEMENT =1
* FUNCTION =2
* TYPE =3
* UNOPENED =4
* UNSTARTED =5
* WINDOW =6
* BAD_PAGEFORMAT_FOR_PRINT =7
* SPOOL_ERROR =8
* OTHERS =9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

* Write Footer
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT =''
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'FOOTER'.
* IMPORTING
* PENDING_LINES =
* EXCEPTIONS
* ELEMENT =1
* FUNCTION =2
* TYPE =3
* UNOPENED =4
* UNSTARTED =5
* WINDOW =6
* BAD_PAGEFORMAT_FOR_PRINT =7
* SPOOL_ERROR =8
* OTHERS =9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDLOOP. "LOOP AT tb_kunnr

CALL FUNCTION 'CLOSE_FORM'


* IMPORTING
* RESULT =
* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED =1
* BAD_PAGEFORMAT_FOR_PRINT =2
* SEND_ERROR =3
* SPOOL_ERROR =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.

On execution of above program, the following screen will appear –

Click on Print Preview, the output will be as shown –


7. Transporting Script Layout between clients

Since SAP Script Layout is client dependent thus layout designed in


development client can not be tested until it is transported to test client.
Thus, to transport layout from one client to another, transaction SCC1 is
used (Screen shot below).
To transport layout, mention source client, request number under which
layout is locked and click on checkbox Incl. task for request. Finally, click
on tab Start Immediately as shown below –
Function Modules Used in Script:

In the Driver we must use all or some of the function modules that are listed below to
transfer the data.

 Open_Form
 Close_Form
 Start_Form
 Write_Form
 Write_Form_Lines
 End_Form
 Control_Form
 Read_Form_elements
 Read_Form_Lines

Any driver program must contain Open_Form, Close_Form and Write_Form. Other
function modules are optional.

OPEN_FORM: This function module opens layout set printing. One must call this
function module before he uses any of other layout set function modules like
Write_Form, Start_Form, Control_Form etc., You need specify a layout set name in
the export parameters of this function module. If nothing is passed to Open_Form
then one should use Start_Form function module to open layout set before starting
the output. The layout set opened by Open_Form should be closed by Close_Form
function module, other wise output doesn’t appear. We can use any number of
Open_Form, Close_Form functions in one single program. But Close_Form must be
there for every Open_Form in the program.

Some of the important export parameters we have to pass to Open_Form


function module.

Form: Enter the Layout set name here, which then controls the output
formatting. If nothing is specified then we must use Start_Form for opening layout
set.
Language: Layout sets are Language dependent. Enter the desired language
here. If the entered layout set is not in that language, then the function tries to
open the Form entered in its original language. The default value is SY-LANGU.
Device: SAP Script can format a text on different device types. The device can
be ‘PRINTER’ or ‘TELEX’, ‘TELEFAX’, ’ABAP’ and ‘SCREEN’.
Dialog: Use parameter DIALOG to determine whether to display a dialog box
before printing, in which the user can set several spool parameters for print
formatting. Possible values: SPACE displays no print parameter screen. 'X'
display print parameter screen. Default value: 'X'
Options: Use parameter OPTIONS to set several options for print formatting.
The parameter has the structure ITCPO. The user can change some of the
defined settings on the print control screen. The default value for Options is ‘ ‘.
We will discuss about ITCPO structure in detail later.

Other Export, Import and Exceptions are self-explanatory.


Close_Form: The function module closes the layout set opened using
OPEN_FORM. The system executes any terminating processing steps for the last
opened layout set. No Export parameters for this Function Module.

Start_Form: In-between the function modules OPEN_FORM and CLOSE_FORM,


we can use different layout sets. This allows us to combine several different layout
sets into one print output. However, we can combine only those layout sets that have
the same page format. To switch layout sets, use the function module
START_FORM. If another layout set is still open, we must close it first using
END_FORM. If we specify no layout set name when calling START_FORM, the
system restarts the last open layout set. If after OPEN_FORM no layout set was
activated yet, the system leaves the function module with the exception UNUSED.
Some of the important export parameters for this function module are

Form: The parameter contains the name of the layout set you want to use for
printing. If you specify no layout set here, the system restarts the last active layout
set.

Language: Layout sets are language-dependent. Enter the desired language


here. If the layout set does not exist in this language, the system tries to call the
layout set in its original language. If the parameter LANGUAGE is empty, the
system uses the language of the last active layout set.

Startpage: Usually, SAP script starts with the page specified as start page in
the layout set definition. If we want to start output with another layout set page,
enter the name of the desired layout set page here. If the desired page is not
defined, the system uses the start page defined in the layout set.

Program: To replace program symbols, SAP script must know which active
program contains the work areas for the values to be passed. If we omit the
parameter, the system searches for the field values in the program that was
specified in the parameter OPTIONS (field TDPROGRAM) of OPEN_FORM. If we
enter a program name, the system replaces the program symbols with the values
from this program up to the next END_FORM.

Exceptions and other Export, Import parameters are self-explanatory.

Write_Form: The system outputs the layout set element specified in parameter
ELEMENT into the currently opened layout set. In the parameter WINDOW we can
specify the name of a window for the output. Remember that the layout set element
must be defined in this window. The parameter FUNCTION specifies how to merge
the text lines to be output with any existing contents in the window. In this case, there
are differences between the different window types or areas. Some of the important
export parameters used in Write_Form.
Element: Specify the name of the text element you want to output into the layout
set window specified in the parameter WINDOW. The element must be defined in
that layout set window. If you specify no element, the system uses the default
element, if one is defined in the layout set.

Window: Specify the name of the window into which you want to output the
layout set element specified in the parameter ELEMENT. Default value for
Window is ‘MAIN’.

Function: The parameter determines how to output the text element into the
respective window. The output type depends on the window type and area:

Window Type: MAIN Area: BODY


SET/APPEND: Appends to previous output.
Window Type: Main Area: Top/Bottom and
Window Type: Other than Main and all areas
SET : Delete the old element contents and prints the new elements
APPEND: Appends the new content to existing elements.

Type: The system interprets this parameter only for output to the main window.
The parameter determines the area of the main window into which we want to
output the element. Possible values: 'TOP' header area
'BODY' main area
'BOTTOM' footer area
Default value: 'BODY'

Write_Form_Lines: This function module outputs the text lines in table LINES
into the specified layout set window. The text lines must have the SAP script ITF
format. From the data in the text header, the system uses only the field
TDSTYLE to apply the formatting attributes defined in the specified style for this
text. If the field is empty, the system uses the identically named formatting
attributes (character and paragraph formats) of the layout set.
Use parameter WINDOW to specify into which of the windows defined in the
layout set we want to output the text. We can specify any window used in the
layout set. The parameter FUNCTION determines how to merge the text lines to
be output with any existing contents in the window. There are differences
between the different window types or areas.

Header: This parameter contains the header of the text module we want
to output in the current layout set. For the formatting process, the system
uses only the entries in the header fields TDSTYLE and TDFORM.
Structure: THEAD

WINDOW: Enter the name of the window into which we want to output the
layout set element specified in parameter ELEMENT. Default value:
'MAIN'
FUNCTION: This parameter determines how to output the text element
into the respective window. The output type depends on the window type
and area: Window type MAIN, area BODY: 'SET' append to previous
output 'APPEND' same as SET. DELETE' no effect. Window type
MAIN, areas TOP and BOTTOM; all other windows: 'SET' delete old
window or area contents and output the element 'APPEND'append the
element to the existing elements 'DELETE' no effect Default
value: 'SET'

TYPE: The system interprets this parameter only for output to the main
window. The parameter determines the area of the main window into
which you want to output the element. Possible values: 'TOP' header area
'BODY' main area 'BOTTOM' footer area Default value: 'BODY'

END_FORM: END_FORM ends the currently open layout set and executes the
required termination processing. After calling this function module, no more
layout set is active. For further output, we must start a new layout set using
START_FORM. No Export parameters.

CONTROL_FORM: Use this function module to pass SAP Script Control


Commands to the layout set. The Control command is passed through the export
parameter ‘COMMAND’ in quotes.

READ_FORM_ELEMENTS: This function module fills a table with all text


elements that appear in one layout set. If we specify no layout set name, the
system includes all elements of the currently open layout set. If we specify a
layout set, the system uses the information about the active version of the layout
set, retrieved from the database. Here we have two export parameters, Form and
Language and a table parameter Elements.

READ_FORM_LINES: Use this function module to transfer the lines of a layout


set element into an internal table. If we specify no layout set name, the system
transfers the text lines of the currently open layout set. If we specify a layout set,
the system uses the text lines of the active version of the layout set from the
database. The Export parameters are Form, Language, Window and Element. If
we pass these 4 parameters the function module returns a table with the lines
from layout set.
Procedure

Migrating a SAPscript form

1. Go to the SAP Smart Forms initial screen (transaction SMARTFORMS ).


2. In the Form field enter the name of the Smart Form you want to create.
3. Choose Utilities  Migrate SAPscript form.
The dialog window Migrate SAPscript Form appears.
4. Enter the name and the language of the source form (SAPscript).
5. Choose Enter.
This takes you to the change mode of the SAP Form Builder.

If the selected SAPscript form does not exist in the selected language, a dialog
window appears on which you can select one of the existing languages.

6. Now change the design of the form and of the form logic. To activate the Smart Form
choose Activate.

Converting a SAPscript style

1. Go to the Smart Styles inital screen (transaction SMARTSTYLES ).


2. In the Style name field enter the name of the Smart Style you want to create.
3. Choose Smart Styles  Convert SAPscript style.
4. Enter the name of the SAPscript style you want to convert.
5. Choose Enter.
A list of the converted styles appears.
6. Choose Back. You can now change the Smart Style (Change).To activate the Smart Style
choose Activate.

Mass Migration of SAPscript Forms

1. In Reporting select the program SF_MIGRATE and execute it.


2. Select the names and the language of the SAPscript forms and choose Execute. The
system creates the Smart Forms under the names of the SAPscript forms plus the
extension _SF.
It displays a list of the migrated forms.
3. To change and adapt a form, go to transaction SMARTFORMS . Then activate the changed
Smart Form.

Result
You created one or more Smart Forms based on the respective SAPscript form(s) and a Smart
Style based on the respective SAPscript style.
SAP SCRIPT LOGO PRINTING

To Create a logo in SAP printouts , just do the following

1. Save a Logo using Paintshop Pro or Corel Draw as Tiff file.

2. Run this program RSTXLDMC and enter the following parameters

Enter file name C:\MAIL\COMPLOGO.TIF


UOM CM
Line width for text 132
Text name ZHEX-MACRO-COMPLOGO
Text ID ST
Text language = E
Number of Tiff gray levels (2,4,9) 2

3. Then Create a new window 'COMP' with attributes;


Window COMP description Company Logo
Left margin 7.00 CH window width 10.00 CH
Upper margin LN window height 8.00 LN

Finally in the text element , mention


/: INCLUDE 'ZHEX-MACRO-COMPLOGO' OBJECT TEXT ID ST LANGUAGE
'E'.

Please note that if object name is not indicated as 'ZHEX...', the logo may not be printed!
You will not be able to see the logo in a test print. The same will be printed in actual
printout.
SAP SCRIPTS SYMBOLS

Commands
1. Defining a variable
2. Define and insert a standard text:
3. Formatting addresses
4. Avoiding pagebreaks in a paragraph
5. Conditonal text ouput IF - ENDIF

1. Defining a variable

DEFINE &CUST& = '00000021'.

2. Define and insert a standard text:

Standard texts is predifined textst that can be used in more than one form. Standard texts are can
be created, changed and displayed using transaction SO10.

The text ID is used to callsify texts.

To include a stadard text in a form, use the INCLUDE command:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD

When formatting the standard text the PARAGRAPH parameter is used. To center the text use:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD LANGUAGE EN PARAGRAPH C.

3. Formatting addresses

The ADDRESS-ENDADDRESS command formats addresses according to the postal norms of


the recipient's country, as defined in the

country parameter.

ADDRESS DELIVERY PARAGRAPH AD


NAME &KNA1-NAME&
STREET &KNA1-STRAS&

POSTCODE &KNA1-PSTLZ&
CITY &KNA1-ORT01&'
COUNTRY &KNA1-LAND1&
FROMCOUNTRY 'DE'
ENDADDRESS

4. Avoiding pagebreaks in a paragraph

/: PROTECT
:
:
/: ENDPROTECT

The text lines to be protected are enclosed between the two commands

5. Conditonal text ouput IF - ENDIF

You can use IF/ENDIF like in a normal ABAP program

/: IF condition
:
:
/: ENDIF

and

/: IF condition
:
/: ELSE
:
/: ENDIF

Example:

/: IF &SPFLI-CITYTO& = "BERLIN"
* ..... put some text here
/: ENDIF

Frames lines and shading


BOX

Draws a box

Syntax:

/: BOX <xpos> <ypos> <width> <height> <frame> <intensity>


The intensity is the grey scale of the box as %. The frame parameters is the thickness of the
frame. Default is 0.

Each of the paramteters ypos, xpos, width, height and frame muts be followed of the
measurement unit:

TW (twip)
PT (point)
IN (inch)
MM (millimeter)
CM (centimeter)
LN (line)
CH (character).
Examples:

/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY 10
FRAME 0 TW

/: BOX FRAME 10 TW
Draws a frame around the current window with a frame thickness of 10 TW (= 0.5 PT).

/: BOX INTENSITY 10
Fills the window background with shading having a gray scale of 10 %.

/: BOX HEIGHT 0 TW FRAME 10 TW


Draws a horizontal line across the complete top edge of the window.

/: BOX WIDTH 0 TW FRAME 10 TW


Draws a vertical line along the complete height of the left hand edge of the window.

/: BOX WIDTH '17.5' CM HEIGHT 1 CM FRAME 10 TW INTENSITY 15

/: BOX WIDTH '17.5' CM HEIGHT '13.5' CM FRAME 10 TW


/: BOX XPOS '10.0' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW
/: BOX XPOS '13.5' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW
Draws two rectangles and two lines to construct a table of three columns with a highlighted
heading section.

POSITION and SIZE

You can use the POSITION and SIZE commands to set default parmeters for a box. This can be
usefull if you have several boxes that share the same parameters.

Example:

/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM


/: SIZE HEIGHT '2' MM WIDTH '76' MM
/: BOX FRAME 10 TW INTENSITY 10

If you want to set the position realtively to the window use POSITION WINDOW to set the
position to the top/left start of the window. Then use POSITION to set the current position
relatively to the start of the Window. Note that
you uses "+" or "-" in the ORIGIN position to the set the position relatively.

/: POSITION WINDOW
/: POSITION XORIGIN '+5' MM YORIGIN '+10' MM

the position is now 5 MM from the left and 10 MM from the top of the window.

NOTE: After using the position command you can move the current position realtively to the last
used position

/: POSITION XORIGIN '+10' MM YORIGIN '+20' MM

Now the position will be X = 15 and Y = 30

More examples:

/: POSITION WINDOW
Sets the origin for the coordinate system to the upper left corner of the window.

/: POSITION XORIGIN 2 CM YORIGIN '2.5 CM'


Sets the origin for the coordinate system to a point 2 cm from the left edge and 2.5 cm from the
upper edge of the output page.

/: POSITION XORIGIN '-1.5' CM YORIGIN -1 CM


Shifts the origin for the coordinates 1.5 cm to the left and 1 cm up.

Drawing a line
You can draw a line by setting the Height or Width of a box to 0 and add a frame. E.g. a
horizontal line:

/: SIZE HEIGHT '0' MM WIDTH '200' MM


/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100

Window and Page

WINDOW sets the values for the width and height to the values of the current window (default
setting).

PAGE Sets the values for the width and height to the values of the current output page.
Examples:

/: SIZE WINDOW
Sets WIDTH and HEIGHT to the current window dimensions.

/: SIZE WIDTH '3.5' CM HEIGHT '7.6' CM


Sets WIDTH to 3.5 cm and HEIGHT to 7.6 cm.

/: POSITION WINDOW
/: POSITION XORIGIN -20 TW YORIGIN -20 TW
/: SIZE WIDTH +40 TW HEIGHT +40 TW
/: BOX FRAME 10 TW
A frame is added to the current window. The edges of the frame extend beyond the edges of the
window itself, so as to avoid obscuring the leading and trailing text characters.

Structure of a print program


The print program is used to print forms. The program retieves the necesary data from datbase
tables, defines the order of in which text elements are printed, chooses a form for printing and
selects an output device and print options.

* Open form printing - Must be called before working with any of the other form function
modules.
Must be ended with function module CLOSE FORM
call function 'OPEN_FORM'.....

*To begin several indentical forms containing different data within a single spool request, begin
each form using START_FORM, and end it using END_FORM

call funtion 'START_FORM'.....

* Write text elements to a window of the form


call function 'WRITE_FORM'.....

* Ends form
call funtion 'END_FORM'.....

* Closes form printing


call function 'CLOSE_FORM'....

Examples of function calls


OPEN FORM

* Structure for the OPTIONS parameter


DATA BEGIN OF OPTIONS.
INCLUDE STRUCTURE ITCPO.
DATA END OF OPTIONS.

OPTIONS-TDDEST = '*'.

OPTIONS-TDIMMED = '*'.
OPTIONS-TDDELETE = '*'.
OPTIONS-TDNEWID = 'X'.

CALL FUNCTION 'OPEN_FORM'


EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
* FORM =''
* LANGUAGE = SY-LANGU
OPTIONS = OPTIONS

* MAIL_SENDER =
* MAIL_RECIPIENT =

* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
EXCEPTIONS
CANCELED =1
DEVICE =2
FORM =3
OPTIONS =4

UNCLOSED =5
MAIL_OPTIONS =6

ARCHIVE_ERROR =7
INVALID_FAX_NUMBER =8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS = 10
.
IF sy-subrc <> 0.
...............................
ENDIF.

START_FORM

CALL FUNCTION 'START_FORM'


* EXPORTING
* ARCHIVE_INDEX =
FORM = 'MY_FORM'

* LANGUAGE =''
* STARTPAGE =''
* PROGRAM =''

* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
* EXCEPTIONS
FORM =1
FORMAT =2
UNENDED =3
UNOPENED =4
UNUSED =5
OTHERS =6

WRITE_FORM

See 'WRITE_FORM'

END_FORM

CALL FUNCTION 'END_FORM'

* IMPORTING
* RESULT =
EXCEPTIONS
* UNOPENED =1
* BAD_PAGEFORMAT_FOR_PRINT = 2

OTHERS =3

CLOSE_FORM

* Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
INCLUDE STRUCTURE ITCPP.
DATA END OF RESULT.

CALL FUNCTION 'CLOSE_FORM'


IMPORTING
RESULT = RESULT

* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED =1
* BAD_PAGEFORMAT_FOR_PRINT = 2

* SEND_ERROR =3
* OTHERS =4
.

WRITE FORM function module


The print program is used to print forms. The program retieves the necesary data from datbase
tables, defines the order of in which text elements are printed, chooses a form for printing and
selects an output device and print options.

* Open form printing - Must be called before working with any of the other form function
modules.
Must be ended with function module CLOSE FORM
call function 'OPEN_FORM'.....

*To begin several indentical forms containing different data within a single spool request, begin
each form using START_FORM, and end it using END_FORM

call funtion 'START_FORM'.....

* Write text elements to a window of the form


call function 'WRITE_FORM'.....

* Ends form
call funtion 'END_FORM'.....

* Closes form printing


call function 'CLOSE_FORM'....
Examples of function calls

OPEN FORM

* Structure for the OPTIONS parameter


DATA BEGIN OF OPTIONS.
INCLUDE STRUCTURE ITCPO.
DATA END OF OPTIONS.

OPTIONS-TDDEST = '*'.

OPTIONS-TDIMMED = '*'.
OPTIONS-TDDELETE = '*'.
OPTIONS-TDNEWID = 'X'.

CALL FUNCTION 'OPEN_FORM'


EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
* FORM =''
* LANGUAGE = SY-LANGU
OPTIONS = OPTIONS

* MAIL_SENDER =
* MAIL_RECIPIENT =

* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
EXCEPTIONS
CANCELED =1
DEVICE =2
FORM =3
OPTIONS =4

UNCLOSED =5
MAIL_OPTIONS =6

ARCHIVE_ERROR =7
INVALID_FAX_NUMBER =8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS = 10
.
IF sy-subrc <> 0.
...............................
ENDIF.

START_FORM

CALL FUNCTION 'START_FORM'


* EXPORTING
* ARCHIVE_INDEX =
FORM = 'MY_FORM'

* LANGUAGE =''
* STARTPAGE =''
* PROGRAM =''

* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
* EXCEPTIONS
FORM =1
FORMAT =2
UNENDED =3
UNOPENED =4
UNUSED =5
OTHERS =6

WRITE_FORM

See 'WRITE_FORM'

END_FORM

CALL FUNCTION 'END_FORM'

* IMPORTING
* RESULT =
EXCEPTIONS
* UNOPENED =1
* BAD_PAGEFORMAT_FOR_PRINT = 2

OTHERS =3

CLOSE_FORM
* Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
INCLUDE STRUCTURE ITCPP.
DATA END OF RESULT.

CALL FUNCTION 'CLOSE_FORM'


IMPORTING
RESULT = RESULT

* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED =1
* BAD_PAGEFORMAT_FOR_PRINT = 2

* SEND_ERROR =3
* OTHERS =4
.

CONTROL_FORM Calling Commands Using a program


The function module CONTROL_FORM can be used to create SapScript control statements from
within an ABAP program.

Example:

call function 'CONTROL_FORM'


EXPORTING
COMMAND = 'PROTECT'.

call function 'WRITE_FORM'.....................

call function 'CONTROL_FORM'


EXPORTING
COMMAND = 'ENDPROTECT'.

Boxes Lines Shading


Setting default parameters for a box:

You can use the POSITION and SIZE commands to set default parmeters for a
box.

Instead of:
/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM
INTENSITY 10 FRAME 0 TW

You can write:

/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM


/: SIZE HEIGHT '2' MM WIDTH '76' MM
/: BOX FRAME 10 TW INTENSITY 10

This can be usefull if you gave several boxes that share the same parameters

If you want to set the position realtively to the window use POSITION WINDOW

to
set the position to the top/left start of the window. Then use POSITION
to set the current position relatively to the start of the Window. Note that

you uses "+" or "-" in the ORIGIN position to the set the position
relatively.

/: POSITION WINDOW
/: POSITION XORIGIN '+5' MM YORIGIN '+10' MM

the position is now 5 MM from the left and 10 MM from the top of the window

NOTE: After using the position command you can move the current position

realtively to the

last used position

/: POSITION XORIGIN '+10' MM YORIGIN '+20' MM

Now the position will be X = 15 and Y = 30

Drawing a line. You can draw a line by setting the Height or Weidth to 0
and add a frane. E.g. a horizontal line:

/: SIZE HEIGHT '0' MM WIDTH '200' MM


/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100
Styles
Styles are used to predefine paragraph and character formats for forms. SAP provides several
standard styles e.g. for Address includes, on-line documentation and so on. You can define your
own styles.

To find styles, create styles and maintaine styles, use transaction SE72.

You assign style to a text by using menu Format -> Style

You can make temporary style changes using the control command /: STYLE

Using graphics in SapScript


Use transaction SE78 to inmport graphics to SAP.

In the form painter, you can either include directly to the form using menu Edit->Graphic-
>Create or using the INCLUDE statement in a window.

To use an INCLUDE stanment, goto into the woindow script editor and use menu Include-
>Graphic. The include can look like this for a bitmap:

/: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON

Modifications
Considerations in connection with modifications

The standard SAP print program should only be changed when it is absolutely necessary. If
additional data is needed, these can in many cases be retrieved using a a PERFORM statement in
the form instead of changing the print program..

There can be the following reasons to change the print program:

Structureal changes
New text eloements are needed
Print program to be used to print additional forms

Determine/change which forms and printprograms that are used for printing

The forms and print programs for a given output type and application can be found in table
TNAPR Processing programs for output
Use view V_TNAPR in (Transaction SE30) to change entries.

TROUBLE-SHOOTING SAP SCRIPTS:


In this section, I have explained regarding some of the errors that occur while
using the SAP Scripts with each error in each step.

STEP1: Check List of things before Trouble shooting SAP Scripts:

Following things needs to be check listed before starting the trouble shooting for the
sap scripts.

 The form and its ABAP print program are used


 We have to check out whether the SAP standard versions are used or form
or whether the driver program are modified?
 If we are using the printer to take the printouts?
 If the printer is used then check whether its device type is Standard SAP
device or whether it is defined by the user.

STEP2: If there are errors that data or field Contents are missing or the
Includes or the symbols are not Printed

In case of missing data, first of all check the data in the spool.

 If the data gets printed correctly in the spool, then there might be problem
with the printer.

 If data is not found in the spool then there can be problem with the print
program. And if it is ok with the print program then check with the form.

Step3: If the field values are not printed correctly

 If the field values are not printed correctly then debug the print program. If
the fields are not declared then SAP script will not read those fields.

Step 4: Error while reading the print program name.

 Generally the name of the print program is passed to ITCPO-TDPROGRAM


parameter of the OPEN_FORM function module. If the name is not passed
correctly then this error occurs.

Step 5: Error ‘INCLUDE is not found’.

 Include is set in the following format

/: INCLUDE <name> OBJECT <object> ID <id> LANGUAGE <l>


If those variables values are not assigned correctly, then this error occurs.

Step6: Error that text is not printed correctly’.

 This can be verified by including the sample text in the text element and
activate the form. If it prints correctly then there will problem with the include
parameters.
 If the sample text is not printed then it is problem with the text element and
it is not called from the print program.
 There will also be problem with language defined and the language used also.

Step 7: Error in fonts:

 Generally SAP Scripts uses printer font which is almost same as the form
submitted. If the printer font and the submitted form font are not matched
then this error occurs.

Step 8: Error ‘Text is not printed correctly in the desired positions’.

 First Check whether the tabs are used. If the field to be placed between the
tab positions is larger than the gap available at that particular position then
there is a possibility of the text not printed correctly in the desired positions.
 If the alignments are not given correctly then also there will be a chance for
not printing the text in the desired positions.
 Check if the standard drivers are used for printing as the standard drivers
cannot over prints the text.

Step 9: Special characters are replaced by normal characters:

 Check whether any standard SAP Device is used and whether it supports
the required character set.
 If not got to transaction SPAD and check whether the required character
set matches with the character set there.

 If not goto transaction sp01 and by using using the display function print
the character. If it prints correctly in the output controller then there
problem persists with the printer .

 If not check if there are any changes made to the page code definiton in
spool adminstration. If yes, execute the program RSTXDELL by selecting
the character set in the execution screen . Upon execution all the character
sets are deleted.

Step 10: Using the SAP Script Form Debugger

 Errors that occur in sap script can be mostly identified by using the SAP Script
debugger.
 First debugger is activated and the printer output is verified in the dialog box.
 Every function module, include and every warning are verified in the
debugger.
 To turn off the debugger, choose Debugger and press exit in the debugger
window.

6. Need for Performance Tuning for driver Programs:

Performance tuning for the driver program is essential to reduce the


processing time taken by that driver program and to make it efficient in
doping its work. An efficient driver program delivers the script output to the
user in a finite time as per the complexity of the program.

7. Queries Related to Sap scripts:


1. How to list out all sap scripts in ZH (any language)?

Sol: GO to TADIR table give OBJECT as 'FORM ' and MASTERLANG as


'ZH'. Then u will get all form names in that language.
2. How to divide the sap script main window into 99 times?

Sol: Go to SAP script (SE71) -> Page window tab -> Edit -> Main window
there a pop up appears and you can give according and you can get the
number of windows.
3. How can we download the sap scripts to our PC?

Sol: Use the program RSTXSCRP.


On execution, select the radio button ‘Form’.
In Mode give EXPORT.
Provide the Form Name in Object Name
And Save with .FRM extension.

4. What is the significance of following symbols in text element


editor.

Sol:
Syntax: &symbol(<)&
The leading sign is normally displayed to the right of a numeric value,
except in the case of a floating point number. This option enables you to
specify that the leading sign should be placed to the left of the number.

Syntax: &symbol(>)&
The default setting is to print the leading sign to the right of a numeric
value. If you used the SET SIGN LEFT control command to specify that the
leading sign should be printed in front of the value, you can override this
specification for individual symbols. The symbols specified with the >
option are then printed with the leading sign to the right.

Syntax:&symbol(Z)&
Certain symbol values are printed with leading zeros. If you want to
suppress these, use the Z option.
5. What is the procedure to display the SAP Script in different
languages?

Sol:
 Go to transaction se63.
 Translation-ABAP objects--- Other Long texts- Expand FS
forms and styles
 Select FORM Forms By double clicking on the Forms
 Provide the Object name which is nothing but the form name.
 Provide the Source Language And Target language.
 Then got to edit
 Select The Radio Button as Window Texts and Documentation.
 Open it in Change Mode.
 Change the Texts and Elements.
 Save It and activate it.

6. What is the ‘LPD’ error in sap scripts?

Sol:
 This error occurs when the text in the sub windows is not fitted in
the size of the window. In order to overcome this error the text
length inside the window is checked with the window size. This
error occurs only in the case of sub windows.

7. How to import a logo to window in sap script?

Sol: Go To ->SE78 (Graphics Administration).

On Left Panel ->Stored on document server -> Graphics -> Bitmap


Images.

On Right Window-> (Store on document server) Enter the file you want to
mention which is on your Hard disk (Say) (C:/Windows...)
Go To->Click on Import button on the left Toolbar.

Rest follows the process.

In your Script Text Editor:


Go To->Insert->Graphics->Store on Document server.
Name->Copy and Paste it from->SE78.
Sample Code for Logo how will it look after inserting the graphics logo.

/: BOX FRAME 20 TW
* P1
/: BITMAP 'LOGO' OBJECT GRAPHICS ID BMAP TYPE BCOL DPI 100

8. How to transfer the scripts?


Sol: There are 3 ways to transfer scripts. They are
a. Using program RSTXR3TR - By using the transport requests
b. Using program RSTXSCRP - It transfers the script from one server to
the other server.
c. Using transaction SCC1 - It copies the script in one client to the other
client.

9. Are the scripts Client dependent or independent?

Sol: Scripts are client dependent, because the changes done in one client
will not be reflected in to other and also scripts are stored in ITF format as
text in client dependent tables STXH and STXL.
10. Why the error “WRITE_FORM is invalid” occurs?

Sol: If the correct element name is not given while calling the function
module ‘WRITE_FORM’ then this error occurs.
11. Why we use open form, write form, close form , start form
and end form in scripts?

Sol:
OPEN_FORM: This form opens the script. The module OPEN_FORM opens
layout set printing.

WRITE_FORM: This form is used to write the content mentioned in the


windows of the SAP Script.

START_FORM: This form is dynamically call a page in the script. The


layout set can be changed in the current print procedure with
START_FORM. This may also be used to trigger a new-spool id.

END_FORM: This form is used to close the current layout set.

CLOSE_FORM: This form closes the current SAP script form.

You can have any number for WRITE_FORM, START_FORM and


END_FORM, but for a script you can have only one OPEN_FORM and
CLOSE_FORM.
12. Some standard programs and their functionalities:

Sol:
RSTXFCOM: Comparison of Two Forms
RSTXFCON SAP script: Conversion of Page Format for Forms
RSTXFCPY: Copy Forms Between Clients
RSTXFDEL: Delete and Repair
RSTXFINF: Comprehensive Information about a Specific Form
RSTXFLST: Display Forms in Two Different Clients
13. How to find all SAP scripts and their driver programs?

Sol:
 NACE T-Code is used for finding all the driver programs linked to
forms or by using the table TNAPR, we can find script form names
and their driver programs.

 Go to table TTXFP , there we can find the forms and their


corresponding print programs.

14. How to migrate Sap scripts to smart forms?

Sol:
 Go to the SAP Smart Forms initial screen (transaction
SMARTFORMS).
 In the Form field enter the name of the Smart Form you want to
create.
 Migrate SAP script form  Choose Utilities
The dialog window Migrate SAP script Form appears.
 Enter the name and the language of the source form (SAP script).
 Click Enter.
This takes you to the change mode of the SAP Form Builder.
If the selected SAP script form does not exist in the selected
language, a dialog window appears on which you can select one of
the existing languages.
 Now change the design of the form and of the form logic. To
activate the Smart Form choose Activate.
Alternate Method:
 By using the standard program ‘SF_MIGRATE’ the sap scripts
can be migrated to smart forms.

Das könnte Ihnen auch gefallen