You are on page 1of 70

SAP Scripts

Agenda

Chapter 1: Introduction
Chapter 2: Layout Set
Chapter 3: Output Program
Chapter 4: Configuration
Chapter 5: Printing
Chapter 6: SAP Script Utilities

© SAP 2008 / Page 2


Introduction
What is SAP Script ?

• SAP Script is used to print forms.

• Form Vs. Reports


• Forms look “nicer”.
• Forms can have graphic elements.
SD Inquiry PU Purchasing req.
Order confirmation Purchase order
• Forms can be
Delivery note
event-triggered.
Contract
• Examples
Invoice
Customer
of forms:
statement Goods receipt
FI IM
Checks Goods issue

WM Picking list
Packing list
Labels
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 •SAP documents are printed using forms. • Purchase order
• etc • etc
•Forms are defined and SAP Scriptusing layout sets.
formatted
•SAP script is a tool that SAP provides for creating layout sets.
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)
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
logo impact / laser printer, bar code,
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
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.
Layout Set Elements
Initial Screen

Menu:
Tools > Word processing > Layout set

• Header

• Paragraphs

• Character strings

• Windows

• Pages

• Page windows

IMG
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
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.
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.
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
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
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.
Layout Set Elements
Paragraphs

•Contains all
information needed to
format a paragraph of
text
•Font
•Tabs
Layout Set Elements
Paragraphs

•Specify tabs to create columns for line items

•If no font is specified, default font from the layout set


header will be used
Tabs

Font
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.
Layout Set Elements
Header

•Administrative info
•Default settings
•Page format: different
for different countries /
applications
•Never change ‘Lines
per inch’ &
‘Characters/inch’
Layout Set
•Menu: Utility > Test
Test Print

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
Layout Set
•Menu: Layout set >
Activating Layout Set

Activate
•Must activate the
layout set any time a
change has been made
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
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
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’.
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’&
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&
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
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
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
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.
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.
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.
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.
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.
Layout Set
Commands

• Several different text IDs can belong to one object .


• TEXT ID
0002 Sales document header note1.
0003 Sales document header note2.
Layout Set
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.
Layout Set
Logo Printing – using Standard Text
• To print a Logo, follow the steps below :

• Build 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.
Layout Set
Logo Printing – using GRAPHICS
• object
To print a logo using a GRAPHICS object (SAP
4.6B onwards)
• Build a Logo. This file can be a bit map.

• Import the logo as a GRAPHICS object using


transaction SE78 (Function key F5).

• Print this GRAPHICS object via SAPscript INCLUDE


command.
• e.g. /: INCLUDE ZHEX-IBMLOGO-BMP OBJECT GRAPHICS ID BCOL
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
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 ’.


Output Program
•CALL FUNCTIONFunction Call
‘ OPEN_FORM ’ = ..

EXPORTING FORM = ..
LANGUAGE = ..
DEVICE = ..
OPTIONS = ..
DIALOG = ..
APPLICATION = ..

IMPORTING LANGUAGE = ..
EXCEPTIONS …..
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.
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


Output Program
Function Call

• CALL FUNCTION ‘ WRITE_FORM ’


= ..

EXPORTING ELEMENT = ..
TYPE = ..
FUNCTION = ..
WINDOW = ..
EXCEPTIONS …..
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).
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
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.


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.


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


Output Program
Function Call
• CALL FUNCTION ‘ READ_TEXT ’ = ..

EXPORTING OBJECT = ..
NAME = ..
ID = ..
LANGUAGE = ..
IMPORTING HEADER = ..
TABLES LINES = ..
EXCEPTIONS …..
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
Output Program
• Possible Exceptions
Function Call
:
• 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.


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
Configuration
Output Determination

 Linking a layout set to the printing


program

 Proposing the output type for the


documents
 Output time
 Output device
 Print parameters
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
Configuration •By using the “FORM Routine” field you can indicate different
Linking Layout set to Program
“entry point” to the printing program.
•All output type can be associated with the same program /
Program Layout set layout set combination but to different “FORM Routines”.

FORM EntryA FORM EntryB FORM EntryC •Helps to consolidate logic variation in one program

Internt’l = X Interco = X internal = X

FORM Entry Open_Form

If Internt’l = X
….
elseif Interco = X

elseif Internal = X
….
Endif
Configuration
•Purchasing Menu: MM > Purchasing > Messages > Output
Linking Layout set to Program: MM
control > Output Module
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
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
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?
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
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
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
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
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)
Printing SAP Script Forms
Print Preview
•On screen display of
print preview
Printing SAP Script Forms
Collective Printing•Execute
(Send Program
time = RSNAST00
1) 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
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.
SAP Script Utilities
Upload/Download
• SAP Scripts are client-dependent objects.
Hence, they may often require to be
downloaded from or uploaded to SAP system

• Following programs can be used to download


from/upload to SAP System

• RSTXR3TR – To EXPORT/IMPORT layout set


(FORM) using a Transport Request (CTS)
SAP Script Utilities
Assignment of Standard text to CTS

• Creation of a SAP Script Standard Text does


not require a CTS

• Standard Text can be assigned to a CTS using


program RSTXTRAN

You might also like