Register Login

Script Commands in SAP ABAP

Updated May 18, 2018

Script Commands.

Defining a variable

DEFINE &CUST& = '00000021'.

Define and insert a standard text:

Standard texts is predifined textst that can be used in more than one form. Standard texts are can be created, changed and displayed using transaction SO10.

The text ID is used to callsify texts.

To include a stadard text in a form, use the INCLUDE command:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD

When formatting the standard text the PARAGRAPH parameter is used. To center the text use:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD LANGUAGE EN PARAGRAPH C.

Formatting addresses

The ADDRESS-ENDADDRESS command formats addresses according to the postal norms of the recipient's country, as defined in the country parameter.

ADDRESS DELIVERY PARAGRAPH AD
NAME  &KNA1-NAME&
STREET  &KNA1-STRAS&
POSTCODE  &KNA1-PSTLZ&
CITY  &KNA1-ORT01&'
COUNTRY    &KNA1-LAND1&
FROMCOUNTRY     'DE'
ENDADDRESS

Avoiding pagebreaks in a paragraph

/: PROTECT
:
:
/: ENDPROTECT

The text lines to be protected are enclosed between the two commands

Conditonal text ouput IF - ENDIF

You can use IF/ENDIF like in a normal ABAP program

/: IF condition
:
:
/: ENDIF

and

/: IF condition
:
/: ELSE
:
/: ENDIF

Example:

/: IF &SPFLI-CITYTO& = "BERLIN"

..... put some text here

/: ENDIF

Symbols and Control commands

  • Symbols are placeholders for values that are inserted during print formatting.
  • Symbols are indentified by name surrounded by "&" and are not case sensitive

Types of symbols

System symbols

DATE Date
DAY Day
NAME_OF_DAY Name of day
MONTH Month
YEAR Year
TIME Time

HOURS Hours
MINUTES Minutes
SECONDS Seconds
PAGE Page number
NEXTPAGE Number of next pagre
DEVICE Output device
SPACE Blank space
ULINE Underline
VLINE Vertical line

Standard symbols

Standard symbols are user defined and are maintained in table TTDG(table is not available???). You use transaction SM30 to change or display standard symbols.

An examples of standard symbols is &MFG& fot "Yours faithfully"

Standard text

Standard texts is predifined texts that can be used in more than one form. Standard texts are can be created, changed and displayed using transaction SO10.

The text ID is used to classify texts.

To include a standard text in a form, use the INCLUDE command:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD

When formatting the standard text the PARAGRAPH parameter is used. To center the text use:

/: INCLUDE

= Object, ID, Language, Paragraph

Example:

/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD LANGUAGE EN PARAGRAPH C.

Name: Z_BC460_EX4_HF

Object: Text

Text id: SDVD (Text id from SO10)

Language: EN

Paragraph: C (Centered)

Tip: You can use menu Insert->Text->Standard to make it easier to insert the text

Program symbols

Program symbols are for contents of database fields or global program symbols. When you print the form, data from the database tables are printed isntead of the symbols.

In the print program:

TABLES: kna1.

In the form:

&KNA1-NAME1&

Formatting

&SYMBOL& No formatting
&SYMBOL+4& Offset - Output begins here. Offset refers to formatted value
&SYMBOL(5)& Length - Output data in the specified length
&SYMBOL(I)& Suppress initial value - If the field has been initialized, nothing is output
&SYMBOL(Z)& Suppress leading zeros
&SYMBOL(C)& Compress blank spaces - Consecutice spaces are compressed into a single space. Leading spacesare suppressed.

&SYMBOL(R)& Right align output
&SYMBOL(S)& Operators are suppressed
&SYMBOL(*)& Dictionary length - The data length is defined by the ABAP dictionary
&SYMBOL(8.2)& Decimal format. Length 8 decimals 2
&'text1'SYMBOL'text2'& Text can be inserted before and after the symbol

Control commands

Control command are used to modify text output. Use format key /: in the format column.

/: INCLUDE
/: DEFINE
/: ADDRESS....ENDADDRESS
/: PROTECT.....ENDPROTECT

/: NEW-PAGE
/: IF....ENDIF
/: CASE...ENDCASE

Examples of control commands

INCLUDE

INCLUDE name

Parameters:

OBJECT E.g. TEXT, DOKU (Document), DSYS (Hypertext).
ID Text ID -Text ID is a way to group texts - Se transaction SO10
LANGUAGE If the parameter is not specefied, the logon language will be used

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.

Object
ID
Language
Paragraph
Standard texts are maintained in transaction SO10.

Example 1:

You have created a standard text in SO10 Named MYTEXT and with Text Id ST

/: INCLUDE MYTEXT OBJECT text ID st

Example 2:

You can also use a dynamic name so that you can retreive a ext depeding of the name variable:

/: INCLUDE &SCUSTOM-NAME& text ID st.

Depending on the name in the variable &SCUSTOM-NAME& different texts will be shown. Note that a text with the name in the variable &SCUSTOM-NAME& name must be created in SO10.

DEFINE

/: DEFINE &SYMBOL& = 'String1 String2'

/: DEFINE &CUST& = '00000021'.

ADDRESS-ENDDRESS

The ADDRESS-ENDADDRESS command formats addresses according to the postal norms of the recipient's country, as defined in the country parameter.

/: ADDRESS DELIVERY PARAGRAPH AD
/: NAME &KNA1-NAME&
/: STREET &KNA1-STRAS&
/: POSTCODE &KNA1-PSTLZ&
/: CITY &KNA1-ORT01&
/: COUNTRY &KNA1-LAND1&
/: FROMCOUNTRY 'DE'
/: ENDADDRESS

Time Date and decimal format

Examples:

/: SET TIME MASK = 'HH:MM'
/: SET DATE MASK = 'DD.MMMM.YYYY'
/: SET COUNTRY 'USA'

Frames, lines and shading

BOX

Draws a box

Syntax:

/: BOX

The intensity is the grey scale of the box as %. The frame parameters is the thickness of the frame. Default is 0.

Each of the paramteters ypos, xpos, width, height and frame muts be followed of the measurement unit:

TW (twip)
PT (point)
IN (inch)
MM (millimeter)
CM (centimeter)
LN (line)
CH (character).

Examples:

/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY 10 FRAME 0 TW

/: BOX FRAME 10 TW

Draws a frame around the current window with a frame thickness of 10 TW (= 0.5 PT).

/: BOX INTENSITY 10

Fills the window background with shading having a gray scale of 10 %.

/: BOX HEIGHT 0 TW FRAME 10 TW

Draws a horizontal line across the complete top edge of the window.

/: BOX WIDTH 0 TW FRAME 10 TW

Draws a vertical line along the complete height of the left hand edge of the window.

/: BOX WIDTH '17.5' CM HEIGHT 1 CM FRAME 10 TW INTENSITY 15

/: BOX WIDTH '17.5' CM HEIGHT '13.5' CM FRAME 10 TW
/: BOX XPOS '10.0' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW
/: BOX XPOS '13.5' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW

Draws two rectangles and two lines to construct a table of three columns with a highlighted heading section.

POSITION and SIZE

You can use the POSITION and SIZE commands to set default parmeters for a box. This can be usefull if you have several boxes that share the same parameters.

Example:

/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM
/: SIZE HEIGHT '2' MM WIDTH '76' MM
/: BOX FRAME 10 TW INTENSITY 10

If you want to set the position realtively to the window use POSITION WINDOW to set the position to the top/left start of the window. Then use POSITION to set the current position relatively to the start of the Window. Note that you uses "+" or "-" in the ORIGIN position to the set the position relatively.

/: POSITION WINDOW
/: POSITION XORIGIN '+5' MM YORIGIN '+10' MM

the position is now 5 MM from the left and 10 MM from the top of the window.

NOTE: After using the position command you can move the current position realtively to the last used position

/: POSITION XORIGIN '+10' MM YORIGIN '+20' MM

Now the position will be X = 15 and Y = 30

Drawing a line

You can draw a line by setting the Height or Width of a box to 0 and add a frame. E.g. a horizontal line:

/: SIZE HEIGHT '0' MM WIDTH '200' MM
/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100

Window and Page

WINDOW sets the values for the width and height to the values of the current window (default setting).

PAGE Sets the values for the width and height to the values of the current output page.

Examples:

/: SIZE WINDOW

Sets WIDTH and HEIGHT to the current window dimensions.

/: SIZE WIDTH '3.5' CM HEIGHT '7.6' CM

Sets WIDTH to 3.5 cm and HEIGHT to 7.6 cm.

/: POSITION WINDOW
/: POSITION XORIGIN -20 TW YORIGIN -20 TW
/: SIZE WIDTH +40 TW HEIGHT +40 TW
/: BOX FRAME 10 TW

A frame is added to the current window. The edges of the frame extend beyond the edges of the window itself, so as to avoid obscuring the leading and trailing text characters.

Calling a form from SapScript (*****)


/:DEFINE &CUST& = '00000021'.
/:PERFORM GET_NAME IN PROGRAM Z_BC460_EX4_HF
/:  USING &CUST&
/:  CHANGING &NAME&
/:ENDPERFORM.

Dear &NAME&

The ABAP routine could be defined as follows:

IMPORTANT: The structure itcsy must be used for the parameters.

REPORT Z_HENRIKF_SCRIPT_FORM .
tables scustom.
form get_name tables in_tab structure itcsy
out_tab structure itcsy.

read table in_tab index 1.

select single * from scustom
where id = in_tab-value.

if sy-subrc = 0.

read table out_tab index 1.
move scustom-name to out_tab-value.
modify out_tab index sy-tabix.
else.

read table out_tab index 1.
move 'No name' to out_tab-value.
modify out_tab index sy-tabix.
endif.

**  You could also fill the ouput parameter table this way

READ TABLE out_par WITH KEY 'NAME1'.
out_par-value = l_name1.

MODIFY out_par INDEX sy-tabix.

endform.

Note that if you use more than one parameter you must use Using or Changing before every parameter !

/: PERFORM

IN PROGRAM

/: USING &INVAR1&
/: USING &INVAR2&
......

/: CHANGING &OUTVAR1&
/: CHANGING &OUTVAR2&
......

/: ENDPERFORM

Structure of a print program

The print program is used to print forms. The program retieves the necesary data from datbase tables, defines the order of in which text elements are printed, chooses a form for printing and selects an output device and print options.

Open form printing - Must be called before working with any of the other form function modules.

call function 'OPEN_FORM'.....

Must be ended with function module CLOSE FORM

*To begin several indentical forms containing different data within a single spool request, begin each form using START_FORM, and end it using END_FORM

call funtion 'START_FORM'.....

Write text elements to a window of the form

call function 'WRITE_FORM'.....

Ends form

call funtion 'END_FORM'.....

Closes form printing

call function 'CLOSE_FORM'....

Examples of function calls

OPEN FORM

CALL FUNCTION 'OPEN_FORM'

EXPORTING

*         APPLICATION                                                = 'TX'
*         ARCHIVE_INDEX                                          =
*         ARCHIVE_PARAMS                                      =
           DEVICE                                                           = 'PRINTER'
           DIALOG                                                           = 'X'
*         FORM                                                               = ' '
*         LANGUAGE                                                     = SY-LANGU
          OPTIONS                                                          = OPTIONS
*         MAIL_SENDER                                               =
*         MAIL_RECIPIENT                                           =
*         MAIL_APPL_OBJECT                                     =
*         RAW_DATA_INTERFACE                              = '*'
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
OTHERS                                                                       = 10
.
START_FORM

CALL FUNCTION 'START_FORM'
EXPORTING
*         ARCHIVE_INDEX                                             =
           FORM                                                                 = 'MY_FORM'
*          LANGUAGE                                                      = ' '
*         STARTPAGE                                                      = ' '
*         PROGRAM                                                         = ' '
           MAIL_APPL_OBJECT                                      =
IMPORTING
*         LANGUAGE                                                        =
EXCEPTIONS
FORM                      = 1
FORMAT                 = 2
UNENDED             = 3
UNOPENED          = 4
UNUSED               = 5
OTHERS                = 6

WRITE_FORM

See 'WRITE_FORM'

END_FORM

CALL FUNCTION 'END_FORM'

IMPORTING
*        RESULT                                                 =
EXCEPTIONS
*        UNOPENED                                          = 1
          BAD_PAGEFORMAT_FOR_PRINT   = 2
         OTHERS                                                 = 3

CLOSE_FORM

Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
INCLUDE STRUCTURE ITCPP.
DATA END   OF RESULT.

CALL FUNCTION 'CLOSE_FORM'
IMPORTING
           RESULT                                                = RESULT
*         RDI_RESULT                                       =
TABLES
*         OTFDATA                                              =
EXCEPTIONS
*         UNOPENED                                         = 1
           BAD_PAGEFORMAT_FOR_PRINT = 2
*         SEND_ERROR                                   = 3
*         OTHERS                                               = 4.


CONTROL_FORM - Calling Commands Using a program

The function module CONTROL_FORM can be used to create SapScript control statements from within an ABAP program.

Example:

call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'PROTECT'.

call function 'WRITE_FORM'.....................

call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'ENDPROTECT'.

Styles

Styles are used to predefine paragraph and character formats for forms. SAP provides several standard styles e.g. for Address includes, on-line documentation and so on. You can define your own styles.

To find styles, create styles and maintaine styles, use transaction SE72.

You assign style to a text by using menu Format -> Style

You can make temporary style changes using the control command /: STYLE

Using graphics in SapScript

Use transaction SE78 to inmport graphics to SAP.

In the form painter, you can either include directly to the form using menu Edit->Graphic->Create or using the INCLUDE statement in a window.

To use an INCLUDE stanment, goto into the woindow script editor and use menu Include->Graphic. The include can look like this for a bitmap:

/: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON

Modifications

Considerations in connection with modifications

The standard SAP print program should only be changed when it is absolutely necessary. If additional data is needed, these can in many cases be retrieved using a a PERFORM statement in the form instead of changing the print program..

There can be the following reasons to change the print program:

Structureal changes

New text eloements are needed
Print program to be used to print additional forms

Determine/change which forms and printprograms that are used for printing

The forms and print programs for a given output type and application can be found in table TNAPR Processing programs for output

Use view V_TNAPR in (Transaction SE30) to change entries.

Import/Export SapScript form from PC file

Use ABAP program: RSTXSCRP

SD - Finding the name of the print program
For SD dopcuments you can use table TNAPR top find the name of the a
printprogram


×