SET ( SAP ABAP Keyword)

SET is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.

SET

Effect
Sets different processing parameters

Basic forms

 

————————————————
SET

Basic form 1
SET PF-STATUS pfstat.

 

Additions

1. … EXCLUDING f or … EXCLUDING itab
2. … IMMEDIATELY

Effect
Sets
a GUI (Graphical User Interface) status pfstat which can be up to 8
characters long. There are many of these statuses in the GUI of a
program. Each one describes which functions are available and how you
can select these via menus and menu bars or by pressing function keys
or pushbuttons. For further information about this, refer to the Menu
Painter documentation.

Setting a status makes the functions contained therein selectable.

This method allows you to vary the available functions according to the current screen, list level and/or previous program flow.

The current status is stored in the system field SY-PFKEY .

A status remains valid until reset.

Example
Event in program:

START-OF-SELECTION.
SET PF-STATUS ‘MAIN’.
WRITE SY-PFKEY.

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN ‘F001’.
SET PF-STATUS ‘0001’.
WRITE SY-PFKEY.

ENDCASE.

Produces
a list (contents MAIN ) with a GUI framework which allows you to select
functions assigned to the the status MAIN . If you choose the function
code F001 (e.g. from the menu or by pressing a pushbutton), you trigger
the event AT USER-COMMAND . This generates a details list (contents
0000) with a GUI framework which allows you to select functions
assigned to the status 0001 . On returning from the details list to the
basic list the status MAIN is reactivated.

Example
PBO module:

MODULE PBO_100 OUTPUT.
SET PF-STATUS ‘S001’.
ENDMODULE.
Displays the screen 100 with a GUI framework which allows you to select functions assigned to the status S001 .

Notes
If
no GUI is defined in the list processing (or it is deactivated with SET
PF-STATUS SPACE ), the system supplies a standard user interface.
This
statement converts the contents of the field pfstat to type C. The
converted value is used to search for the desired status. Since the
conversion employs the standard conversion rules as for MOVE , you
should use a field similar to type C (e.g. type C or N) for pfstat to
avoid unwanted conversions. In this case, a field of type I with a
value of 12 would give the key ‘ 12 ‘.

Addition 1
… EXCLUDING f
… EXCLUDING itab

Effect
Deactivates
one or more of the status functions, so that they cannot be selected.
Specify the appropriate function codes using one of the following:

a field f or a literal which contains a function code
an internal table itab which contains several function codes

This method allows you simply to modify the selectable functions of a status at runtime.

Example

DATA: BEGIN OF TAB OCCURS 10,
FCODE(4),
END OF TAB.

REFRESH TAB.
MOVE ‘DELE’ TO TAB-FCODE.
APPEND TAB.
MOVE ‘AUSW’ TO TAB-FCODE.
APPEND TAB.
SET PF-STATUS ‘STA3’ EXCLUDING TAB.

Sets the status STA3 which renders the functions with the function codes DELE and AUSW inactive.

Addition 2
… IMMEDIATELY

Effect
List
processing: The status becomes effective for the last list displayed
and is not flagged for the next details list. In screen processing,
this addition has no effect because every status becomes immediately
effective anyway.

Example
Event in program:

START-OF-SELECTION.
SET PF-STATUS ‘MAIN’.
WRITE SY-PFKEY.

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN ‘F002’.
SET PF-STATUS ‘0002’ IMMEDIATELY.
EXIT.

ENDCASE.

Selecting
the function F002 in the basic list (contents MAIN , status MAIN )
redisplays the basic list, but this time with the status 0002 .

Note
Without the addition … IMMEDIATELY , the old status MAIN becomes active again.

———————————————————————-
SET

Basic form 2
SET TITLEBAR f.

Addition

… WITH g1 g2 … gn

Effect
Sets a screen title

You
use the Menu Painter to edit these program-driven screen headers. If
there is a text for the three-character title, it is displayed in the
title bar of the next screen.
If the program is in an external
subroutine, the name of the main program is used as the program name.
In contrast, a function module sets a title belonging to the function
group.
A set title remains valid within a transaction until you call SET TITLEBAR again.
After SET TITLEBAR , the system field SY-TITLE contains the current screen header.
SY-TITLE can be up to 70 characters long.

Note
Here,
the contents of the field f are converted to a value of type C
(according to the standard conversion rules) and the desired title is
found using this value. It is therefore advisable to use a field
similar to type C (e.g. type C or N) to avoid unwanted conversions. For
example, a field of type I with a value of 9 would give the key ‘ 9 ‘.

Addition
… WITH g1 g2 … gn

Effect
Allows
you to build up to 9 parameters into the header, using the variables
&1 to &9. Starting on the left, all & characters are
replaced by the corresponding parameter (i.e. the first & is
replaced by the first parameter specified under WITH and so on). If you
do not want a & character to be replaced, you must specify it twice
( && ).
If a parameter is missing for one of the title variables, it is replaced by a blank.
On
account of the upper limit of 70 characters (the length of SY-TITLE ,
&1 characters can be lost when replacing with WITH .

Example

DATA: PAR1(4) VALUE ‘par1’,
PAR2(4) VALUE ‘par2’.

SET TITLEBAR ‘ABC’ WITH PAR1 PAR2 ‘par3’.

If the title “ABC” contains

“Title & &1 &3 intermediate text & &2 && & &4”

the above example would produce a title bar with the text

“Title par1 par1par3 intermediate text par2 par2 & par3 ” .

—————————————————————-
SET

Basic form 3
SET SCREEN scr.

Effect
In ABAP/4 dialogs, this sets the next screen number.

In addition to the current screen , processes the screen with the number scr .

Example

SET SCREEN 200.

Note
To
leave a screen called with CALL SCREEN or to return from a branch to
the transaction selection screen, you must use the statement

SET SCREEN 0.

or

LEAVE TO SCREEN 0.

——————————————————————–
SET CURSOR

Variants

1. SET CURSOR FIELD f.
2. SET CURSOR LINE lin.
3. SET CURSOR col lin.

Effect
Sets the cursor dynamically in display (screen program or list).

Variant 1
SET CURSOR FIELD f.

Additions

1. … OFFSET off
2. … LINE lin

Effect
Places the cursor dynamically at the start of the field g which is specified in the field f .

Note
With step loops and in list processing, you also need the addition … LINE lin .

Addition 1
… OFFSET off

Effect
Offsets the cursor position by off columns from the start of the field g which is specified in the field f (1st column = 0).

Addition 2
… LINE lin

Effect
Places
the cursor in the field g (specified in the field f ) of the loop line
lin with step loops, or of the absolute list line lin ( SY-LILLI ) in
the case of list processing.

Notes
Specifying LINE lin is
possible only with step loops and in list processing. In these cases,
it is necessary. The name specified in the field f must be a global
field. For field symbols and reference parameters, you must use the
name of the global field which is assigned to the field symbol or
parameter at the time of output (i.e. with ” WRITE “).

Examples
1. Place the cursor on a screen field.

DATA F(5) VALUE ‘MODUS’.
DATA MODUS(10) VALUE ‘1234567890’.

MODULE set_cursor OUTPUT.

SET CURSOR FIELD F.

or

SET CURSOR FIELD ‘MODUS’.

Both statements place the cursor at the beginning of the field MODUS .

SET CURSOR FIELD F OFFSET 2.
or

SET CURSOR FIELD ‘MODUS’ OFFSET 2.

Both statements place the cursor on the third character (in this case the digit “3”) of the field MODUS .

ENDMODULE.

2. Place the cursor at the beginning of a field when selecting a line in list processing.

MOVE ‘MODUS’ TO F.
MOVE ‘1234567890’ TO MODUS.

DO 10 TIMES.
NEW-LINE. POSITION SY-INDEX WRITE MODUS.
ENDDO.

AT LINE-SELECTION.
SET CURSOR FIELD F LINE SY-LILLI.

or

SET CURSOR FIELD ‘MODUS’ LINE SY-LILLI.

Both statements place the cursor at the beginning of the field MODUS on this line when the user double-clicks.

SET CURSOR FIELD F LINE SY-LILLI OFFSET 2.
or

SET CURSOR FIELD ‘MODUS’ LINE SY-LILLI OFFSET 2.

Both
statements place the cursor on the third character (in this case the
digit “3”) of the field MODUS on this line when the user double-clicks.

Variant 2
SET CURSOR LINE lin.

Additions

1. … OFFSET off

Effect
Places
the cursor dynamically in the loop line lin with step loops or in the
absolute list line lin ( SY-LILLI ) in list processing. This variant is
only possible with step loops and in list processing.

Addition 1
… OFFSET off

Effect
Places the cursor off columns from the beginning of the line.

Example
Place the cursor at the beginning of the line when selecting a line in list processing.

DATA MODUS(10) VALUE ‘1234567890’.

DO 10 TIMES.
NEW-LINE. WRITE MODUS.
ENDDO.

AT LINE-SELECTION.
SET CURSOR LINE SY-LILLI.

This statement sets the cursor at the beginning of the line when the user double-clicks.

SET CURSOR LINE SY-LILLI OFFSET 2.

This
statement sets the cursor on the third column (in this case the digit
“3” of the field MODUS ) on this line when the user double-clicks.

Variant 3
SET CURSOR col lin.

Effect
Places the cursor dynamically on the column col and the line lin of the current screen .

Example

SET CURSOR 60 5.

Positions the cursor on line 5, column 60.

——————————————————–
SET

Basic form 5
SET PARAMETER ID pid FIELD f.

Effect
Writes
the contents of the field f to the global SAP memory under the key pid
. If the key already contains a value, it is overwritten.

The
key pid must consist of three characters. You can find a list of the
keys (parameters) used in the SAP system description or in the ABAP/4
Development Workbench.

Notes
The global SAP memory remains
available to the user during the entire terminal session. This means
that set values are retained when you leave a program.
You should not use the SAP memory for temporary storage of values because other modes use the same global memory.
If you need a new key (parameter), you can create this in the ABAP/4 Development Workbench.

Example

DATA: REPID(8) VALUE ‘RFSCHU01’.
SET PARAMETER ID ‘RID’ FIELD REPID.

Sets the program name, e.g. for transfer to another program.

Notes
Runtime errors

SET_PARAMETER_ID_TOO_LONG : Key longer than 3 characters.
SET_PARAMETER_ID_WRONG_TYPE : Key neither type C nor type N.
SET_PARAMETER_VALUE_TOO_LONG : Value longer than 250 characters.

—————————————————————
SET

Basic form 6
SET LANGUAGE lg.

Effect
Initializes
all text elements TEXT-nnn and all language-specific text literals
‘abcd…..'(nnn) ( nnn = text number) in the specified language.
If
the text pool does not exist in the desired language, searches in the
system language. If the text pool does not exist in the system language
either, searches in the secondary language.

Notes
The length of the texts must be the same in all languages.
The
effect is restricted to the current program and is neither extended by
an external PERFORM nor by a SUBMIT from another program.

—————————————————————-
SET COUNTRY

Basic form 7
SET COUNTRY f.

Effect
Displays
the decimal point and date in all subsequent output ( WRITE ) according
to the settings specified in the table T005X for the country ID f .

The return code value is set as follows:

SY-SUBRC = 0 The statement was successful.
SY_SUBRC = 4 The country ID was not found in table T005X .

Notes
The country must exist in table T005X . Otherwise, the formats used are “.” for the decimal point and “MM/DD/YYYY” for the date.
The
special form SET COUNTRY SPACE (or f contains SPACE ) resets the
decimal point and date display formats to the setting contained in the
current user’s master record. In this case, table T005X is not read and
the return code value is always 0.
The effect of SET COUNTRY is not
restricted to the current program, but applies at once to all programs
in the current roll area.

Example
When outputting documents, display the decimal point and date in the format specified for the country of the recipient:

DATA: RECEIVER_COUNTRY LIKE T005X-LAND,
DATE LIKE SY-DATUM,
AMOUNT TYPE P DECIMALS 2.

SET COUNTRY RECEIVER_COUNTRY.
IF SY-SUBRC = 4.
WRITE: / RECEIVER COUNTRY, ‘ is unknown’.
ENDIF.
WRITE: / DATE, AMOUNT.

Then, you can say

SET COUNTRY SPACE.

to display the decimal point and date according to the specification for the user again.

————————————————————-
SET

Basic form 8
SET BLANK LINES ON.
SET BLANKS LINES OFF.

Effect
These
statements allow you to specify whether you want to output blank lines
or not. Use SET BLANK LINES ON to output blank lines or SET BLANK LINES
OFF to suppress them. The default setting is SET BLANK LINES OFF .

Example
When outputting texts, include blank lines:

DATA: BEGIN OF TEXTTAB OCCURS 100,
LINE(72),
END OF TEXTTAB.
SET BLANK LINES ON.
LOOP AT TEXTTAB.
WRITE / TEXTTAB-LINE.
ENDLOOP.

Suppress blank lines again with the statement:

SET BLANK LINES OFF.

—————————————————————-
SET

Basic form
SET MARGIN x y.

Effect
Applies only to list output:

Produces
a Print with a margin of x columns on the left and (if specified) y
lines from the top of the page. x and y can be constants or variables.

Note
The MARGIN specification is always effective on the current page.

——————————————————————–
SET

Basic form
SET USER-COMMAND f.

Effect
Only valid with report list output:

Sets
the contents of the field f as USER-COMMAND and executes them
immediately when the list is next displayed (i.e. the system suppresses
the list display und immediately processes the event AT LINE-SELECTION
, AT USER-COMMAND or, in the case of a system function code (list of
reserved function codes, see AT USER-COMMAND ), this system function).
The
effect is exactly as if the user had entered the function in the
command field and pressed ENTER . This means that the current
positioning of the list (SCROLL ) and the cursor (SET CURSOR ) is taken
into account.

Note
You can specify SET USER-COMMAND several times in the same event.
If you set several functions one after the other with USER-COMMAND when creating a list, only the last one is effective.
If
the function key ENTER in the GUI status of the relevant list itself
contains a function code, this is executed rather than that specified
with SET USER-COMMAND .

Example
Process a line selection immediately:

WRITE: ‘List’… “Create a list
SET CURSOR LINE 7.

SET USER-COMMAND ‘PICK’.

The event AT LINE-SELECTION is processed immediately for list line 7.

Example
Process a function immediately:

WRITE: ‘List’… “Create a list

SET USER-COMMAND ‘FUN’.

Processes the event AT USER-COMMAND immediately; the system field SY-UCOMM contains the function code FUN .

Example
Leave list immediately:

WRITE: ‘List’… “Create a list

SET USER-COMMAND ‘BACK’.

The list is not displayed, but is left immediately.

Example
Create list with dialog box ‘Find by…’:

WRITE: ‘List’… “Create a list

SET USER-COMMAND ‘%SC’.

The list is displayed with the dialog box ‘Find by…’.

————————————————————————-
SET

Basic form 11
SET LEFT SCROLL-BOUNDARY.

Addition

… COLUMN col

Effect
When
you create a list, the current write position (system field SY-COLNO ,
see WRITE ) is set as the left boundary of the movable area. When this
list page is displayed on the screen, you can scroll horizontally with
the scrollbar only from this list column – all list column to the left
of this are fixed at the left edge.

Addition
… COLUMN col

Effect
Sets the column col as the left boundary of the movable area.

Note
The
last value set by SET SCROLL-BOUNDARY affects the entire page display
and must be reset for each list page (usually in the event TOP-OF-PAGE
) – although it can be different for each list page.
The NEW-LINE
NO-SCROLLING statement allows you to exclude individual list lines from
horizontal scrolling (e.g. title lines and indented comment blocks).

Example
Fix the leading column

DATA: NUMBER TYPE I,
SUB_NUMBER TYPE I.

NEW-PAGE NO-TITLE NO-HEADING.

DO 10 TIMES.
NUMBER = SY-INDEX.
DO 10 TIMES.
SUB_NUMBER = SY-INDEX.
WRITE: /(10) NUMBER, ‘|’,
(10) SUB_NUMBER, ‘|’.
SET LEFT SCROLL-BOUNDARY.

Not really necessary here because it was already set in the event TOP-OF-PAGE .

WRITE: ‘Data 1’, ‘|’, ‘Data 2’, ‘|’, ‘Data 3’, ‘|’. ” … ‘Data n’
ENDDO.
ENDDO.
ULINE.

TOP-OF-PAGE.
ULINE.
WRITE: /(10) ‘No’, ‘|’,
(10) ‘Sub_No’, ‘|’.
SET LEFT SCROLL-BOUNDARY.
WRITE: ‘DATA 1’, ‘|’, ‘DATA 2’, ‘|’, ‘DATA 3’, ‘|’. ” … ‘DATA n’
ULINE.

This produces the following list:

——————————————————
No | Sub_No | DATA 1 | DATA 2 | DATA 3 |
——————————————————
1 | 1 | Data 1 | Data 2 | Data 3 |
1 | 2 | Data 1 | Data 2 | Data 3 |
1 | 3 | Data 1 | Data 2 | Data 3 |

10 | 8 | Data 1 | Data 2 | Data 3 |
10 | 9 | Data 1 | Data 2 | Data 3 |
10 | 10 | Data 1 | Data 2 | Data 3 |
——————————————————

Only the columns DATA 1 , DATA 2 and DATA 3 are moved with horizontal scrolling.

Example
Reset the leading column for a new page:

NEW-PAGE.

SET LEFT SCROLL-BOUNDARY COLUMN 0.

—————————————————————
SET

Basic form 12
SET EXTENDED CHECK OFF.
SET EXTENDED CHECK ON.

Effect
You use these statements tot switch the extended syntax check off or on.
If
the extended syntax check (Transaction SLIN ) reports errors which you
do not consider to be errors, and you want to suppress them in future,
you can insert the above statements at the appropriate places in the
program. A ” SET EXTENDED CHECK OFF. ” should be followed as soon as
possible by a ” SET EXTENDED CHECK ON. “, so that the check is only
switched off for a short time.

These statements are not interpreted at runtime. You use them only to mark the source code.

During the extended syntax check, you can ignore these statements by using the additional function Include suppressed fields .

——————————————————————————-
SET

Basic form 13
SET PROPERTY OF obj p = f.

Addition

… NO FLUSH

Effect
Sets the property p of the object obj according to the contents of the field f .

The object obj must be of type OLE2_OBJECT .

SET PROPERTY

Addition
… NO FLUSH

Example
Sets the property ‘Visible’ of an EXCEL worksheet.

INCLUDE OLE2INCL.
DATA EXCEL TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL ‘Excel.Application’.
SET PROPERTY OF EXCEL ‘Visible’ = 1.

——————————————————–
SET RUN TIME ANALYZER ON/OFF

Variants

1. SET RUN TIME ANALYZER ON.
2. SET RUN TIME ANALYZER OFF.

Variant 1
SET RUN TIME ANALYZER ON.

Addition

… MODE mode

Effect
Switches on runtime analysis.

More References