GET (ABAP keyword)

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

GET

Basic form 1
GET dbtab.

Additions

1. …
LATE
2. … FIELDS f1 … fn

Effect
Processing event.

Gets
the table dbtab for processing while the logical database is running. You can
address all the fields from dbtab in the subsequent processing. You can also
refer to fields from tables in the logical database on the access path to the
table dbtab .

Note
You can use the event ” GET dbtab. ” only once in
the report.

Example
The program uses the logical database F1S which
has a structure where the table BOOKING appears below the table FLIGHT
.

TABLES: SFLIGHT, SBOOK.

GET SFLIGHT.
WRITE:
SFLIGHT-CARRID,
SFLIGHT-CONNID,
SLFIGHT-FLDATE,
SFLIGHT-PLANETYPE.

GET
SBOOK.
WRITE:
SBOOK-BOOKID,
SBOOK-CUSTOMID,
SBOOK-ORDER_DATE.

Addition
1
… LATE.

Effect
Executes the code following ” GET dbtab LATE. ”
only when all the subordinate tables have been read and
processed.

Example
Count the smokers among the bookings already
made.

TABLES: SFLIGHT, SBOOK.
DATA SMOKERS TYPE I.

GET
SFLIGHT.
ULINE.
WRITE: / SFLIGHT-SEATSMAX,
SFLIGHT-SEATSOCC.
SMOKERS
= 0.

GET SBOOK.
CHECK SBOOK-SMOKER <> SPACE.
ADD 1 TO
SMOKERS.

GET FLIGHT LATE.
WRITE SMOKERS.

Addition
2
… FIELDS f1 … fn

Effect
Performance option. Addresses only
the fields f1, …, fn of the tabelle dbtab (also possible with a dynamic ASSIGN
). Since only these fields have to be assigned values by the logical database,
this can improve performance considerably.

Notes
The addition (for GET
dbtab or GET dbtab LATE ) is allowed only for tables intended for field
selection by the logical database (SELECTION-SCREEN FIELD SELECTION FOR TABLE
dbtab ).
When executing the events GET dbtab , GET dbtab LATE or GET dbtab_2
for a subordinate table dbtab_2 in the database hierarchy, the contents of all
all fields of dbtab apart from f1, …, fn are undefined.
If both GET dbtab
FIELDS f1 …fn and GET dbtab LATE FIELDS g1 …gm occur in the program, values
are assigned to all the fields f1, …, fn, g1, …, gm .
In addition to the
specified fields, values are also assigned to the key fields of dbtab .
If
you use the FIELDS addition, you access only the specified fields. Any external
PERFORM calls should be taken into account here.
A special rule applies for
tables which are intended for field selection by the logical database, for which
neither a GET dbtab nor a GET dbtab LATE event exists in the program, yet for
which there is a subordinate table dbtab_2 with GET dbtab_2 or GET dbtab_2 LATE
in the program.

If the table is declared with TABLES dbtab in the
program, the work area of dbtab exists for GET dbtab_2 or GET dbtab_2 LATE and
is can therfore receive values. Also, if a restricted field selection is
sufficient for dbtab , you can achieve this with a GET dbtab FIELDS f1 … fn
statement (without subsequent processing).

If the program contains no
TABLES dbtab statement, the system assumes no access to the work area of dbtab .
In this case, therefore, only the key fields of dbatab are assigned values. If,
however, you want to fill the work area of dbtab completely (e.g. for an
external PERFORM call), you must include the TABLES dbtab statement in the
program.
The field lists are made available to the report and the logical
database in an internal table SELECT_FIELDS .

The exact definition of the
object SELECT_FIELDS is stored in the TYPE-POOL RSFS and reads:

TYPES:
BEGIN OF RSFS_TAB_FIELDS,
TABLENAME LIKE RSDSTABS-PRIM_TAB,
FIELDS LIKE
RSFS_STRUC OCCURS 10,
END OF RSFS_TAB_FIELDS.

TYPES:
RSFS_FIELDS TYPE RSFS_TAB_FIELDS OCCURS 10.

DATA SELECT_FIELDS TYPE
RSFS_FIELDS.

SELECT_FIELDS is thus an internal table. Each line of this
internal table contains a table name ( TABLENAME ) and another internal table (
FIELDS ) which contains the desired table fields ( TABLENAME ).

Neither
the TYPE-POOL RSFS nor the declaration of SELECT_FIELDS have to be in the
report. Both are automatically included by the system, if required. If, for some
reason, you need to assign values to more fields, you can manipulate this table
under INITIALIZATION or START-OF-SELECTION .

Examples
Specify the
necessary fields under GET . Both SFLIGHT and SBOOK must be defined for field
selection.

TABLES: SFLIGHT, SBOOK.

GET SFLIGHT FIELDS CARRID
CONNID FLDATE PLANETYPE.
WRITE:
SFLIGHT-CARRID,
SFLIGHT-CONNID,
SFLIGHT-FLDATE,
SFLIGHT-PLANETYPE.

GET
SBOOK FIELDS BOOKID CUSTOMID ORDER_DATE.
WRITE:
SBOOK-BOOKID,
SBOOK-CUSTOMID,
SBOOK-ORDER_DATE.

In the
above ‘smoker’ example, you can also specify the required SFLIGHT fields under
‘GET SFLIGHT LATE’:

TABLES: SFLIGHT, SBOOK.
DATA SMOKERS TYPE
I.

GET SFLIGHT.
ULINE.
WRITE: /
SFLIGHT-SEATSMAX,
SFLIGHT-SEATSOCC.
SMOKERS = 0.

GET SBOOK FIELDS
SMOKER.
CHECK SBOOK-SMOKER <> SPACE.
ADD 1 TO SMOKERS.

GET
SFLIGHT LATE FIELDS SEATSMAX SEATSOCC.
WRITE SMOKERS.

Only
fields from SBOOK are output. No TABLES SFLIGHT statement exists. Then, for the
table SFLIGHT , only the key fields are read (regardless of whether the FIELDS
addition is used with GET SBOOK or not).

TABLES: SBOOK.

GET
SBOOK FIELDS BOOKID CUSTOMID ORDER_DATE.
WRITE:
SBOOK-BOOKID,
SBOOK-CUSTOMID,
SBOOK-ORDER_DATE.

Only fields
from SBOOK are output, but SFLIGHT is declared by TABLES SFLIGHT . In this case,
all the fields of table SFLIGHT are read (regardless of whether the FIELDS
addition is used with GET SBOOK or not).

TABLES: SFLIGHT,
SBOOK.

GET SBOOK FIELDS BOOKID CUSTOMID ORDER_DATE.
WRITE:
SBOOK-BOOKID,
SBOOK-CUSTOMID,
SBOOK-ORDER_DATE.

GET
CURSOR

Variants

1. GET CURSOR FIELD f.
2. GET
CURSOR LINE lin.

Variant 1
GET CURSOR FIELD
f.

Additions

1. … OFFSET off
2. … LINE lin
3.
… VALUE g
4. … LENGTH len

Effect
Transfers the name of the
field at the cursor position to the field f .

The return code value is
set as follows:

SY-SUBRC = 0 Cursor was positionedd on a
field.
SY_SUBRC = 4 Cursor was not positioned on a
field.

Note
Unlike screen processing, list processing allows you to
output literals, field symbols, parameters and local variables of subroutines.
Literals, local variables and VALUE parameters of subroutines are treated like
fields without names (field name SPACE , return value 0).
Otherwise, GET
CURSOR FIELD returns only names of global fields, regardless of whether they are
addressed directly (i.e. by ” WRITE “), by field symbols or by reference
parameters.

Example

DATA: CURSORFIELD(20),
GLOB_FIELD(20) VALUE
‘global field’,
REF_PARAMETER(30) VALUE ‘parameter by
reference’,
VAL_PARAMETER(30) VALUE ‘parameter by value’,
FIELD_SYMBOL(20)
VALUE ‘field-symbol’.
FIELD-SYMBOLS: .
PERFORM WRITE_LIST USING
REF_PARAMETER VAL_PARAMETER.
ASSIGN GLOB_FIELD TO .

AT
LINE-SELECTION.
GET CURSOR FIELD CURSORFIELD.
WRITE: / CURSORFIELD,
SY-SUBRC.

FORM WRITE_LIST USING RP VALUE(VP).
DATA: LOK_FIELD(20)
VALUE ‘lokal field’.
ASSIGN FIELD_SYMBOL TO .
WRITE: / GLOB_FIELD, /
LOK_FIELD,
/ RP, / VP,
/ ‘literal’, /
FIELD_SYMBOL.
ENDFORM.

When you double-click on the word ” global
field “, CURSORFIELD contains the field name GLOB_FIELD , on ” parameter by
reference ” the field name REF_PARAMETER , on ” field symbol ” the field name
FIELD_SYMBOL , and on ” local field “, ” parameter by value ” and ” literal ”
the value SPACE .

Addition 1
… OFFSET off

Effect
Copies
the position of the cursor within the field to the field off (1st column =
0).
If the cursor is not somewhere within a field ( SY-SUBRC = 4 ), the
offset value is set to 0.

Addition 2
… LINE
lin

Effect
With step loops, lin contains the number of the loop line
where the cursor stands. In list processing, this is the absolute line number
(as stored in the system field SY-LILLI ).

Addition 3
… VALUE
g

Effect
g contains the value of the field where the cursor stands,
always in output format (character display).

Addition 4
… LENGTH
len

Effect
len contains the output length of the field where the
cursor stands.

Variant 2
GET CURSOR LINE
lin.

Additions

1. … OFFSET off
2. … VALUE g
3.
… LENGTH len

Effect
As for variant 1 with addition LINE , except
that there are differences with the return value and the effect of the
additions.

The return code value is set as follows:

SY-SUBRC =
0 The cursor is on one of the list lines (list processing) or on a loop line
(step loop).
SY_SUBRC = 4 The cursor is not on one of the list or loop
lines.

Addition 1
… OFFSET off

Effect
Applies to list
processing only. The field off contains the position of the cursor releative to
the beginning of the list line (1st column = 0). With horizontally shifted
lists, the offset value can thus be greater than 0, even if the cursor is
positioned on the extreme left of the window.

Addition 2
… VALUE
g

Effect
List processing only. The field g contains the list line
where the cursor is positioned.

Addition 3
… LENGTH
len

Effect
List processing only. len contains the length of the line (
LINE-SIZE ).

GET

Basic form 3
GET
PARAMETER ID key FIELD f.

Effect
Transfers the value stored under the
key pid from the global user-related SAP memory memory to the field f .
The
key pid must consist of three characters. For an overview of the keys
(parameters) used, refer to the SAP system description or the appropriate
function in the ABAP/4 Development Workbench.

The return code value is
set as follows:

SY-SUBRC = 0 A value was read from SAP
memory.
SY_SUBRC = 4 No value was found in SAP memory under the specified
key

Notes
The global user-related SAP memory is available to each user
for the entire duration of a terminal session. For this reason, set values are
retained when you leave a program.
The SAP memory should not be used for
intermediate storage, since a user’s parallel sessions use the same global
memory.

Example
Read the program name from SAP memory:

DATA
: REPID(8).
GET PARAMETER ID ‘RID’ FIELD REPID.

GET
TIME

Basic form 4
GET TIME.

Addition

… FIELD
f

Effect
Sets the system field SY-UZEIT to the current time and resets
SY-DATUM .

Addition
… FIELD f

Effect
Transfers the current
time to the field f , depending on the type. SY-DATUM and SY-UZEIT are not
set.

GET
Basic form 5
GET RUN TIME FIELD
f.

Effect
Relative runtime in microseconds. The first call sets
(initializes) the field f to zero. For each subsequent call, f contains the
runtime in microseconds since the first call. The field F should be of type I
.

Note
If the applications server is a multiple processor, switching
the CPU to another processor may lead to fluctuations in the returned runtime.
When measuring the runtime of smaller program components, you can achieve the
correct result by taking several small measurements.

Example

DATA:
T1 TYPE I,
T2 TYPE I,
TMIN TYPE I.

DATA: F1(4000), F2 LIKE
F1.

TMIN = 1000000.
DO 10 TIMES.
GET RUN TIME FIELD T1.
MOVE F1
TO F2. “Time measurement of the MOVE statement
GET RUN TIME FIELD T2.
T2 =
T2 – T1. IF T2 < tmin =" T2.">GET
Basic form 6
GET PROPERTY OF obj p
= f.

Addition

… NO FLUSH

Effect
Transfers
attribute p of object obj to field f .
Object obj must be of type OLE2_OBJECT
.
GET PROPERTY

Addition
… NO FLUSH

Example
Read the
attribute ‘Visible’ of an EXCEL worksheet.

INCLUDE OLE2INCL.
DATA:
EXCEL TYPE OLE2_OBJECT,
VISIBLE TYPE I.
CREATE OBJECT EXCEL
‘Excel.Application’.
GET PROPERTY OF EXCEL ‘Visible’ = VISIBLE.