SAP Script
Chapter 1: Introduction
Chapter 2: Printing
Chapter 3: Layout Set
Chapter 4: Output Program
Chapter 5: Configuration
Electronic Name.1 Chapter Title
Introduction
What is SAP Script ?
• SAP Script is used to print forms.
• Form Vs. Reports
Forms look “nicer”.
Forms can have graphic elements.
Forms can be event-triggered.
• Examples of forms:
SD Inquiry PU Purchasing req.
Order confirmation Purchase order
Delivery note Contract
Invoice
FI Customer statement IM Goods receipt
Checks Goods issue
WM Picking list
Packing list
Labels
Electronic Name.2 Chapter Title
Introduction
How SAP Script Works (Big Picture)
Layout set Form
SAP
SAP Read Data Print
Document
Document (Template) (Output)
• Sales order Define • Order confirmation
• Billing document • Invoice
• Purchase order • Purchase order
• etc SAP Script • etc
• SAP documents are printed using forms.
• Forms are defined and formatted using layout sets.
• SAP script is a tool that SAP provides for creating layout sets.
Electronic Name.3 Chapter Title
Introduction
Creating Report Vs. Form
Creating Reports
Output
SAP
SAP Report
Program
Document
Document (ABAP)
Creating Forms
Output
SAP
SAP Program Layout set Form
Document
Document (ABAP)
Electronic Name.4 Chapter Title
Introduction
Components of SAP Script
Output determination configuration
SAP Output Form
SAP Layout set
Document Program
Document
Printer / Font Configuration
• Output program: Extracts data from SAP data dictionary
• Layout set: Formats the extracted data
• Output determination configuration: Configures triggering event, timing / destination
• Printer / Font configuration: Configures impact / laser printer, bar code, logo
Electronic Name.5 Chapter Title
Introduction
SAP Script Development
Component Resource
Output program ABAP resource
Layout set ABAP resource
Output determination Functional resource
configuration
Printer configuration Basis / ABAP
(Impact, Thermal, Laser)
Font configuraiton Basis / ABAP
Testing End-user / Functional /
ABAP resrouce
Electronic Name.6 Chapter Title
Printing SAP Script Forms
What? Where? When? How?
• Where should it be printed?
• How many copied should be printed?
• When should it be printed?
• What medium should it be “printed” on?
• What types of status should be captured?
Electronic Name.7 Chapter Title
Printing SAP Script Forms
Output Type
• Menu: Sales order > Header > Output
• Output Type defines “when” and to
“where” to print the form.
• “When” - Communication method
• “Where” - Further data
• “How” - Medium
Electronic Name.8 Chapter Title
Printing SAP Script Forms
Output Type - “When”
• Click on “Communication method”
button
• Send time
– 1 Send with next selection run
• Batch printing using program RSNAST00
– 2 Send with time specification
• Batch printing using program RSNAST00
in the background job
– 3 Explicit request
• On demand
– 4 Immediately
• After an update
Electronic Name.9 Chapter Title
Printing SAP Script Forms
Output Type - “Where”
• Click on “Further data” button
• Printer name - Physical output
device name
• Number of messages - Number
of copies to be printed
Electronic Name.10 Chapter Title
Printing SAP Script Forms
• Output medium:
– 1 Printout
– 2 Fax
– 3 Teletex
– 4 Telex
– 6 EDI
– 7 SAP Office
– 8 Special function
– 9 Workflow events
– A Distribution (ALE)
– T Workflow: Task
• Processing status:
– 0 Not processed
– 1 Successfully processed
– 2 Incorrectly processed
– 3 Not active
Electronic Name.11 Chapter Title
Printing SAP Script Forms
Screen Vs. Printer
• Menu: Issue Output To > Screen
– Works with all timing as
long as there exists an
output type
– Ignores the output device
specification
– Best for debugging
• Menu: Issue Output To > Printer
– Works only if Send time = 3
(On demand)
Electronic Name.12 Chapter Title
Printing SAP Script Forms
Print Preview
• On screen display of print
preview
Electronic Name.13 Chapter Title
Printing SAP Script Forms
Collective Printing (Send time = 1)
Execute Program RSNAST00 using
Transaction SA38. Transaction OVNN.
• Can define and use variants.
• Only the output types with timing = 1
will be detected
• Only the output type with status = 0
will be detected unless Send Again
field is checked
• Object key = Document number
Electronic Name.14 Chapter Title
Printing SAP Script Forms
Repeating Output
1. Enter the document in
change mode.
2. Select an output type that has
already been successfully
processed (Status = 1).
3. Click on “Repeat output”
button.
4. Select the new entry. (Status
= 0) and change any data if
necessary
5. Trigger printing as before.
Electronic Name.15 Chapter Title
Layout Set
Some Facts
Client specific (client-dependent)
Language specific
• Note: If the layout set is not
available in the client in which the
document is being printed, then
the SAPscript checks for the style
or layout set in client 000.
• Recommendation: Keep only one
copy of the layout set in one client.
Electronic Name.16 Chapter Title
Layout Set Elements
Initial Screen
Menu:
Tools > Word processing > Layout set
• Header
• Paragraphs
• Character strings
• Windows
• Pages
• Page windows
IMG
Electronic Name.17 Chapter Title
Layout Set Elements
Components
S.O. # S.O. #
P.O. # P.O. #
Date Date
Sold-to Ship-to Item Material # Price
40 Part D $250
50 Part E $400
Item Material # Price 60 Part F $350
70 Part G $150
10 Part A $500
20 Part B $350
30 Part C $800 Total $2,800
• Header: General info and default settings
• Paragraphs: Font and tab info
• Character strings: Font info within a paragraph
• Windows: Description of areas on the pages
• Pages: Name of the pages with page flow info
• Page windows: Position and size of the windows on the pages
Electronic Name.18 Chapter Title
Layout Set Elements
Page Windows
• List of all the windows on the
page with coordinates.
• The coordinates are given by
the upper left-hand corner and
the width and length.
• Note: A window which should
appear on a page must first be
defined under ”Windows” and
then be added to the page
windows.
Electronic Name.19 Chapter Title
Layout Set Elements
Windows
• Type of windows:
– Main - Special
– VAR - Variable
– CONST - Constant
• Shows list of all windows
defined for the layout set.
• A window can contain hard-
coded texts and the variables to
be printed in the window.
Electronic Name.20 Chapter Title
Layout Set Elements
Windows - Text element
• A window can contain hard-
coded texts and the variables
to be printed in the window.
• Tag column: Specifies format
of the text
• Text line column: Contains the
actual content of the window.
• Special characters
– * Default paragraph
– /: Command line
– /* Comment line
– /E Text element
Electronic Name.21 Chapter Title
Layout Set Elements
Windows - Text element
• Text element always starts
with the line /E and continues
to the next text element (/E).
• It is the output program (not
the layout set) that controls
whether or not to print a text
element (I.e. block of texts
surrounded by /E) and the
order in which they are
printed.
• ‘,,’ Tabs in a paragraph
• ‘&&’ Variables
Electronic Name.22 Chapter Title
Layout Set Elements
Pages
• Shows the page flow
information.
• Must define at least two pages.
• The first page specifies the
next page.
• The last page recursively
defines the next page as itself.
Electronic Name.23 Chapter Title
Layout Set Elements
Paragraphs
• Contains all information
needed to format a paragraph
of text
• Font
• Tabs
Electronic Name.24 Chapter Title
Layout Set Elements
Paragraphs
Tabs • Specify tabs to create columns
for line items
• If no font is specified, default
Font
font from the layout set header
will be used
Electronic Name.25 Chapter Title
Layout Set Elements
Character Strings
• A default character style is
specified at the paragraph
level.
• Can be used within paragraph
to override the default settings
for a few words within the
paragraph.
Electronic Name.26 Chapter Title
Layout Set Elements
Header
• Administrative info
• Default settings
• Page format: different for
different countries /
applications
• Never change ‘Lines per inch’
& ‘Characters/inch’
Electronic Name.27 Chapter Title
Layout Set
Test Print
• Menu: Utility > Test print
• Shows the layout design of the
layout set.
• Test printing does not trigger
the output program to
interface with the layout set.
• It simply shows the maximum
length of each of the fields
being printed.
Electronic Name.28 Chapter Title
Layout Set
Activating Layout Set
• Menu: Layout set > Activate
• Must activate the layout set
any time a change has been
made
Electronic Name.29 Chapter Title
Layout Set
Symbol
• Symbols are placeholders for values during print
formatting.
• Symbols are identified by a name which is included in
‘&’ characters. Example : &VBAK-VBELN&. Symbols
are case sensitive.
• Depending on the source, the value of a symbol
comes from, they can be categorized as follows:
• SYSTEM symbols
• PROGRAM symbols
• STANDARD symbols
• TEXT symbols
Electronic Name.30 Chapter Title
Layout Set
Symbol
• SYSTEM symbols are supplied by SAPscripts. They can
be used in all texts. Following are list of frequently used
system symbols.
&DATE& = Current date
&DAY& = Day
&MONTH& = Month
&YEAR& = Year
&TIME& = Time of day
&HOURS& = Hours
&MINUTES& = Minutes
&SECONDS& = Seconds
&PAGE& = Page
&NEXTPAGE& = Page number of next page
&SPACE& = Blanks
&ULINE&= Underline
&VLINE& = Vertical line
&NAME_OF_MONTH& = Name of month
Electronic Name.31 Chapter Title
Layout Set
Symbol
• PROGRAM symbols are placeholders for values which
come from the program that calls the layout set. The
symbol has to be defined in the Data Dictionary and
filled with values by the output program.
• Example: &KNA1-NAME1& in the layout set will output the Customer’s
name.
• STANDARD symbol are maintained centrally in one
table (TTDTG) for all SAPscript users.
• Values of TEXT symbol are created by assignment via
DEFINE statement.
Example : /: DEFINE &CASENUM& = ‘1234’.
Electronic Name.32 Chapter Title
Layout Set
Symbol
• FORMATTING of the symbol can be done in following
different ways:
&SYMBOL+ 4& = Off set
&SYMBOL(5)& = Length
&SYMBOL(I)& = If the symbol is initial, output nothing
&SYMBOL(Z)& = Suppress leading zeros
&SYMBOL(C)& = Compress blanks
&SYMBOL(R)& = Right-justified output
&SYMBOL(S)& = Suppress +/- sign
&SYMBOL(5,2)& = Decimal place formatting
&SYMBOL(E3)& = Exponential notation
&’text1’SYMBOL’text2’& = Concatenation of symbol and text
Examples :
&VBDPR-MATNR+2(4)&
&VBDKL-BRGEW(I13)&
&’Currency : ’VBDKA-WAERK&
&’Case # &PREFIX&’VBDPR-BSTNK+2(8)’00’&
Electronic Name.33 Chapter Title
Layout Set
Commands
• IF..ELSE..ENDIF can be used within the layout set to
control the flow of logic.
Example :
/: IF &VBRK-VKORG(2)& EQ ‘HG’.
/: DEFINE &PREFIX& = ‘Mr.’.
/: ELSE.
/: DEFINE &PREFIX& = ‘Mrs.’.
/: ENDIF.
.
/ &PREFIX&
Electronic Name.34 Chapter Title
Layout Set
Commands
• CASE ..ENDCASE command can also be used in the
layout set to control the flow of logic.
Example :
/: CASE &VBDKL-VKORG(2)&
/: WHEN ‘HG’
/ Case # &‘934’VBDPL-SORTKRI&
/: WHEN OTHERS
/ Case # &‘999’VBDPL-SORTKRI&
/: ENDCASE
Electronic Name.35 Chapter Title
Layout Set
Commands
• Using the command NEW-PAGE, a page -break can be
made in SAPscript at any position before the end of the
page defined in the layout set. The next page can be
specified explicitly.
Syntax: /: NEW-PAGE [PAGE]
• A page break within a paragraph can be prevented by
using this command PROTECT..ENDPROTECT.
Syntax :
/: PROTECT
text text text
/: ENDPROTECT
Electronic Name.36 Chapter Title
Layout Set
Commands
• The command ADDRESS…ENDADDRES formats an
address according to the postal standards of the
country of destination which is defined in the parameter
COUNTRY.
Syntax :
/: ADDRESS DELIVERY PARAGRAPH paragraph
[ PRIORITY prio LINES lines ]
/: TITLE form of address
/: NAME name1[, name2[, name3[,name4]]]
/: STREET strno
/: POBOX pobox [CODE code]
/: POSTCODE postal code
/: CITY city1[,city2]
/: REGION district
/: COUNTRY recipient country
/: FORMCOUNTRY sender country
/: ENDADDRESS
Electronic Name.37 Chapter Title
Layout Set
Commands
• Parameter PRIORITY defines which address lines may be
omitted, if necessary. The possible values are as follows :
A Form of address
B Mandatory blank line 1
C Mandatory blank line 2
2 Name2
3 Name3
4 Name4
L Country name
S Street line
O City line
• The parameter LINES are available for formatting the
address. Possible values are from 1 to n. If it is not
possible to format all address data due to a lack of lines,
the data which is entered in the parameter PRIORITY is
omitted.
Electronic Name.38 Chapter Title
Layout Set
Commands
• The date can be formatted using the command SET DATE
MASK = ‘…’. After formatting all date fields are output as
specified. The available formats for day, month and year
are following.
DD Day
MM Month in figures
MMMM Month in words
YY Year (2 digits)
YYYY Year (4 digits)
Example : /: SET DATE MASK = ‘MM/DD/YYYY’
• The formatting can be reset at any point of time by
/: SET DATE MASK = ‘’. Formatting is then carried out as
defined by the System.
Electronic Name.39 Chapter Title
Layout Set
Commands
• The time can be formatted using the command SET
TIME MASK = ‘…’. After formatting all time fields are
output as specified. The available formats for hours,
minutes and seconds are following.
HH Hours
MM Minutes
SS Seconds
Example /: SET TIME MASK = ‘HH:MM:SS’
• The formatting can be reset at any point of time by
/: SET TIME MASK = ‘’. Formatting is then carried out
as defined by the System.
Electronic Name.40 Chapter Title
Layout Set
Commands
• In SAPscript, any text can be included at a certain
position in the document using INCLUDE command.
Syntax :
INCLUDE name OBJECT object ID identifier PARAGRAPH paragraph
LANGUAGE language
Example :
INCLUDE &VBDPL-TDNAME& OBJECT VBBP ID 0001 PARAGRAPH IT
INCLUDE ‘SD_TEXT’ OBJECT TEXT ID SDVD PARAGRAPH HT
• There are two different types of text handled in SAPscript. One is APPLICATION
TEXT and other one is STANDARD TEXT.
Electronic Name.41 Chapter Title
Layout Set
Commands
• The ‘name’ in the include command is always the document no for APPLICATION
TEXT and the name of standard text for STANDARD TEXT.
• Example : vbdka-tdname, vbdkl-tdname, vbdkr-tdname.
• The text ‘object’ specifies the environment to which a text belongs.
TEXT NAME TEXT ORIGIN
VBBK Sales document Header Text
KNVV Customer Master SD Text
VBKA Contacts General Text
VTTK Shipment Header Text
The ‘object’ is always ‘TEXT’ for STANDARD TEXT.
Electronic Name.42 Chapter Title
Layout Set
Commands
• Several different text IDs can belong to one object .
• TEXT ID
0002 Sales document header note1.
0003 Sales document header note2.
Electronic Name.43 Chapter Title
Output Program
Overview
• Program retrieves the data to be printed in a Layout set.
• Structure of Programs
Stand alone .
Transaction Triggered.
• Communication in between program and layout set is done via
execution of function calls and communication structures.
• Execution sequence of function calls
• A layout set must be opened before being able to output data.
• Data can be transfer as often as required.
• At end layout set has to be closed.
Electronic Name.44 Chapter Title
Output Program
Function Call
• General Function calls
• CALL FUNCTION ‘ OPEN_FORM ’.
• CALL FUNCTION ‘ WRITE_FORM ’.
• CALL FUNCTION ‘ CLOSE_FORM ’.
• CALL FUNCTION ‘ CONTROL_FORM ’.
• CALL FUNCTION ‘ READ_TEXT ’.
Electronic Name.45 Chapter Title
Output Program
Function Call
• CALL FUNCTION ‘ OPEN_FORM ’ = ..
EXPORTING FORM = ..
LANGUAGE = ..
DEVICE = ..
OPTIONS = ..
DIALOG = ..
APPLICATION = ..
IMPORTING LANGUAGE = ..
EXCEPTIONS …..
Electronic Name.46 Chapter Title
Output Program
Function Call
• OPEN_FORM opens layout set for
Printing .
• Parameters
• LANGUAGE defines the layout set
language version .
• DEVICE specifies the output
device type .
( Example : PRINTER, SCREEN,
TELEX, TELEFAX)
• OPTIONS can be used to specify
the print preview.
• DIALOG can request a pop-up
screen on which user can enter
spool information such as printer
name.
Electronic Name.47 Chapter Title
Output Program
Function Call
• Possible Exceptions :
• DEVICE = Device type invalid
• FORM = Layout set does not exist
• OPTIONS = Options invalid
• UNCLOSED = A layout set is still active
Electronic Name.48 Chapter Title
Output Program
Function Call
• CALL FUNCTION ‘ WRITE_FORM ’ = ..
EXPORTING ELEMENT = ..
TYPE = ..
FUNCTION = ..
WINDOW = ..
EXCEPTIONS …..
Electronic Name.49 Chapter Title
Output Program
Function Call
• WRITE_FORM transfer the data to
layout.
• Parameters
• Explicitly specify ELEMENT and
WINDOW name to output data
from a specific ELEMENT.
• No specification of WINDOW name
is necessary for MAIN window.
• TYPE defines area of the MAIN
window, where data need to
written. Possible values :
• TOP = MAIN window header.
• BOTTOM = MAIN window footer.
• BODY = MAIN window normal
output area (Default).
Electronic Name.50 Chapter Title
Output Program
Function Call
• FUNCTION defines how the data specified in the text
element is to be written in the respective WINDOW.
• MAIN window
• SET = Append to preceding output.
• APPEND = Identical with SET.
• DELETE = Ineffective.
• OTHER window
• SET = Delete old contents and output new text.
• APPEND = Append to preceding output.
• DELETE = Delete the specified text element.
• Default is SET
Electronic Name.51 Chapter Title
Output Program
Function Call
• Possible Exceptions :
• ELEMENT = Text does not exist.
• FUNCTION = Function is invalid.
• TYPE = Window area is invalid.
• WINDOW = Window does not exist.
• UNOPENED = Layout set printing not opened.
Electronic Name.52 Chapter Title
Output Program
Function Call
• CALL FUNCTION ‘ CLOSE_FORM ’ = ..
EXPORTING RESULT = ..
EXCEPTIONS…..
• Layout set opened with function
‘OPEN_FORM’ is closed.
• Layout set must be closed before
being able to output the data on
the screen or printer.
• Possible exceptions :
• UNOPENED = No open layout set.
Electronic Name.53 Chapter Title
Output Program
Function Call
• CALL FUNCTION ‘ CONTROL_FORM ’ = ..
EXPORTING COMMAND = ..
EXCEPTIONS…..
• ‘CONTROL_FORM’ can execute SAPscript
control commands.
• Example : PROTECT … ENDPROTECT.
• Parameter COMMAND accept the SAPscript
command.
• Possible exceptions :
• UNOPENED = Layout set printing has not
been opened.
• UNSTARTED = No layout set opened
Electronic Name.54 Chapter Title
Output Program
Function Call
• CALL FUNCTION ‘ READ_TEXT ’ = ..
EXPORTING OBJECT = ..
NAME = ..
ID = ..
LANGUAGE = ..
IMPORTING HEADER = ..
TABLES LINES = ..
EXCEPTIONS …..
Electronic Name.55 Chapter Title
Output Program
Function Call
• An application text can be read
from text file. HEADER and
LINES contain header and text
information after successful
execution.
• Work area for header must be
defined as a field string.
DATA BEGIN OF HEADER
INCLUDE STRUCTURE THEAD
DATA END OF HEADER
• Work area for text lines must
be defined as an internal table.
DATA BEGIN OF LINES OCCURS ...
INCLUDE STRUCTURE TLINE
DATA END OF HEADER
Electronic Name.56 Chapter Title
Output Program
Function Call
• Possible Exceptions :
• ID = Text ID invalid.
• LANGUAGE = Language invalid.
• NAME = Text name invalid.
• NOT_FOUND = Text not found.
• OBJECT = Text object invalid.
• REFERENCE_CHECK = Reference sequence interrupted.
Electronic Name.57 Chapter Title
Output Program
Function Call
• Document ( e.g. Sales Order )
generation programs can also be
triggered via business transaction.
• Sources of data :
Document Header Item
SO VDBKA VBDPA
Delivery Note VDBKL VBDPL
Picking VDLKK VBLKP
Invoice VDBKR VBDPR
Purchase Order EKKO EKPO
Payment REGUH REGUP
Electronic Name.58 Chapter Title
Configuration
Output Determination
Linking a layout set to the printing
program
Proposing the output type for the
documents
Output time
Output device
Print parameters
Electronic Name.59 Chapter Title
Configuration
Linking Layout set to Program: SD Module
• SD Menu: SD > Basic functions >
Output > Output determination >
Process output and forms > Assign
forms and programs > Allocate to
sales documents
• Output type / Medium determines
– Printing program
– Layout set
– Form routine
• Good screen to check initially to see
which programs and the layout sets
the standard system uses to print
standard forms
Electronic Name.60 Chapter Title
Configuration
Linking Layout set to Program
Program Layout set
FORM EntryA FORM EntryB FORM EntryC • By using the “FORM Routine”
field you can indicate different
Internt’l = X Interco = X internal = X “entry point” to the printing
program.
• All output type can be
FORM Entry Open_Form associated with the same
program / layout set combination
but to different “FORM
If Internt’l = X Routines”.
….
elseif Interco = X
… • Helps to consolidate logic
elseif Internal = X
….
variation in one program
Endif
Electronic Name.61 Chapter Title
Configuration
Linking Layout set to Program: MM Module
• Purchasing Menu: MM > Purchasing
> Messages > Output control >
Output control > Define output
control for the purchase order
• Inventory Management Menu: MM >
IM > Output determination > Assign
layout sets and programs
• Warehouse Management Menu: MM >
WM > Activities > Define print control
Electronic Name.62 Chapter Title
Configuration
Linking Layout set to Program: FI Module
• Finance Menu: FI > AR & AP >
Customer (Vendor) accounts > Line
items > Correspondence > Carry out
check or correspondence settings
>Define form names for printing
correspondence
• Check Printing Menu: FI > AR & AP >
Business transaction > Outgoing
payments > Automatic outgoing
payments > Payment method / Bank
selection > Configure payment program
> Payment method > In company code
> “Double click on the country” >
“Double click on check” > Environment
> Form data
Electronic Name.63 Chapter Title
Barcode Printing
• To print barcode , follow the steps below :
• Select / Create a barcode font in SAP.
• Create a character string and include the barcode with it.
• The data need to printed as barcode should be attributed
via the character string.
• e.g. / <BC> * &VBAKA-WERKS& * </>
Electronic Name.64 Chapter Title
Logo Printing
• To print a Logo, follow the steps below :
• Built a Logo. This file can be a bit map or windows meta
file.
• Convert the Logo to a TIFF ( extension TIF ) file.
• Use program RSTXLDMC to convert the TIF file to a
standard text.
• Print this standard text via SAPscript INCLUDE command.
• e.g. /: INCLUDE ZHEX-IBMLOGO-PCL OBJECT TEXT ID ST
Electronic Name.65 Chapter Title