Understanding SAP Scripts and Layout Sets
Understanding SAP Scripts and Layout Sets
Page
SAP Scripts
SAP Script
SAP Script is SAP’s word processing tool for generating the Business Documents which are
frequently used in Manufacturing sectors, Service Sector and Trading sectors. Some of the business
Documents are Sales Order, Invoice, Purchase Order, Purchase Requisition etc.
Often there are instances where an output from a SAP program is required on a physical paper in a
pre-designed format. Using normal ABAP code this is not possible. Instead SAP provides an object
called SAPSCRIPTS to generate such kind of documents which can contain logos, tables and other
objects, which can look like pre-printed documents.
A layout set is a template designed in SAP to place the stream of data coming from a SAP program
on different parts of a physical page. The designer needs to lay out the various elements that need
to be printed on the page and store it as an object in the SAP system. An ABAP program will
subsequently call this object to generate an instance of the template – thus generating an output
document from the program.
Some Facts
Client specific (client-dependent)
Language specific
Can be translated using the standard SAP translation tools
If the layout set is not available in the client in which the document is being printed,
then the SAP script checks for the style or layout set in client 000.
Recommendation: Keep only one copy of the layout set in client 000
Table TNAPR contains all the script form name and print program name.
Language
Language is which the data coming on to the layout set will be printed. Generally, this will be the
language that has been set up as default in the SAP system.
There are 6 components of the layout set
Page
SAP Scripts
Header: Section to define the various attributes of the layout set on a global level. Changing these
attributes will affect all the components of the lay out set.
The various components of the header are explained below.
Administrative Data: This shows the information about the layout set – details of the
designer, details of the changes occurring to the design, development class of the layout set
and the language details for the layout set. Also it contains the Description – Brief
description or title of the layout set.
Basic Settings: This contains all standard information as explained below.
1. Default Paragraph: The base paragraph that is globally applicable to the
document. This can be overridden at lower level of the layout set by using other
paragraph.
2. Tab Stop: The base tab-stop that is globally applicable to the document. This can
be overridden at lower level of the layout set by using other tab stops.
3. First Page: The start of the page of the layout set.
4. Page Format
5. Orientation: The direction of the printing the data on a page – P for portrait
(Vertical) and L for landscape (Horizontal).
6. Lines per inch
7. Character per inch
8. Font Attribute
Paragraphs: Used to define the start and end positions for the different texts and objects that need
to be printed on the output document.
Character strings: Used to define the font and formatting and printing styles for each and every
character that needs to be printed on the output document. The start of the character string is
indicated by <String name>, while the end of the character string is indicated by </>
Windows: Various parts of the output document can be conveniently organized on the pages using
windows. Thus the data stream coming from the ABAP program can be logically grouped into
various parts and can be placed on different location on a page.
There are 3 types of windows that can be used in a layout set.
MAIN: A layout set can have only one MAIN window which is created by default. This
window can flow over multiple pages. The MAIN window range can be from 00 to 98 i.e.
MAIN00, MAIN01…
VARIABLE: A layout set can have any number of VARIABLE windows. A VARIABLE window
can be used once per page.
CONSTANT: CONSTANT window works same way as VARIABLE window works.
Note: Maximum of 99 windows can be placed in a PAGE. MAIN window is the default window and a
SAP Script is not possible without a MAIN window.
Pages: Name of the pages with page flow info
Text Element: Any text that needs to be written on the output document should be placed within a
text element. This includes constant text as well as variable data like internal table data coming
from ABAP program.
The Text Elements are used to identify the block of statement from the Page Window, so that
instead of executing all the statement all the time we can specify when to execute particular set of
Page
SAP Scripts
statements in the page window by passing element name along with window name in
WRITE_FORM of the driver program.
All text element start with /E tag.
Note: Text Element is simply the name given to group of statements in the page window.
Text Element 4
Created by Iman Sen
Note: It is advisable to group logically related data within one text element.
Page windows: Position and size of the windows on the pages. All the windows that form a page of
the layout set. Choose the window and click the Text Elements button to go to the layout set editor.
These consist of 2 parts.
The small space on the left is for specifying the type of command, while the window adjacent to it is
for writing the command or the text that needs to go under a text element.
Various types of commands that can be used within a layout set are tabulated below.
Command Purpose
* Default paragraph
Blank Continuous text
= Extended
( Raw Line
/ Line Feed
/= Line Feed and Extended Line
/( Line Feed and Raw Line
/: Command Line
/* Comment Line
/E Text Element
<PN> This is the name of the paragraph that should be applicable
Page
SAP Scripts
Page
SAP Scripts
Program Symbols: 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 Symbols: STANDARD symbol are maintained centrally in one table (TTDTG) for all
SAPscript users. This table contains both the name of each symbol and its value. The value, which is
language dependent, can contain up to 60 characters. SAP supplies this table filled with standard
entries. We can extend it with customer specific symbols. We can use standard symbols in all kinds
of text.
Text Symbols: All symbols that do not correspond to one of the three types of symbol described
above are text symbols. Values of TEXT symbol are created by assignment via DEFINE statement.
Example: /: DEFINE&CASENUM& = ‘1234’.
SAPSCRIPT: General SAPscript Fields:
You can print the following fields of structure SAPSCRIPT as program symbols in SAPscript forms:
Page
SAP Scripts
&SAPSCRIPT-SUBRC&:
Receives a value after executing an INCLUDE statement. The value shows whether the INCLUDE
was found (that is, the INCLUDE text exists) or not. You can query this value in an IF statement.
INCLUDE was found: &SAPSCRIPT-SUBRC& = 0
INCLUDE was not found: &SAPSCRIPT-SUBRC& = 4
&SAPSCRIPT-DRIVER&:
SAPscript formats a text for a specific output device. The initial formatting is independent of the
specific language of this device. SAPscript then calls a driver to convert the device-independent
format to device-specific control commands. This field contains the name of the driver.
&SAPSCRIPT-FORMPAGES&:
This field contains a number representing the total number of pages of the currently formatted
form (any output between START_FORM and END_FORM). The page counter mode (START, INC,
HOLD) of the individual pages is ignored. You can use this symbol to formulate information such as:
"Page x of y" for your output.
You cannot display the &SAPSCRIPT-FORMPAGES& value in a bar code. Do not use &SAPSCRIPT-
FORMPAGES& in a control command. The symbol is replaced once the entire form has been
processed (as only then is the total number of pages fixed). However, a control command is
processed immediately by the composer, which means that the value "zero" is displayed. This also
applies to the symbol &SAPSCRIPT-JOBPAGES&.
&SAPSCRIPT-JOBPAGES&:
This field contains a number representing the total number of pages of all forms contained in the
currently formatted print request, in other words, of all forms created using the OPEN_FORM,
START_FORM .. ENDFORM, START_FORM .. END_FORM, ..., CLOSE_FORM function modules.
When you use the SAPSCRIPT-FORMPAGES or SAPSCRIPT-JOBPAGES symbols, SAPscript leads all
output pages of the current form or current print request into main memory to replace the symbol
by the appropriate value. For large output jobs, this can mean a very large amount of memory.
&SAPSCRIPT-COUNTER_x& (x = 0 .. 9):
These fields represent ten counter variables that you can use in your text and forms for any
counting purposes. You can use the "+" and "- " formatting options to increment or decrement a
counter before its value is printed. You can use the DEFINE control command to assign any specific
value to a counter.
&SAPSCRIPT-TELELAND&:
This field contains the country key of the fax target address when using fax output via SAPscript
(field ITCPO-TDTELELAND of parameter OPTIONS of function module OPEN_FORM).
&SAPSCRIPT-TELENUM&:
This field contains the local fax number of the fax target address when using fax output via
SAPscript (field ITCPO-TDTELENUM of parameter OPTIONS of function module OPEN_FORM).
&SAPSCRIPT-TELENUME&:
Page
SAP Scripts
This field contains the complete fax number of the fax target address when using fax output via
SAPscript (field ITCPO-TDTELENUME of parameter OPTIONS of the function module OPEN_FORM).
Formatting Options:
The value of a symbol is normally printed using its full length, although trailing spaces are removed.
An exception are program symbols of these data types (CURR, DEC, QUAN, INT1, INT2, INT4, PREC,
and FLTP). These are formatted right-justified with an output length as specified in the dictionary.
We can adapt the standard formatting by using one of the additional formatting options available.
List of possible formatting options:
OFFSET: Specifying an offset has the effect that a certain number of bytes of the symbol value,
starting with the first byte on the left, will not be displayed. If the offset specified is greater than the
length of the value, nothing will be printed.
Syntax : &symbol+offset&
If <symbol> has the value 123456789, the following will be displayed.
&symbol& 123456789
&symbol+3& 456789
&symbol+7& 89
&symbol+12&&symbol+0& 123456789
(As 12 in &symbol+12& is greater than the total length )
Output Length: If the requirement is for only a part of the symbol value, or the output has to fit into
the box or a field on the screen without overlapping the edges of this area, then you can use an
output length specification to define how many bytes of the value should be copied.
Syntax:- &symbol(length)&
If <symbol> has the value 123456789, the following will be displayed.
&symbol(3)& 123
&symbol(7)& 1234567
Note: Here we can combine an output length specification with an offset specification. The specified
length is then counted from the specified offset position. &symbol+4(3)& 567. If a length specified
is greater than the current length of the value, then spaces are appended to the symbol value.
OMITTING THE LEADING SIGN: Program symbols with numeric values can have a leading sign.
This sign usually appears to the right of the numeric values, eaither as a space for positive numbers,
or as a minus sign as a negative numbers. We can use the ‘S’ option to ensure that the value is
formatted without the sign.
Syntax:- &symbol(S)&
The ITCDP-TDULPOS field contains the value -100.00
The ABAP Dictionary definitation for this field includes a leading sign.
&ITCDP-TDULPOS & 100.00-
&ITCDP-TDULPOS(S)& 100.00
Page
SAP Scripts
LEADING SIGN TO THE LEFT: 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 us to specify that the
leading sign should be placed to the left of the number.
Syntax:- &symbol(<)&
&ITCDP-TDULPOS & 100.00-
&ITCDP-TDULPOS(<)& -100.00
The SET SIGN LEFT control command specifies that all subsequent symbols with a numeric value
should have a left-justified leading sign. If we use this control command, you must no longer repeat
the < option for each individual symbol.
LEADING SIGN TO THE RIGHT: The default setting is to print the leading sign to the right of a
numeric value. If we use the SET SIGN LEFT control command to specify that the leading sign
should be printed in front of the value, we 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(>)&
We can use the SET SIGN RIGHT control command to switch back to the default setting for the
output of the leading sign.
OMITTING LEADING ZEROS: Certain symbol values are printed with leading zeros. If you want to
suppress these, use the ‘Z’ option.
Syntax:- &symbol(Z)&
Assuming the current date is 09.10.2011, &DAY& 09 then&DAY(Z)& 9
SPACE COMPRESSION: The symbol value is viewed as a sequence of ‘words’, each separated from
the next by either one or a string of space characters.
The ‘C’ option has the effect of replacing each string of space characters with a single space and
shifting the ‘words’ to the left as necessary to close up the gaps. Leading space are completely
removed. The results are the same as those of the ABAP command CONDENSE.
Syntax:- &symbol(C)&
Assuming ‘Iman Sen’ is the symbol value,
&symbol& Iman Sen
&symbol(C)& Iman Sen
NUMBER OF DECIMAL PLACES: A program symbol of one of the data types DEC, QUAN and FLTP
can contain decimal place data. Use the option below to override the Dictionary definition for the
number of decimal places for the formatting of this symbol value.
Syntax:- &symbol(.N)&
The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal
places and an output length of 17.
&EKPO-MENGE& 1,234.560
&EKPO-MENGE(.1)& 1,234.5
&EKPO-MENGE(.4)& 1,234.5600
Page
SAP Scripts
&EKPO-MENGE(.0)& 1,234
OMITTING THE SEPARATOR FOR ‘THOUSANDS’: Symbols of the DEC, CURR, INT, and QUAN data
types are normally formatted with a ‘thousand’ seperator character. The ‘T’ option allows us to omit
this seperator character.
Syntax:- &symbol(T)&
The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal
places and an output length of 17.
&EKPO-MENGE& 1,234.560
&EKPO-MENGE(T)& 1234.560
SPECIFYING AN EXPONENT FOR FLOATING POINT NUMBERS: The way a floating point number
is formatted depends on whether an exponent is specified. The mantissa is adjusted by shifting the
decimal point and, if necessary, introducing leading zeros according to the exponent chosen.
Using an exponent value of 0 means that the exponent representaion will not be used for displaying
the symbol.
Syntax:- &symbol(EN)&
If we specify an exponent of 0, then the number is displayed without using the exponent
representation. This has the same effect as completely omitting the specificataion of an exponent.
&symbol(E0)& has the same effect as &symbol(E)&
Example: The PLMK-SOLLWERT field is assumed to have the value 123456.78 and to be of data
type FLTP.
&PLMK-SOLLWERT& +1.23456780000000E+05
&PLMK-SOLLWERT(E3)& +123.456780000000E+03
&PLMK-SOLLWERT(E6)& +0.123456780000000E+06
&PLMK-SOLLWERT(E0)& +123456.780000000
&PLMK-SOLLWERT(E)& +123456.780000000
RIGHT-JUSTIFIED OUTPUT: Symbol values other than numeric values are normally formatted left-
justified. To specify right-justified formatting, use the R option. We must use this option in
conjuction with an output length specification.
Syntax:- &symbol(R)&
If symbol has the value 1234.
&symbol& 1234
&symbol(8R)& 1234
For program symbols, the length specification contained in the Dictionary definition may be used
instead of an explicit length.
FILL CHARACTERS: We can replace leading spaces in a value with a fill character. Use the ‘F’ option
with the character immediately following the F in the specification as the fill character
Syntax:- &symbol(Ff)& f = fill character.
Page
SAP Scripts
Example: Customer sales in the KNA1-UMSAT field is $700. The Dictionary description of the field
specifies an output length 8.
&KNA1-UMSAT& 700.00
&KNA1-UMSAT(F*)& **700.00 (Since it is right-justified, it is added *s left to it)
&KNA1-UMSAT(F0)& 00700.00 (Zeros are added)
SUPPRESSING OUTPUT OF INITIAL VALUES: Use the ‘I’ option to suppress the output of symbols
that still contain their initial values.
System &sysbol(I)&
Assuming KNA1-UMSAT contains the value 0 and the currency is DEM.
&KNA1-UMSAT& 0,00
&KNA1-UMSAT(I)& If the field contains an amount other than 0, this value is printed in the
normal way.
&KNA1-UMSAT& 700,00
&KNA1-UMSAT(I)& 700,00
IGNORING CONVERSION ROUTINES: SAP Script conversion routines specified in the dictionary
are automatically recognized and used when program symbols are formatted. To suppress
conversion, use the ‘K’ option.
Syntax:- &symbol(K)&
CHANGING THE VALUE OF A COUNTER: We can increase or decrease the value of a SAPSCRIPT-
COUNTER_x (x=0…9) counter variable by 1, before the current counter value is printed.
Syntax : &SAPSCRIPT-COUNTER_x(+)&Increases by 1 the contents of the counter variable x
(x=0…9)
&SAPSCRIPT-COUNTER_x(-)&Decreases by 1 the contents of the counter variable x (x=0…9)
Assume that &SAPSCRIPT-COUNTER_1& initially has the value 2.
&SAPSCRIPT-COUNTER_1(+)& 3
&SAPSCRIPT-COUNTER_1(-)& 2
&SAPSCRIPT-COUNTER_1(-)& 1
PRECEDING AND SUBSEQUENT TEXT (PRE-TEXT / POST-TEXT): In addition to using initial
values for symbols, you can specify additional texts that are printed only when the value of the
symbol is no longer the initial value.
We can specify a text to be printed immediately before the symbol value (the pre-text), and a text to
be printed immediately after the symbol value (the post-text).
Syntax:- &’pre-text’symbol’post-text’&
Example: &’[Link]’KNA1-PFACH&
COUNTRY-DEPENDENT FORMATTING: Certain fields are formatted specific to a particular
country. These inculdes fields for displaying a date and numeric fields containing either a decimal
point or a ‘thousands’ separator character. The formatting applied is usually determined by
definitions contained in the user master record.
Page
SAP Scripts
We can use the SET COUNTRY control command to choose a different formatting operation. The
various country-depenent formatting options are stored in the table T005X.
Syntax:- /:SET COUNTRY country_key
We can specify this country key either by quoting it directly enclosed in inverted commas or by
using symbol
/: SET COUNTRY ‘CAN’ or /: SET COUNTRY &KNA1-LAND1&
DATE MASK: To format date fields, use the SAP Script SET DATE MASK command. Executing this
command causes all the subsequent date fields to be printed with te specified formatting.
Syntax:- /:SET DATE MASK = ‘date mask’
The templates may be used in date mask as below.
DD day (two digits)
DDD name of the day (abbreviated)
DDDD name of the day (written out in full)
MM month (two digits)
MMM name of the month (abbreviated)
MMMM name of the month (written out in full)
YY year (two digits)
YYYY year (four digits)
LD day (formatted as for the L option)
LM month (formatted as for the L option)
LY year (formatted as for the L option)
Assuming a current system date of September 15th 2011.
/:SET DATE MASK = ‘Kolkata, [Link]’
&DATE& Kolkata, 09.15.11
&DATE(Z)& Kolkata, 9.15.11 (No leading zeros)
/:SET DATE MASK = ‘[Link]’
&DATE& September 15, 2011
We can revert to the standars setting by using the SET DATE MASK command again with an empty
string in place of the date mask.
/:SET DATE MASK = ‘ ’
TIME MASK: We can use the SAP Script 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 printed with the specified formatting.
Syntax:- /:SET TIME MASK = ‘time_mask’
The templates may be used in date mask as below.
HH hours (two digits)
MM minutes (two digits)
SS seconds (two digits)
Assuming the current time is 10:08:12.
&TIME& 10:08:12
/:SET TIME MASK = ‘HH:MM’
&TIME& 10:08
Page
SAP Scripts
The purpose of these is to allow control of the output formatting. These commands are not
interpreted by the SAP Script editor, but are passed through to the SAP Script composer for
processing. The composer is the program that converts text from the form displayed in the editor to
the form used for printing. This includes, for example line and page formatting, the replacement of
symbols with their current values and the formatting of text according to the paragraph and
character formats specified.
Syntax of Control Commands
SAP Script control commands are entered and edited in the text editor in the same way as a normal
line of text.
Enter the paragraph format /: in the format column to identify a control command.
Make sure that a control command, together with any parameters it requires, does not
occupy more than a single line.
Enter only one control command in each line.
Note: The editor formatting has no effect on lines containing control commands. Also if control
command is unknown or it contains syntax errors, the line containing it is treated as a comment line. It
is neither interpreted nor printed.
EXPLICIT PAGE BREAK: NEW-PAGE
Sap Script automatically inserts a page break when the main window of a page (MAIN) is full. We
can use the NEW-PAGE command to force a page break in the text at any point we want. It is an
unconditional page break.
Syntax:- /: NEW-PAGE [page_name]
/: NEW-PAGE the current page will be completed and the text in the following lines will be written
to the page specified in the form.
/: NEW-PAGE S1 As above, except that the page S1 will be taken as the next page.
PREVENTING PAGE BREAK: PROTECT-ENDPROTECT
This is to allow we to define the areas to be protected against a page break on an individual basis;
SAP Script provides the PROTECT-ENDPROTECT command pair.
When the text that is to be printed on one without break in between then we use PROTECT-
ENDPROTECT. The text given between the PROTECT-ENDPROTECT will tries to print on current
page if the space is available. If the current MAIN window does not have sufficient space then it will
print entire text on the next page if the NEXT window is enough. If next page also not sufficient to
print then some line of the text will be printed the current page and remaining lines on the next
page because we cannot avoid the page break.
Page
SAP Scripts
Syntax:-
/:PROTECT
:
:
/:ENDPROTECT
NEXT MAIN WINDOW: NEW-WINDOW
Each page can consist of up to 99 main windows. Each main window is assigned a consecutive
identifying number (0…98), and the windows are filled in this order. We can use the NEW-
WINDOW command to call the next main window explicitly, even if the current main window is not
yet full. If we are in the last main window of the page, the command has the same effect as the NEW-
PAGE command.
Syntax:- /:NEW-WINDOW
ASSIGNING A VALUE TO A TEXT SYMBOL: DEFINE
Text symbols acquire their values as a result of explicit assignment. To interactively assign text
symbols, in the text editor choose Include Symbols Text. This method is available for all text
symbols belonging to a text module as well as those of the associated form.
Values defined in this way are lost when the transaction is left. If you want to print the text module
again, then you must enter the symbol values again. The purpose of the DEFINE command is to
provide a means of making this value assignment a permanent part of the text, so that the values
are available again when the text module is called again. This command can also be used to re-
assign a new value to a text symbol half-way through the text.
Syntax:-
/: DEFINE &symbol_name& = 'value'
Ex- /: DEFINE &subject& = 'Your letter of 7/3/95'
Page
SAP Scripts
described in the structures ADRS1, ADRS2, or ADRS3, depending on the type of address. Either
direct values or symbols may be assigned to the parameters.
Syntax:-
/: ADDRESS [DELIVERY] [TYPE t] [PARAGRAPH a] [PRIORITY p] [LINES l]
/: TITLE title
/: NAME name1[,name2[,name3[,name4]]]
/: PERSON name of natural person [TITLE form of address]
/: PERSONNUMBER number of the personen
/: DEPARTMENT department
/: STREET street name HOUSE house number
/: LOCATION additional location information
/: POBOX po box [CODE post code / zip code] [CITY city]
/: POSTCODE post code / zip_code
/: CITY city1[,city2]
/: NO_UPPERCASE_FOR_CITY
/: REGION county / state
/: COUNTRY recipient country [LANGUAGE language code]
/: COUNTRY_IN_REC_LANG
/: LANG_FOR_COUNTRY language key
/: FROMCOUNTRY sender country
/: ADDRESSNUMBER address number
/: ENDADDRESS
Page
SAP Scripts
:
/: ENDIF
The logical expression can use the following comparison operators:
= EQ equal to
< LT less than
GT greater than
<= LE less than or equal to
>= GE greater than or equal to
NE not equal to
The following logical operators can be used to combine conditions:
NOT
AND
OR
INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.
Page
SAP Scripts
OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.
The ABAP subroutine called via the command line stated above must be defined in the ABAP
report prog as follows:
FORM <form> TABLES IN_TAB STRUCTURE ITCSY
OUT_TAB STRUCTURE ITCSY.
...
ENDFORM.
The values of the SAPscript symbols passed with /: USING... are now stored in the internal
table IN_TAB . Note that the system passes the values as character string to the subroutine, since
the field Feld VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 80). See the example
below on how to access the variables.
The internal table OUT_TAB contains names and values of the CHANGING parameters in the
PERFORM statement. These parameters are local text symbols, that is, character fields. See the
example below on how to return the variables within the subroutine
BOX COMMAND
Syntax
/: BOX [XPOS] [YPOS] [WIDTH] [HEIGHT] [FRAME] [INTENSITY]
Effect: draws a box of the specified size at the specified position.
Parameters: For each of XPOS, YPOS, WIDTH, HEIGHT, and FRAME, you must specify both a
measurement and a unit of measurement. Specify the INTENSITY parameter as a percentage
between 0 and 100.
XPOS, YPOS
Upper left corner of the box, relative to the values of the POSITION command.
Default: Values specified in the POSITION command.
The following calculation is performed internally to determine the absolute output position of a box
on the page:
X(abs) = XORIGIN + XPOS
Y(abs) = YORIGIN + YPOS
WIDTH: Width of the box. Default: WIDTH value of the SIZE command.
Page
SAP Scripts
HEIGHT: Height of the box. Default: HEIGHT value of the SIZE command.
FRAME: Thickness of [Link]: 0 (no frame).
INTENSITY: Grayscale of box contents as %.
Default: 100 (full black)
Measurements: You must specify decimal numbers as literal values (like ABAP numeric constants)
by enclosing them in inverted commas. Use the period as the decimal point character. See also the
examples listed below.
Units of measurement: The following units of measurement may be used:
TW (twip)
PT (point)
IN (inch)
MM (millimeter)
CM (centimeter)
LN (line)
CH (character).
The following conversion factors apply:
1 TW = 1/20 PT
1 PT = 1/72 IN
1 IN = 2.54 CM
1 CM = 10 MM
1 CH = height of a character relative to the CPI specification in the form header
1 LN = height of a line relative to the LPI specification in the form header
POSITION COMMAND
Syntax
/: POSITION [XORIGIN] [YORIGIN] [WINDOW] [PAGE]
Effect: Sets the origin for the coordinate system used by the XPOS and YPOS parameters of the BOX
command. When a window is first started, the POSITION value is set to refer to the upper left
corner of the window (default setting).
Parameters: If a parameter value does not have a leading sign, then its value is interpreted as an
absolute value, in other words, as a value that specifies an offset from the upper left corner of the
output page. If a parameter value is specified with a leading sign, then the new value of the
parameter is calculated relative to the old value. If one of the parameter specifications is missing,
then no change is made to this parameter.
XORIGIN, YORIGIN: Origin of the coordinate system.
WINDOW: Sets the values for the left and upper edges to match those of the current window
(default setting).
PAGE: Sets the values for the left and upper edges to match those of the current output page
(XORIGIN = 0 cm, YORIGIN = 0 cm).
SIZE COMMAND
Syntax
/: SIZE [WIDTH] [HEIGHT] [WINDOW] [PAGE]
Effect: Sets the values of the WIDTH and HEIGHT parameters used in the BOX command. When a
window is first started, the SIZE value is set to the same values as the window itself (default
setting).
Parameters: If one of the parameter specifications is missing, then no change is made to the
current value of this parameter. If a parameter value does not have a leading sign, then its value is
interpreted as an absolute value. If a parameter value is specified with a leading sign, then the new
value of the parameter is calculated relative to the old value.
Page
SAP Scripts
OPEN_FORM
The function module OPEN_FORM opens form printing. You must call this function module before
you can use any other form function (WRITE_FORM, START_FORM, CONTROL_FORM ...).
You need not specify a form name. If you omit the name, you must use the function module
START_FORM to open a form before starting the output.
You must end form printing by using the function module CLOSE_FORM. Otherwise, the system
does not print or display anything.
Within a program, you can use several OPEN_FORM. CLOSE_FORM pairs. This allows you to write
output to several different spool requests from within one program,
Function Call
CALL FUNCTION 'OPEN_FORM'
* EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
* DEVICE = 'PRINTER'
* DIALOG = 'X'
* FORM = ' '
* LANGUAGE = SY-LANGU
* OPTIONS =
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* SPONUMIV =
* 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
* CODEPAGE = 11
* OTHERS = 12
.
Page
SAP Scripts
Export parameters:
You can enter the name of a form here, which then controls output formatting. After
calling OPEN_FORM, you can immediately output texts to the form using other
function modules.
FORM
If you leave the parameter blank, you must call START_FORM with a valid form
name before starting any output functions.
Default value: SPACE
Forms are language-dependent. Enter the desired language. If a form does not exist
in this language, the system tries to call the form in its original language.
LANGUAGE
Reference field: THEAD-TDSPRAS
Default value: SY-LANGU
SAPscript can format a text for output on different device types. Enter the desired
device type here.
Possible values:
'PRINTER' print output
'TELEX' telex output
'TELEFAX' telefax output
'ABAP' screen output as ABAP list
(interface of the calling program)
'SCREEN' screen output as ABAP list
DEVICE
(interface controlled by SAPscript,
can be set with parameter APPLICATION)
The user can display output formatted for PRINTER, TELEX, or TELEFAX as print
view on the screen. From within the program, you can set the field TDPREVIEW
(structure ITCPO) in the parameter OPTIONS, or the user can call the function on
the print control screen.
The fields TDSENDTIME and TDSENDDATE designed for fax output (structure
ITCPO) will be used for future enhancements; they are not used at present.
Default value: 'PRINTER'
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:
DIALOG
' ' display no print parameter screen
'X' display print parameter screen
Default value: 'X'
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
OPTIONS print control screen.
Structure: ITCPO
Default value: SPACE
For the device type SCREEN, the system displays the text formatting on the screen.
This requires an interface in which the different menu entries are defined. The same
applies if the user chooses to display a print view on the screen for the other device
types.
APPLICATION
Enter one of the interface names provided by SAPscript. You usually use the
interface that is assigned to the respective text object in table TTXOB.
Reference field: TTXOB-TDAPPL
Default value: 'TX'
Enter the index information for the print output you want to archive. This
information (DARA line) is stored in the archive together with the print output.
Thus, you can use the index information to access the print output directly in the
ARCHIVE_INDEX
archive.
Structure: TOA_DARA
Default value: SPACE
ARCHIVE_PARAMS The system interprets the settings passed in this parameter when archiving the
Page
SAP Scripts
output. The archive parameters have the ABAP Dictionary structure ARC_PARAMS.
Structure: ARC_PARAMS
Default value: SPACE
Import parameters:
LANGUAGE The parameter tells you which language variant of the form the system
actually used.
Reference field: THEAD-TDSPRAS
RESULT The parameter contains results of the print formatting process. By
comparing the corresponding fields of parameter OPTIONS with those of
parameter RESULT, you can determine whether the user made changes to
any settings on the print control screen.
Structure: ITCPP
NEW_ARCHIVE_PARAMS The parameter contains results of the archiving process, including the
archive parameters the user changed on the print control screen. The
parameter has the ABAP Dictionary structure ARC_PARAMS.
Structure: ARC_PARAMS
Exceptions:
When starting SAPscript print formatting, the system displayed a selection screen, on
which the user can enter settings for the output, such as:
Printer name
Information on the cover page
CANCELED Page selection
Number of copies
The user did not call any subsequent actions allowed on this screen, but canceled the
output formatting instead. The function module was ended without further action. No form
is open for output anymore.
DEVICE The parameter DEVICE contains an invalid device type.
The parameter FORM contains the name of a form that the system could not find.
Possible reasons:
The form does not exist.
There is no active version of this form.
FORM
SAPscript first searches for the form in the current client and in the specified language. If
the form does not exist there, it tries the original language of the form. If the form is still not
found, it searches in client 0, first in the specified language, than in the original form
language.
The parameter OPTIONS contains invalid values for the formatting options.
Possible errors:
OPTIONS The output device specified in field TDDEST does not exist.
The field TDPAGESLCT for selecting the pages to be printed contains invalid
characters.
The system was told to open a new form even though an old form is still active. The old
UNCLOSED
form must be closed first (CLOSE_FORM or END_FORM).
CLOSE_FORM
The function module closes the form opened using OPEN_FORM. The system executes any
terminating processing steps for the last opened form.
You must use this function module to close form printing. Otherwise, no output appears on printer
or screen.
CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
* RESULT =
Page
SAP Scripts
* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SEND_ERROR = 3
* SPOOL_ERROR = 4
* CODEPAGE = 5
* OTHERS = 6
.
Import parameters:
The parameter contains results of the print formatting process. By comparing the
corresponding fields of parameter OPTIONS with those of parameter RESULT, you can
determine whether the user made changes to any settings on the print control screen.
Structure: ITCPP
Among others, the structure ITCPP contains a field with the name of USEREXIT. This field
RESULT
tells you how the user left the print view:
Characters E, B, or C:
EXIT <-> E
BACK <-> B
CANCEL <-> C
Table parameters:
If in the parameter OPTIONS the field TDGETOTF contains 'X', the system returns the
formatted output in the OTF format in the optional table parameter OTFDATA.
OTFDATA
In this case, the system does not output anything to printer, screen or fax/telex/teletex.
Structure: ITCOO
Exceptions:
UNOPENED The system could not execute the current form function, since the form output was not yet
initialized using OPEN_FORM.
START_FORM
In-between the function modules OPEN_FORM and CLOSE_FORM, you can use different forms. This
allows you to combine several different forms into one print output. However, you can combine
only those forms that have the same page format.
To switch forms, use the function module START_FORM. If another form is still open, you must
close it first using END_FORM.
If you specify no form name when calling START_FORM, the system restarts the last open form. If
after OPEN_FORM no form was activated yet, the system leaves the function module with the
exception UNUSED.
CALL FUNCTION 'START_FORM'
* EXPORTING
* ARCHIVE_INDEX =
* FORM = ' '
* LANGUAGE = ' '
* STARTPAGE = ' '
* PROGRAM = ' '
Page
SAP Scripts
* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
* EXCEPTIONS
* FORM = 1
* FORMAT = 2
* UNENDED = 3
* UNOPENED = 4
* UNUSED = 5
* SPOOL_ERROR = 6
* CODEPAGE = 7
* OTHERS = 8
.
Export parameters:
The parameter contains the name of the form you want to use for printing. If you
FORM specify no form here, the system restarts the last active form.
Default value: SPACE
Forms are language-dependent. Enter the desired language here. If the form does
not exist in this language, the system tries to call the form in its original language. If
the parameter LANGUAGE is empty, the system uses the language of the last active
LANGUAGE
form.
Reference field: THEAD-TDSPRAS
Default value: SY-LANGU
Usually, SAPscript starts with the page specified as start page in the form
definition. If you want to start output with another form page, enter the name of
STARTPAGE the desired form page here. If the desired page is not defined, the system uses the
start page defined in the form.
Default value: SPACE
To replace program symbols, SAPscript must know which active program contains
the work areas for the values to be passed.
If you 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.
PROGRAM
If you enter a program name, the system replaces the program symbols with the
values from this program up to the next END_FORM.
Reference field: SY-REPID
Default value: SPACE
Enter index information for the print output you want to archive. The system
stores this information (DARA line) together with the print output in the archive.
You can then access this special print output in the archive using the index
ARCHIVE_INDEX
information.
Structure: TOA_DARA
Default value: SPACE
Import parameters:
The parameter tells you which language variant of the form the system actually
LANGUAGE used.
Reference field: THEAD-TDSPRAS
Exceptions:
Page
SAP Scripts
The parameter FORM contains the name of a form which could not be found.
Possible reasons:
The form does not exist.
There is no active version of this form.
FORM
SAPscript first searches for the form in the current client and in the specified
language. If the form does not exist there, it tries the original language of the form.
If the form is still not found, it searches in client 0, first in the specified language,
than in the original form language.
Within a print output defined between OPEN_FORM and CLOSE_FORM, you must
use forms of the same page format. The page format of the current form differs
from that of the previously called forms.
FORMAT
Include only those forms into one spool request that have the same format (for
example, DINA4). Page orientation is of no consequence; that means, you can mix
pages in landscape and portrait format.
The last form opened is still open. It must first be closed using END_FORM or the
UNENDED
form output must be closed using CLOSE_FORM.
The current form function could not be executed, since the form output was no yet
UNOPENED
initialized using OPEN_FORM.
One of the parameters FORM or LANGUAGE contains only blanks and no form has
UNUSED
been opened yet whose name or language could be used as defaults.
WRITE_FORM
The system outputs the form element specified in parameter ELEMENT into the currently opened
form.
In the parameter WINDOW you can specify the name of a window for the output. Remember that
the form 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.
CALL FUNCTION 'WRITE_FORM'
* EXPORTING
* ELEMENT = ' '
* 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
* CODEPAGE = 9
* OTHERS = 10
.
Export parameters:
ELEMENT Specify the name of the text element you want to output into the form window specified
Page
SAP Scripts
in the parameter WINDOW. The element must be defined in that form window. If you
specify no element, the system uses the default element, if one is defined in the form.
Default value: SPACE
Specify the name of the window into which you want to output the form element
WINDOW specified in the parameter ELEMENT.
Default value: 'MAIN'
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 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
FUNCTION
output the element
'APPEND' append the element to the existing elements 'DELETE' delete the specified
element from the window
or area
DELETE in the TOP area (headings) takes effect only on the next page. You can no longer
delete any heading from the TOP area after outputting text to the BODY area.
Import parameters:
If a text is output to the BOTTOM area of the main window (TYPE = 'BOTTOM'),
there may be not enough space left on the current output page. The system then
internally flags this text for output into the BOTTOM area of the next page. The
PENDING_LINE actual output is pending.
S
If output is pending, the parameter PENDING_LINES contains 'X', and the print
program can react accordingly. For example, an explicit page break at the text end
(NEW-PAGE) could implicitly trigger the pending BOTTOM output on the next page.
Exceptions:
ELEMENT The parameter ELEMENT contains the name of a form element that the system
could not find.
Possible reasons:
The element does not exist.
An element refers to a window, and the specified window does not contain the
element. If no window is specified, the system searches for the element in the main
window.
The specified element is not defined in the form.
Page
SAP Scripts
The form version that contains the text element in the specified form
window is not active.
The function specified in parameter FUNCTION is unknown.
For this parameter, the following values are allowed:
FUNCTION SET
APPEND
DELETE
The type of window area specified in parameter TYPE is invalid.
Depending on the window type, these entries are valid:
TYPE BODY: for all windows
TOP: only for the main window
BOTTOM: only for the main window
The current form function could not be executed, since the form output was no yet
UNOPENED
initialized using OPEN_FORM.
No form was opened yet.
Possible reasons:
The form processing was started using OPEN_FORM without specifying a
form name, but no form was opened yet using START_FORM.
The last used form was closed using END_FORM, but no new form was
UNSTARTED opened using START_FORM.
The last filled page of the current form has no subsequent page. In this case,
the system automatically terminates form printing after this page. You need
no explicit END_FORM call.
In the current form, no page contains a main window, but a text element
shall be output in the main window.
The form window specified in parameter WINDOW does not exist in the current
form.
WINDOW Possible reasons:
A wrong window name was specified.
The form version, which contains the specified window, is not active.
END_FORM
END_FORM ends the currently open form and executes the required termination processing. After
calling this function module, no more form is active. For further output, you must start a new form
using START_FORM.
END_FORM does not replace CLOSE_FORM, that is, you must always close any SAPscript output
using CLOSE_FORM.
CALL FUNCTION 'END_FORM'
* IMPORTING
* RESULT =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SPOOL_ERROR = 3
* CODEPAGE = 4
* OTHERS = 5
Import parameters:
The parameter contains results of the print formatting process. By comparing the
corresponding fields of parameter OPTIONS with those of parameter RESULT, you can
RESULT
determine whether the user made changes to any settings on the print control screen.
Structure: ITCPP
Page
SAP Scripts
Exceptions:
The current form function could not be executed, since the form output was no yet
UNOPENED
initialized using OPEN_FORM.
Run it
Page
SAP Scripts
Page
SAP Scripts
UPLOAD THE LOGO FROM USER DESKTOP TO THE DOCUMENT SERVER THROUGH SAP.
Go to transaction ‘SE78’ and click on the BMAP under GRAPHICS tab.
Then click on the leftmost ‘Import’ button. The following pop up window appears. Pass the file
name and the parameters as follows.
The following screen appears with a status message that the logo was imported.
Page
SAP Scripts
Page
SAP Scripts
Chose Old Barcode technology and give the Bar Code name, description and the following
parameters.
Page
SAP Scripts
Give the description and keep the radio button selected. Save it. The form is
now created.
Click on the button and enter the following parameters and save it. The page is created.
Page
SAP Scripts
Page
SAP Scripts
Create a paragraph format TB for table header defining the margins and tab positions as many as
required.
Page
SAP Scripts
Create a paragraph format TC for table content defining the margins and tab positions as many as
required.
Page
SAP Scripts
Create a paragraph format TF for table footer defining the margins and tab positions as many as
required.
Click on the button and create BC for Bar Code character format defining the
followings.
Page
SAP Scripts
Click on the ‘Header’ button and then ‘Basic Settings’ and define the following parameters.
Page
SAP Scripts
Click on button and go to and then click on ‘Create Element’ and define all the
necessaries. Apart from the ‘Main Window’ created create all the windows required defining the
Window Types and Default Paragraphs.
Page
SAP Scripts
Click on button and go to and then click on ‘Create Element’. The following
pop up window appears.
Click on the window and define its dimensions required. Put the left and upper margins and
window widths and heights accordingly. Repeat the process for all the windows in that page. If no.
of windows is more than eight then press page down key from keyboard to see the rests.
Finally the form consists of the following windows in the output.
Page
SAP Scripts
To view the windows graphically go to and click on ‘Form Painter’. After fixing the user
settings the layout comes as follows:
Page
SAP Scripts
In the following pop up window pass the logo that is Stored on Document Server and define all the
parameters.
Print the Title in the ‘TITLE’ window defining the paragraph and character format in the editor.
Print the Company Address in the ‘ADDRESS’ window defining the paragraph format, character
format and tabs and spaces in the editor.
Page
SAP Scripts
Print the terms and condition in the ‘FREETEXT’ window defining the paragraph and character
format in the editor.
Print the VAT No. and Reg. No. in the ‘FOOTER’ window defining the paragraph format, character
format and tabs and spaces in the editor.
Create a box in the ‘PAGE’ window using the commands according to requirements and print the
Page No., Date and Name over there defining the paragraph format, character format and tabs and
spaces in the editor. Also pass their values as obtained from the driver program.
Page
SAP Scripts
Print the Sales Doc. No., Sales Org., Distribution Channel, Division and Total Value with its currency
in the ‘HEADER’ window using the commands according to requirements and defining the
paragraph format, character format and tabs and spaces in the editor. Also pass their values as
obtained from the driver program.
Create a box in the ‘MAIN’ window using the commands according to requirements and print the
table with Item, Material, Material Description, Quantity, Unit Price and Net Price over there
defining the paragraph format, character format and tabs and spaces in the editor. Also pass their
values under the Text Element ITEM_INFO as obtained from the driver program.
Page
SAP Scripts
Keep the table footer in separate window ‘TOTAL’ at the bottom of the main window and create the
box using the commands according to requirements to print the total value under the Text Element
‘FOOTER’ so that it gets printed only at the last page of the form.
Print the Total value in form of Bar Code in the ‘BARCODE’ window defining the paragraph and
character format and tabs and spaces.
Page
SAP Scripts
*STRUCTURES
*===========
TYPES: BEGIN OF t_vbak,
vbeln TYPE vbeln_va, " Sales Document
erdat TYPE erdat, " Date on Which Record Was Created
ernam TYPE ernam, " Name of Person who Created the
Object
vkorg TYPE vkorg, " Sales Organization
vtweg TYPE vtweg, " Distribution Channel
spart TYPE spart, " Division
waerk TYPE waerk, " SD Document Currency
END OF t_vbak,
BEGIN OF t_vbap,
vbeln TYPE vbeln_va, " Sales Document
posnr TYPE posnr_va, " Sales Document Item
matnr TYPE matnr, " Article Number
arktx TYPE arktx, " Short text for sales order item
kwmeng TYPE kwmeng, " Cumulative Order Quantity
netpr TYPE netpr, " Net price
END OF t_vbap,
*TABLES
*=======
t_tab_vbap TYPE STANDARD TABLE OF t_vbap.
*---------------------------------------------------------------------*
* GLOBAL DATA OBJECTS DECLARATIONS *
*---------------------------------------------------------------------*
*WORK AREAS
*===========
DATA: wa_header TYPE t_vbak, " Holds Header Information
wa_item TYPE t_vbap, " Holds Item Information
*INTERNAL TABLES
*================
i_item TYPE t_tab_vbap, " Holds Item Records
*VARIABLES
*==========
v_total TYPE char15, " Variable to hold the total amount
v_unit_price TYPE char11, " Variable to hold each item price
v_net_price TYPE char15. " Variable to hold line item value
*---------------------------------------------------------------------*
* SELECTION-SCREEN *
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK order WITH FRAME TITLE text-001.
PARAMETERS: p_order LIKE vbak-vbeln.
SELECTION-SCREEN END OF BLOCK order.
*&------------------------------------------------------------------*
*& AT SELECTION-SCREEN
*&------------------------------------------------------------------*
AT SELECTION-SCREEN.
IF sy-ucomm = 'ONLI'.
*============ VALIDATION ON MATERIAL ====================
PERFORM validate_order USING p_order.
ENDIF.
*---------------------------------------------------------------------*
* START-OF-SELECTION *
*---------------------------------------------------------------------*
Page
SAP Scripts
START-OF-SELECTION.
* Get the header data to print
PERFORM get_header_data USING p_order
CHANGING wa_header.
* Get the Sales Order Item details
PERFORM get_item_data USING wa_header
CHANGING i_item
wa_item
v_total.
* Open Form
PERFORM open_form.
* Start Form
PERFORM start_form.
* Write Form
PERFORM write_form.
* End Form
PERFORM end_form.
* Close Form
PERFORM close_form.
*--------------------------------------------------------------------*
* SUBROUTINES *
*---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form validate_order
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_ORDER text
*----------------------------------------------------------------------*
FORM validate_order USING p_p_order TYPE vbeln_va.
*=========LOCAL VARIABLE==========*
DATA : lv_order TYPE vbeln_va.
IF p_p_order IS NOT INITIAL.
SELECT SINGLE "#EC *
vbeln " Sales Document Number
FROM vbuk
INTO lv_order
WHERE vbeln = p_p_order.
IF sy-subrc <> 0.
MESSAGE e007. " Invalid sales order! Please enter valid
sales order.
ENDIF.
ENDIF.
ENDFORM. " validate_order
*&---------------------------------------------------------------------*
*& Form get_header_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_ORDER text
* <--P_WA_HEADER text
*----------------------------------------------------------------------*
FORM get_header_data USING p_p_order TYPE vbeln_va
CHANGING p_wa_header TYPE t_vbak.
* Get the Sales Order Header detail
SELECT SINGLE
Page
SAP Scripts
Page
SAP Scripts
*&---------------------------------------------------------------------*
*& Form write_form
*&---------------------------------------------------------------------*
* text
Page
SAP Scripts
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_form .
* Check if Item data found
IF i_item[] IS NOT INITIAL.
* Take the details for each item
LOOP AT i_item[] INTO wa_item WHERE vbeln = wa_header-vbeln.
* Get the unit price and calculate the net price
CLEAR: v_unit_price, v_net_price.
v_unit_price = wa_item-netpr.
v_net_price = wa_item-netpr * wa_item-kwmeng.
CONDENSE: v_unit_price, v_net_price.
ENDLOOP.
* Write the table Footer
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'FOOTER'
window = 'TOTAL'
EXCEPTIONS
element = 1
function = 2
type = 3
unopened = 4
unstarted = 5
window = 6
bad_pageformat_for_print = 7
spool_error = 8
codepage = 9
OTHERS = 10.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Page
SAP Scripts
ENDIF.
ENDFORM. " write_form
*&---------------------------------------------------------------------*
*& Form end_form
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM end_form .
CALL FUNCTION 'END_FORM'
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
spool_error = 3
codepage = 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.
ENDIF.
*&---------------------------------------------------------------------*
*& Form close_form
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM close_form .
CALL FUNCTION 'CLOSE_FORM'
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " close_form
Execute the program and provide LP01 as Output device. And press enter. The final output appears
as follows:
Page
SAP Scripts
Page
SAP Scripts
PRINTING TOTAL, CARRY FORWARD AMOUNT AND GRAND TOTAL IN SAP SCRIPT
This Scenario explains about how to add and print the page total, Carry forward amount for each
page and also the Grand total at the last page. It also calls different Page orientation
likePORTRAIT and LANDSCAPE Format achieved by using SCRIPTS.
Designing the Form layout in PORTRAIT Format using SE71 .
In the basic settings of the form painter, select the orientation PORTRAIT Format as shown below.
Create the windows for the page. In this scenario created windows for the
Footer - Displaying the Continue page
Headers - Displaying the heading for selected SFLIGHT details.
Page
SAP Scripts
Page
SAP Scripts
In the text editor of main window, we have added the logic to display the number of records for a
page (In this scenario 5 records per page) and also for each page displaying the page total, Carry
forward total as shown in below. And also it prints Grand total at the last page.
In the text editor of the Header Window - Displaying the heading for selected SFLIGHT details.
Page
SAP Scripts
In the text editor of the Var Window - Displaying the Page Header
In the text editor of the Var1 Window - Displaying the Date and Time
Page
SAP Scripts
In the main window of the landscape format include the text as shown below.
Page
SAP Scripts
Page
SAP Scripts
perform main_window.
perform end_form.
perform start_form using 'Z_SCRI_LAND'.
perform landscape_format.
perform end_form.
perform close_form.
*&---------------------------------------------------------------------*
*& Form GETSFLIGHTRECORDS
*&---------------------------------------------------------------------*
* This subroutine gets the Flight records from the table SFLIGHT
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form getsflightrecords .
select carrid " Airline code
connid " Flight connection number
fldate " Flight date
planetype " Plane type
price " Airfare
from sflight
into table t_sflight
where carrid in s_carrid.
if sy-subrc ne 0.
message 'Records Not Found'(001) type 'S'.
endif.
endform. " GETSFLIGHTRECORDS
*&---------------------------------------------------------------------*
*& Form OPEN_FORM
*&---------------------------------------------------------------------*
* This subroutine opens the script form Z_SCRIPTS
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form open_form .
call function 'OPEN_FORM'
exporting
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
* DEVICE = 'PRINTER'
* DIALOG = 'X'
form = 'Z_SCRIPTS'
language = sy-langu
* OPTIONS =
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* SPONUMIV =
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
exceptions
canceled = 1
device = 2
form = 3
Page
SAP Scripts
options = 4
unclosed = 5
mail_options = 6
archive_error = 7
invalid_fax_number = 8
more_params_needed_in_batch = 9
spool_error = 10
codepage = 11
others = 12.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " OPEN_FORM
*&---------------------------------------------------------------------*
*& Form MAIN_WINDOW
*&---------------------------------------------------------------------*
* This subroutine prints the SFLIGHT records in a MAIN window
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form main_window .
loop at t_sflight into fs_sflight.
call function 'WRITE_FORM'
exporting
element = 'SFLIGHT'
* 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
codepage = 9
others = 10.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*&---------------------------------------------------------------------*
*& This statement is used to display the grand total for the last page
*&---------------------------------------------------------------------*
at last.
call function 'WRITE_FORM'
exporting
element = 'GRAND_TOTAL'
* FUNCTION = 'SET'
* TYPE = 'BODY'
window = 'MAIN'
* IMPORTING
Page
SAP Scripts
* PENDING_LINES =
exceptions
element = 1
function = 2
type = 3
unopened = 4
unstarted = 5
window = 6
bad_pageformat_for_print = 7
spool_error = 8
codepage = 9
others = 10.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
exit.
endat.
w_index = w_index + 1.
if w_index eq 6.
call function 'WRITE_FORM'
exporting
element = 'PAGE_TOTAL'
* 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
codepage = 9
others = 10.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
call function 'CONTROL_FORM'
exporting
command = 'NEW-PAGE'
exceptions
unopened = 1
unstarted = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
w_index = 1.
endif.
endloop.
Page
SAP Scripts
Page
SAP Scripts
endif.
endform. " LANDSCAPE_FORMAT
*&---------------------------------------------------------------------*
*& Form START_FORM
*&---------------------------------------------------------------------*
* This subroutine fetches the form Z_SCRIPTS
*----------------------------------------------------------------------*
* -->P_0068 -- Z_SCRIPTS
*----------------------------------------------------------------------*
form start_form using value(p_0068).
call function 'START_FORM'
exporting
* ARCHIVE_INDEX =
form = p_0068
* LANGUAGE = ' '
* STARTPAGE = ' '
* PROGRAM = ' '
* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
exceptions
form = 1
format = 2
unended = 3
unopened = 4
unused = 5
spool_error = 6
codepage = 7
others = 8.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " START_FORM
*&---------------------------------------------------------------------*
*& Form END_FORM
*&---------------------------------------------------------------------*
* This subroutine ends the form Z_SCRI_LAND
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form end_form .
call function 'END_FORM'
* IMPORTING
* RESULT =
exceptions
unopened = 1
bad_pageformat_for_print = 2
spool_error = 3
codepage = 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.
endif.
endform. " END_FORM
Page
SAP Scripts
Second Page:
Page
SAP Scripts
Last Page:
Page
SAP Scripts
Page
SAP Scripts
Page
SAP Scripts
Go to windows tab and create windows. To create a new window edit->create element->window.
Give the window name and meaning. Please observe that we have created 9 main windows here.
Also, align the windows properly. In this example, we have taken 3 main windows in a row.
Go to page windows tab and double click on the main window and select text elements (F9)
Page
SAP Scripts
Go to transaction SE38 and write the print program for the form.
Here is the code for that.
Page
SAP Scripts
*****************************************************************************
* Program : ZDEMO_SAP1 Creation Date:11-JAN-
2012*
* Program Title : Driver Program for SAP SCRIPT *
* Program Author: Iman Sen *
* Program Type : Executable Program *
*****************************************************************************
REPORT ZDEMO_SAP1.
TABLES:
adrc.
SELECT-OPTIONS:
s_addrno FOR adrc-addrnumber.
TYPES:
BEGIN OF type_s_adrc,
addrnumber TYPE adrc-addrnumber,
END OF type_s_adrc.
DATA:
fs_adrc TYPE type_s_adrc.
DATA:
t_adrc LIKE
STANDARD TABLE
OF fs_adrc.
SELECT addrnumber
INTO TABLE t_adrc
FROM adrc
WHERE addrnumber IN s_addrno.
PERFORM open_form.
LOOP AT t_adrc INTO fs_adrc.
PERFORM write_form." USING 'ADDRESS' 'APPEND' 'MAIN'.
ENDLOOP. "LOOP AT T_ADRC
PERFORM close_form.
*&---------------------------------------------------------------------*
*& Form OPEN_FORM
*&---------------------------------------------------------------------*
FORM open_form .
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
* DEVICE = 'PRINTER'
* DIALOG = 'X'
form = 'Y_ADDRESS'
* LANGUAGE = SY-LANGU
* OPTIONS =
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* SPONUMIV =
* IMPORTING
* LANGUAGE =
Page
SAP Scripts
* 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
* CODEPAGE = 11
* OTHERS = 12
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. " If sy-subrc <> 0
FORM write_form .
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'ADDRESS'
* 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
codepage = 9
OTHERS = 10
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. " If sy-subrc <> 0
*&---------------------------------------------------------------------*
*& Form CLOSE_FORM
*&---------------------------------------------------------------------*
Page
SAP Scripts
FORM close_form .
CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
* RESULT =
* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SEND_ERROR = 3
* SPOOL_ERROR = 4
* CODEPAGE = 5
* OTHERS = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. " If sy-subrc <> 0
Page
SAP Scripts
PASSING TABLE DATA TO THE LAYOUT WITHOUT CHANGING THE DRIVER PROGRAM
I have seen a typical requirement from client that SAP script layout need to be changed (additional
data need to be displayed) without modifying the driver program (mainly standard SAP program).
This tip will show us how to pass table data (multiple records at a time) to layout without changing
the driver program.
Create a standard text from SO10.
Create a blank standard text. This will store the table data
Page
SAP Scripts
Create a subroutine pool and a routine in it that can be called from SAP script.
From transaction SE38 create a subroutine pool.
Now create subroutine with proper interface to fetch the data from the table.
Page
SAP Scripts
Within this routine write the logic to fetch the table data and populate the standard text.
***************************************************************
* Fetch table data and upload the data in proper format to the
* standard text
***************************************************************
DATA: i_zemployee TYPE STANDARD TABLE OF zemployee INITIAL SIZE 0,
w_zemployee TYPE zemployee,
i_text TYPE STANDARD TABLE OF tline INITIAL SIZE 0,
w_header LIKE thead,
w_text TYPE tline.
CONSTANTS: c_par TYPE char2 VALUE ',,'. " Sign for tabs
* Fetch data for employee
SELECT * FROM zemployee
INTO TABLE i_zemployee.
IF sy-subrc = 0.
* Create text table
LOOP AT i_zemployee INTO w_zemployee.
* Store default paragraph format
w_text-tdformat = '*'.
* Add all the required fields separated by tab
CONCATENATE w_zemployee-empno w_zemployee-empname
INTO w_text-tdline
SEPARATED BY c_par.
* Store table data
APPEND w_text TO i_text.
ENDLOOP.
check sy-subrc = 0.
* Populate header info
* Text object
w_header-tdobject = 'TEXT'.
* Standard text name
w_header-tdname = 'Z_TABLE_DATA'.
* Text id
Page
SAP Scripts
w_header-tdid = 'ST'.
* Language
w_header-tdspras = 'E'.
* Populate the standard text with table data
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = w_header
insert = 'X'
savemode_direct = 'X'
TABLES
lines = i_text
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5
.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
Call the routine and standard text from the SAP script layout.
Note: For the sake of simplicity this tip is shown in a custom layout that is called from a custom
report.
/* Call the routine
/: PERFORM FETCH_TABLE_DATA IN PROGRAM Z_SUBROUTINE_POOL
/: USING &INVAR1&
/: CHANGING &OUTVAR1&
/: ENDPERFORM
/* Now call the standard text
/: INCLUDE Z_TABLE_DATA OBJECT TEXT ID ST LANGUAGE EN
Page
SAP Scripts
Page
SAP Scripts
FORM = 'Z_DEMO_LAYOUT'
LANGUAGE = SY-LANGU
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
CODEPAGE = 11
OTHERS = 12
.
IF sy-subrc = 0.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = '001'
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
CODEPAGE = 9
OTHERS = 10
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'CLOSE_FORM'
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 4
CODEPAGE = 5
OTHERS = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
After execution of this report SAPscript debugger is triggered.
Page
SAP Scripts
Page
SAP Scripts
Page
SAP Scripts
Table entries:
Page
SAP Scripts
Click on
Page
SAP Scripts
Note: this is same place we change configuration and most of the times the functional consultant do
this.
Requirement: Add the window for Logo and print the Logo.
Steps to copy the layout for modifications:
Execute SE71 and Utilities Copy from client.
Provide the Source Form and Target Form and execute it.
Page
SAP Scripts
Enter.
Open the English version in change mode and add the page window Logo.
Page
SAP Scripts
Page
SAP Scripts
Page
SAP Scripts
L_KUNNR = INPUT-VALUE.
SELECT SINGLE TELNO FROM KNA1 INTO L_TELNO WHERE KUNNR = L_KUNNR.
READ TABLE OUTPUT WITH KEY NAME = 'TELNO'.
OUTPUT-VALUE = L_TELNO.
MODIFY OUTPUT INDEX SY-TABIX TRANSPORTING VALUE.
ENDFORM.
Page
SAP Scripts
Explain how to print the signature only in the last page and address and logo only in the first
page?
Check the page number and print it.
/: IF &PAGE& = 1. “First Page
INSERT the Logo and repeat the same procedure for Address.
ENDIF.
To print the Signature
/: IF &NEXTPAGE& = 0. “Current Page is the Last page when there is no NEXT page.
INSERT the scanned signature text.
ENDIF.
Is it possible to print the text with different font on the same line?
Yes, it is possible through Character Format. In SAPScript apply like this
<U>Underline Text</><B>Bold Text</>
Where Character format: B for Bold and U for Underline.
How can you copy SAPScript from one client from another?
In transaction SE71, Enter the form name and choose Menu, UtilitiesCopy from client to copy
SAPScript from one client to another.
OR use RSTXSCRP to import/Export SAPScript.
What is the difference between the SAPScript texts, ‘Customer: &KNA1-KUNNR&’ and
&Customer: KNA1-KUNNR&?
In the first case of ‘Customer: &KNA1-KUNNR&’, the text ‘Customer:’ is displayed regardless of the
variable KNA1-KUNNR even if it is having initial value.
In the second case of ‘&Customer: KNA1-KUNNR&’, the text ‘Customer:’ and KNA1-KUNNR is
displayed only when the variable KNA1-KUNNR has non-initial values.
What is Standard TEXT and how to create and INCLUDE it in the layout?
Instead of maintaining the Long text as fixed text such as Terms and Conditions, if we maintain the
same as standard text, it can be reused and can be reused in any no of layout also language
translation can be maintained. That means it can be used for all the countries to print it in their
regional language.
We can create standard texts using the transaction SO10. Then to insert these standard texts in the
SAPScript choose Menu, InsertTextStandard and choose the standard text that we want to
choose.
Alternatively, we can display standard text in SAPScripts using the command:
INCLUDE ZIS_TEXT OBJECT TEXT ID ST LANGUAGE EN
Where ZIS_TEXT refers to the standard text name.
Page
SAP Scripts
How to change the Development Class/Package of a SAP Script and other than SAPScript?
For SAPScript, Execute SE03 Choose option change objects directoriesExecute. Or run
RSWBO052.
Select the layout (Object) and click on change Object Directory entry and provide the new
Development Class.
Changing the Development Class/Package for other than Scripts:
Go to Transaction SE80 Select Package (Development Class) Enter &TEMP Hit Enter
Place the cursor on the object Right Click Other Functions Object Directory Entry
Change Change the Package Save.
OR
Open the corresponding Object through it’s transaction i.e. program through SE38 and goto
Object Directory Entry Change the Development Class Save.
I made a SAPScript in development client 200 and save it corresponding to one request, now
I want to test it in Quality client 300. How can I make it?
Once it released transport request on development client 200, Import it into 300 quality client, then
we can test it as well as Create/Change can be done.
OR
Execute TCode SCC1. With the help of request number send the SAPScript from client 200 to client
300.
Page