15 Sap Script
15 Sap Script
Sap Script
INTRODUCTION
Note:
Entering and formatting text in SAP script is a little bit different than
traditional text-processing programs on a PC.
The main difference: the text that you enter is not in its final format.
SAP script applies your formatting to text only when a document
is printed, print-previewed, or displayed on-line in the SAP System
Sap Script
How does a SAP Script work ?
In case you are creating an entirely new script ,you also need to create
the driver program.
1. Standard Text
This is like a normal document.You can create letters , articles bascially
any static text.
This can be created from transaction SO10.
2. Layout Set
This also called as Form created from Transaction SE71.
3. Print Program
This program retrieves desired data from the database , calls the Form,
supplies data to the Form and finally closes the Layout Set ( Form ).
Sap Script
Supplies
data
Driver Program Layout set Gets printed
Defines
Forms
Sap
Script
Sap Script
Name WINDOW
House name
Postal Code
City
Name
House name
Postal Code
City Page window
Particular area in the
page where the window
is printed out
Page
Standard Text
Transaction SO10
Standard Text
• Header
• Pages
• Page Windows
Header
Header data is found both in style and layout set maintenance. In style
maintenance, it is used primarily to present information designed to make
it easier for the end user to select a style.
The header data in layout set maintenance, on the other hand, is used for
information and control purposes.
Header
• Standard
• Font
• Tabs
• Outline
Paragraph
Paragraph Format
Character Format
Character formats
• Allow you to format entire blocks of text within a paragraph
WINDOWS
• To refer a window via program each window must have a unique name
• We can assign text to each windows via text elements
TEXT ELEMENTS
Text elements can be defined in layout set maintenance for each window.
The text elements are accessed by name by a print program, formatted,
and output in the respective window. The /E in the tag column is used to
identify the text as a text element
Windows
WINDOWS
Windows
MAIN
Main window in which continuous text is output. The text in the main
window can extend over several pages. If the text fills one page, output
continues in the window of the next and subsequent pages, as long
as MAIN has been defined for these pages.
VAR
Window with variable contents. The text can vary on each page in
which the window is positioned. Variable windows are formatted for
each page.
CONST
Window with constant contents which is only formatted once.
Pages
At least one page must be defined for every layout set. You must also
designate a "first" page in the layout set header. Otherwise text
formatting is not possible.
Pages
PAGES
Page Windows
When you define page windows, the window names are linked to page
names. To do this, you need to specify the position and size of the
window on the assigned page.
PAGE WINDOWS
Sap Script
COMPONENTS OF SCRIPT
• Text Elements
• Style
• Layout set
Text Elements
The text elements are related to a window .
The print program calls the respective text elements of the window
• To out put named text elements we have to call the function module
WRITE_FORM
Style
A style defines the set of paragraph and character formats that are
available for formatting a document.
• Layout sets are used to control the page layout and also the text
formatting in your documents.
SYMBOLS
Symbols are constants that can be inserted in a document. They save the
user unnecessary work when replacing sections of text, phrases, etc.
Possible symbol types are:
• System symbols
• Standard symbols
• Program symbols
• Text symbols.
Symbols
THE SYNTAX OF SYMBOLS
• The delimiter & must be used both immediately before and after the
symbol.
• A SAP Script editor line break should not occur between the symbol
delimiters.
SYSTEM SYMBOLS
STANDARD SYMBOLS
PROGRAM SYMBOL
SAP Script cannot read this data out of the SAP database itself, but has to
call on another program to do this. The data are then copied into work
areas declared using TABLES. If SAP Script is now called from this
program in order to format a text, it can copy the data out of these work
areas.
Symbols which obtain their values from this kind of data area are called
program symbols.
Note
• The value of a program symbol is limited up to a maximum of 255 chars.
• The name of a program symbol consists of the table name and the field
name separated by a hyphen.
Symbols
TEXT SYMBOLS
All symbols which do not correspond to one of the three types of symbol
described above are text symbols. You define the value of a text symbol
yourself in the text module.
for e.g
/: DEFINE &mysymbol& = ‘XXXX’
/ &mysymbol&
/: DEFINE &mysymbol& = ‘YYYY’
/ &mysymbol&
/: NEW-PAGE
/: RESET paragraph_format
/: TOP
:
/: ENDTOP
/: BOTTOM
:
/: ENDBOTTOM
/: IF condition
:
/: ENDIF
Control Commands
SET DATE MASK command
The formatting for date fields can be defined with the SAPscript SET
DATE MASK command. Executing this command causes all
subsequent date fields to be output using the specified formatting.
Syntax
/: SET DATE MASK = 'date_mask'
You can use the SAPscript SET TIME MASK command to format time
fields in a way that differs from the standard setting. Executing this
command causes all subsequent time fields to be output using the
specified formatting.
Syntax:
/: SET TIME MASK = 'time_mask'
The BOX, POSITION and SIZE commands for drawing boxes, lines and
shadowing can be used for specifying that within a layout set particular
windows or passages of text within a window are to be output in a frame
or with shadowing.
Syntax
1. /: BOX [XPOS] [YPOS] [WIDTH] [HEIGHT] [FRAME] [INTENSITY]
2. /: POSITION [XORIGIN] [YORIGIN] [WINDOW] [PAGE]
3. /: SIZE [WIDTH] [HEIGHT] [WINDOW] [PAGE]
.
Control Commands
ADDRESS
BOTTOM /ENDBOTTOM
/:BOTTOM
The text lines between the two commands are output at the bottom of
MAIN window
/:ENDBOTTOM
REPORT ZSCRIPT .
TABLES: SPFLI.
DATA: I_SPFLI LIKE SPFLI OCCURS 0 WITH HEADER LINE.
SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE
I_SPFLI.
LOOP AT I_SPFLI.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'LINE_ITEM'
* FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'.
ENDLOOP.
CALL FUNCTION 'CLOSE_FORM'.
Example of Print Program
Pages
Example
Windows
Example
Page Windows
Example
Output Length
&symbol(3)& ----> 123
&symbol(7)& ----> 1234567
Time Mask
&Time&
Normally 10:08:12
(hh) : (mm): (ss)
Fill Character
Leading spaces in a value can be replaced with a fill character.
The ‘F’ option is used and character to be filled is specified.
E.g &KNA1-UMSAT& = 700.00
&KNA1-UMSAT(F*)& = **700.00
Space Compression
&symbol(C)&
It has a effect of replacing each string of space characters with a single space and
shifting the words to left as necessary to close up gaps.
Also Leading spaces are completely removed.