Comandos SapScript
Comandos SapScript
Enter the following line as a command in text in a SAPscript document. The command draws a box of 17.5
CM length, 1 CM high, with 10% shading:
/: BOX WIDTH '17.5' CM HEIGHT '1' CM INTENSITY 10
The left upper corner of the box is located at the left upper corner of the main window defined in the form
of the document. The text that you type in is not automatically oriented in accordance with the box.
Whether the text fits in the box or not depends on you. If you type in three lines of text, then the bottom line
of text is likely to appear below the bottom of the box.
In a form, you can orient both text and graphical elements in the windows that you define. You therefore have much
better control of how graphics and text fit together
/: 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.
• If, in a NEW-PAGE command, you specify a page not contained in the form, the
specification is ignored.
• Take care that there are no blank lines immediately before a NEW-PAGE command. If an
implicit page break occurs within the blank lines, an unexpected blank page may be printed
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'
If the formatting turns out not to be as required, then you should check the settings in table T005X.
Assume that the paragraph N1 is defined in the style you are using. This kind of paragraph is intended for
enumerated lists and causes a sequential number to be printed.
* Proceed as follows if you want to work with the SAP R/3
system:
N1 Ensure that you have a PC
N1 Switch the PC on
N1 Click on the SAP icon using the mouse.
* You will then enter the SAP logon screen. In order to log
on here, you must carry out the following actions:
/: RESET N1
N1 Enter your user name
N1 Enter your password
N1 Select the application you want to use
This text specification would be output as follows:
Proceed as follows if you want to work with the SAP R/3
system:
1. Ensure that you have a PC
2. Switch the PC on
3. Click on the SAP icon using the mouse.
You will then enter the SAP logon screen. In order to log on here, you must carry out the following actions:
1. Enter your user name
2. Enter your password
3. Select the application you want to use
If there is no RESET command between the two sections, then the two lists would be numbered in a single
sequence:
Proceed as follows if you want to work with the SAP R/3
system:
1. Ensure that you have a PC
2. Switch the PC on
3. Click on the SAP icon using the mouse.
You will then enter the SAP logon screen. In order to log on here, you must carry out the
following actions:
4. Enter your user name
5. Enter your password
6. Select the application you want to use
Including Other Texts: INCLUDE To include the contents of another text into the current text, use the INCLUDE
control command. SAPscript still treats the text to be included as a separate text. The text is copied over only at the
point at which the output is formatted.
Thus the use of the INCLUDE command always ensures that the most current version of a text is included into the
output, since the text is not read and inserted until the output is formatted.
Syntax:
/: INCLUDE name [OBJECT o] [ID i] [LANGUAGE l] [PARAGRAPH p]
[NEW-PARAGRAPH np]
You must specify the name of the text to be inserted. It can be up to 70 characters long. If the name of the text
contains spaces, then you must enclose it in quotes as a literal value. You can, alternatively, specify the name via a
symbol. All remaining parameters in the INCLUDE command are optional. If an optional parameter is not specified,
then SAPscript uses default values as applicable for the calling environment.
/: INCLUDE MYTEXT
The text MYTEXT is included in the language of the calling text.
/: INCLUDE MYTEXT LANGUAGE 'E' PARAGRAPH 'A1'
The text with the name MYTEXT and the language E is included, regardless of the language of the calling
text. The paragraph format A1 will be used as the standard paragraph type for this call.
Optional parameters:
• LANGUAGE
If this parameter is not specified, then the language of the calling text or the form language are used for the text
to be included. If the language is specified, then the text will be fetched in this language, regardless of the
language of the calling text.
• PARAGRAPH
The text to be included is formatted using the style allocated. The PARAGRAPH parameter can be used to
redefine the standard paragraph for this style for the current call. All *-paragraphs in the included text will then
be formatted using the paragraph specified here.
• NEW-PARAGRAPH
The first line of the text to be included will be given this format indicator, as long as it is not a comment or
command line. If the optional PARAGRAPH parameter (see above) is not specified, then all *-paragraphs of the
included text will also be formatted using the paragraph specified in the NEW-PARAGRAPH command.
• OBJECT
In order to completely specify a text, information about the text object is also required. There are a number of
restrictions and other rules that depend on the object type of the calling text:
• Any kind of text can be included in a form. If no object is specified, then TEXT will be
used (standard texts).
• In the case of a document text (DOKU object), you can include only document texts. This
object type is also assumed if no object is specified in this environment.
• Only hypertexts and document texts can be included in a hypertext (DSYS object). If the
OBJECT parameter is missing, then DSYS is used as the default value.
• In the other kinds of text you can include only standard texts (TEXT object), document
texts or hypertexts. If there is no specification, then the default object is TEXT.
• ID
The text ID is a part of the text key, which permits further text objects within a given object. If no ID is
specified, then the default include ID is used from the TTXID table for the calling text. If there is no entry in
this table, then the text ID of the calling text is used.
The following consistency check is applied both to the ID and the object:
• All text IDs are allowed in a form.
• In document texts, only document texts may be included that have text IDs TX (general texts) or UO
(authorization objects) and also other document texts with the same text ID as the calling document text.
• In DSYS texts, all DSYS texts can be included, whatever ID they have. Document texts to be included must
have one of the IDs TX or UO.
• Into the other texts, standard texts with any allowable text ID, DSYS texts with all IDs, and document texts
with the IDs TX and UO can be included.
The INCLUDE command returns a status code in the SAPSCRIPT-SUBRC symbol:
• 0: the text include was successful.
• 1: the command could not be executed because it contained syntax errors.
• 2: the rules governing the text to be included were not followed (see above).
This value cannot occur if the command is used in a SAPscript form.
• 4: the specified text could not be found.
If the INCLUDE text has a style assigned to it, in both cases, the system always takes the paragraph and
character formats from the directly assigned style.
Formatting Addresses: ADDRESS The ADDRESS - ENDADDRESS control command formats an address
according to the postal convention of the recipient country defined in the COUNTRY parameter. The reference
fields are 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
The parameter values contain both formatting and address information. The address data are formatted for output
according to the data in the following parameters:
• TYPE
• FROMCOUNTRY
• COUNTRY
• LANGUAGE
• PRIORITY
• DELIVERY
• LINES
For more information, see the documentation for the SAP function module ADDRESS_INTO_PRINTFORM.
If DELIVERY is not specified and if a POBOX is specified, then the POBOX is used in an address instead of a
STREET.
Parameters
• DELIVERY
Means that the address should be formatted as a complete delivery address, using the street name and number
rather than the P.O. Box.
• TYPE
Specifies the type of address. The following types are possible:
4. Normal address (ADRS1). This is the address of a company or organization. It corresponds to the
address structure that is expected in most SAP applications.
5. Private or personal address (ADRS2). This is the address of a natural person, a private or home
address.
6. Company addressDienstadresse (ADRS3) with contact person. This is the address of a colleague
or contact within a company or organization. The company name should be specified in the TITLE
and NAME fields; the ATTN: contact person should be named in PERSON and TITLE.
Should you enter another address type or leave the field blank, then type 1 is used for formatting.
• PARAGRAPH
Specifies the paragraph format to be used for outputting the address. If this parameter is not given, the address
will be output using the default paragraph format.
• PRIORITY
Specifies which of the address lines may be omitted should this be necessary. Any combination of the following
codes may be specified. The order in which you list the codes determines the order in which address lines are
left out.
The codes are as follows:
A Title
P Mandatory empty line
4 Name4
3 Name3
R Region
T Neighborhood, administrative section of a city (CITY2)l
D Department
L Country name
C Post code or zip code
2 Name2
B P.O. Box (Japan only)
S Street name and number or P.O. Box, depending upon DELIVERY parameter
N Name and form of address of natural person (PERSON and TITLE)
I Location information in LOCATION
O City
• LINES
Specifies how many lines may be used for formatting the address. If there are too few lines available to allow all
the address data to be formatted, then the data specified in the PRIORITY parameter are omitted. If there is no
LINES parameter and if this command is in a form window of a type other than MAIN, then the number of lines
available for formatting the address are automatically calculated based on the current output position and the
size of the window.
• TITLE
Title or form of address. Used only with addresses of types 1 and 3.
• NAME
Up to four names may be given, separated by commas. Used only with addresses of types 1 and 3.
• PERSON
Name of the addressee. Used only for addresses of type 2 (private or personal address) or type 3 (company
contact address). In type 3 addresses, use PERSON for the name of your contact person: ‘Attn: Mr. Jeffries’.
The name fields should be used for the company address.
• PERSONNUMBER
Personal number. Can be used only for address types 2 or 3 (private or personal address).
• TITLE (with PERSON)
Title of the addressee. Can be used only for address types 2 or type 3 (private or personal address).
• DEPARTMENT
Department of the addressee. Can be used only for address type 3 (company address).
• STREET
Street name.
• HOUSE
House number for the corresponding street.
• LOCATION
Additional location information, such as the building, "Upstairs Apartment" and so on. Appears on its own line
in the address.
• POBOX
P. O. Box
• CODE
The post code / zip code of the P. O. Box if this differs from the post code / zip code of the recipient.
• CITY
The city in which the destination P.O. Box is located if this differs from the city of the recipient.
• POSTCODE
Post code / zip code of the recipient.
• CITY
Addressee’s city. city1 is expected to be the city; city2 is the neighborhood or administrative section, if
required.
• NO_UPPERCASE_FOR_CITY
Default = NO_UPPERCASE_FOR_CITY ‘ ‘
Usually, the system prints the city and country names of foreign addresses in uppercase (
NO_UPPERCASE_FOR_CITY ‘ ‘ ).
You can use this parameter to force the system to output city and country name unchanged
(uppercase/lowercase).
( NO_UPPERCASE_FOR_CITY ‘X’ )
• REGION
This allows an administrative region, county, province, or state etc. to be specified.
• COUNTRY
Specifies the recipient country, i.e. the country according to whose postal conventions the address is to be
formatted.
• COUNTRY_IN_REC_LANG
This flag tells the system to use the recipient language for the country name.
( COUNTRY_IN_REC_LANG ‘X‘ )
( Default: Recipient language is not used: COUNTRY_IN_REC_LANG ‘ ‘ )
• LANG_FOR_COUNTRY
Default = Space
Use this parameter to explicitly set the language in which to print the country name of a foreign address. By
default, the system uses the language of the sending country.
• LANGUAGE
Language code of the language of the recipient country, if it differs from that of the recipient COUNTRY.
Example: addresses in Switzerland. Standard SAP language codes are used; you can display these in the initial
SAPscript text processing screen or in table T002.
• FROMCOUNTRY
Specifies the language to be used for formatting the name of the recipient country. For most European countries,
the recipient country is specified by placing the international car registration letters in front of the post code and
separating them from the post code with a hyphen. You must always specify the sender country.
• ADDRESSNUMBER
The number is used to index a central address file, from which the desired address is read instead of using the
set of the above fields. You can find more information on this facility in the documentation for the function
module ADDRESS_INTO_PRINTFORM.
You use this one parameter instead of the set of parameters described before.
/: ADDRESS
/: TITLE 'Firma'
/: NAME 'Schneider & Co', 'Finanzberatung'
/: STREET 'Kapitalgasse 33'
/: POBOX '12345' CODE '68499'
/: POSTCODE '68309'
/: CITY 'Mannheim'
/: COUNTRY 'DE'
/: FROMCOUNTRY 'DE'
/: ENDADDRESS
This produces the following output address:
Firma
Schneider & Co
Finanzberatung
Postfach 12345
68499 Mannheim
If the DELIVERY parameter is specified on the ADDRESS command, then the street name and number
will appear in the address in place of the P. O. Box number.
Firma
Schneider & Co
Finanzberatung
Kapitalgasse 33
68309 Mannheim
SAPscript makes an internal call to the ADDRESS_INTO_PRINTFORM function module for formatting
the address. If the result is not as expected, you should check the settings for this function module (see the
function module documentation).
• If the main window already contains some output then a newly specified header text takes
effect on the next page only.
• The same applies to the deletion of a header text. If a header text has already been output
on the current page then it cannot be retracted.
• Header texts should not be employed in texts that are printed from applications programs,
such as reminder texts, order texts. These applications programs can also work with header
texts via the form interface, which may lead to unexpected results.
• Assuming there is still sufficient space in the main window, a newly specified footer text
will also be printed on the current page.
• Footer texts should not be employed in texts that are printed from applications programs,
such as reminder texts, order texts. These applications programs can also work with footer
texts via the form interface, which may lead to unexpected results.
Conditional Text: IF
You can use the IF control command to specify that text lines should be printed only when certain conditions are
met. If the logical expression contained within the IF command is true, then the text lines enclosed by the IF...
ENDIF command pair are printed. Otherwise they are ignored.
Syntax:
/: IF condition
:
:
/: 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
Evaluation of both the individual logical expressions and of the combinations of expressions is performed strictly
from left to right. There are no precedence rules. Bracketed expressions are not supported.
The comparison is always performed on literal values, that is, the symbols are formatted as character strings before
they are compared. This is particularly significant in the case of program symbols, because the formatting of these
may depend on various parameters. For example, the formatted form of a currency field employs a variable number
of decimal places and a variable ‘decimal point’ symbol (a period or a comma) depending on the applicable currency
key.
You can extend the IF command with the ELSE command to allow text lines to be specified that you want to print in
case the condition is false. If the condition is true, the text lines enclosed by the IF and ELSE commands are
formatted; otherwise the text lines enclosed by the ELSE and ENDIF commands are formatted.
Syntax:
/: IF condition
:
/: ELSE
:
/: ENDIF
The ELSEIF command allows you to specify multiple cases.
Syntax:
/: IF condition
:
/: ELSEIF condition
:
/: ELSE
:
/: ENDIF
You can use any number of ELSEIF commands within one compound IF.. ENDIF control command. The use of an
ELSE command is then optional.
• You must not extend a condition over more than one line. Both the IF or ELSEIF
command and the attached condition must be completely contained within a single line.
• You can nest IF commands.
• You must terminate an IF command with an ENDIF command. If you forget this, there
will be no more output following the IF command if the condition is false.
• If a syntax error occurs in the interpretation of this command, then the command is not
executed. This may have an unexpected effect on the subsequent text output. For example, if
the IF statement is incorrect, then all following ELSEIF and ELSE commands will be ignored,
since the opening IF command is ‘missing’. This will cause all the text lines attached to the
ELSEIF and ELSE commands to be printed.
From within a SAPscript form, a subroutine GET_BARCODE in the ABAP program QCJPERFO is called.
Then the simple barcode contained there (‘First page’, ‘Next page’, ‘Last page’) is printed as local variable
symbol.
Definition in the SAPscript form:
/: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
/: USING &PAGE&
/: USING &NEXTPAGE&
/: CHANGING &BARCODE&
/: ENDPERFORM
/
/ &BARCODE&
Coding of the calling ABAP program:
REPORT QCJPERFO.
PAGNUM = IN_PAR-VALUE.
NEXTPAGE = IN_PAR-VALUE.
IF PAGNUM = 1.
OUT_PAR-VALUE = ‘|’. "First page
ELSE.
OUT_PAR-VALUE = ‘||’. "Next page
ENDIF.
IF NEXTPAGE = 0.
OUT_PAR-VALUE+2 = ‘L’. "Flag: last page
ENDIF.
For details on summing and carrying forward, see Summing and Carrying Forward is Incorrect.
Current Date
&DATE& The current date is displayed. It is formatted according to the specifications found in the user master
data. You can adapt this format to your own requirements by specifying a date mask (SET DATE
MASK) or by using a country-specific formatting option (SET COUNTRY).
The current value for this symbol is taken from the SY-DATUM field. This value is not copied
every time that the date is called, but only at the following times:
• When printing starts (OPEN_FORM, PRINT_TEXT)
• When symbols are replaced in the text editor
• When a text is exported in the ASCII or RTF format
• When the TEXT_SYMBOL_REPLACE function module is called (optional)
Current Time
&TIME& The current time is printed in the form hours:minutes:seconds. Each of the components for hours,
minutes, and seconds consists of two digits, using a leading zero if necessary. You can adapt this
format to your own requirements by specifying a time mask (SET TIME MASK).
The value for the time field is taken from the SY-UZEIT field. This value can be copied over only at
particular times (c.f. DATE ).
Spaces
&SPACE& You can use this symbol to generate a string of space characters. You must pass the number of space
characters required with the symbol. If you leave out the number, then no spaces are printed.
Underline
&ULINE& You can use this symbol to insert a string of underline characters into the output text. You must pass
the number of underline characters required with the symbol. If you leave out the number, then just
one underline character is printed.
Vertical Line
&VLINE& You can use this symbol to insert a string of vertical line characters into the output text. You must
pass the number of vertical line characters required with the symbol. If you leave out the number,
then just one vertical line character is printed.
Output Length
If you need only a part of the symbol value, or the output has to fit into a 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)&
The SYST-UNAME field contains the logon name of a user called Einstein . The Dictionary entry for this
field contains an output length of 12.
&SYST-UNAME&... -> Einstein...
&SYST-UNAME(9)&... -> Einstein...
&SYST-UNAME(*)&... -> Einstein ...
The ITCDP-TDULPOS field contains the value -100.00. The ABAP Dictionary definition for this field
includes a leading sign.
&ITCDP-TDULPOS& -> 100.00-
&ITCDP-TDULPOS(S)& -> 100.00
Omitting Leading Zeros
Certain symbol values are printed with leading zeros. If you want to suppress these, use the Z option.
Syntax
&symbol(Z)&
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 spaces are completely removed. The results are the
same as those of the ABAP command CONDENSE.
Syntax:
&symbol(C)&
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.6
&EKPO-MENGE&(.4) -> 1,234.5600
&EKPO-MENGE&(.0) -> 1,235
Omitting the Separator for ‘Thousands’ Symbols of the DEC, CURR, INT, and QUAN data types are normally
formatted with the a ‘thousands’ separator character. The T option allows you to omit this separator 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
Right-Justified Output Symbol values other than numeric values are normally formatted left-justified. To specify
right-justified formatting, use the R option. You must use this option in conjunction with an output length
specification.
Syntax
&symbol(R)&
Changing the Value of a Counter You 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)
If you want to change the value of a counter variable without actually printing the new value, use this formatting
option together with an additional option to set the output length to 0 (see above). If you want to set a counter
variable to some specific value, use the DEFINE control command.
Date Mask
To format date fields, use the SAPscript SET DATE MASK command. Executing this command causes all
subsequent date fields to be printed with the specified formatting.
Syntax
/: SET DATE MASK = 'date_mask'
The following templates may be used in the date mask:
DD day (two digits)
DDD name of day (abbreviated)
DDDD name of day (written out in full)
MM month (two digits)
MMM name of month (abbreviated)
MMMM name of 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)
Any other characters occurring in the mask are interpreted as simple text and are copied directly to the output.