ABAP Keyword Documentation → ABAP - Reference → Declarative statemnts → Typing → typing Addition
typing Addition - generic_type
Other versions: 7.31 | 7.40 | 7.54
Syntax
... { TYPE generic_type }
| { LIKE <generic_fs>|generic_para } ...
Effect
To generically type a formal parameter or a field symbol, you can
- specify any generic ABAP type
generic_type
(exceptobject
) afterTYPE
.
- specify a field symbol visible at this position
(
<generic_fs>
) or a formal parameter (generic_para
) with generic typing, afterLIKE
. The typing you have defined is applied when the field symbol/parameter is declared. All generic typings are applied except complete typings. In method parameters, all generic typings are possible. No complete generic typings are possible in parameters of subroutines and field symbols.
When an actual parameter or memory area is assigned to a generically typed formal parameter or field symbol, the system checks whether the specified data type is a subset of the generic type.
The formal parameter or field symbol can be used as operands anywhere that is not excluded by this typing. However, operands that expect particular internal tables are an exception to this rule. Here, only formal parameters or field symbols with the requisite internal table type are allowed.
The type attributes specified by the typing are used in static access to a generically typed formal parameter or field symbol. In dynamic access, the attributes of the actual parameter or memory area assigned apply.
If you do not specify an actual parameter for a generically typed optional formal parameter of a method or a function module when calling the procedure and no replacement parameter is defined in the procedure, the type of the formal parameter is completed according to the following rules:
any
anddata
are converted to the typec
with length 4.
c
,clike
,csequence
, andsimple
are converted to the typec
with length 1.
n
is converted to the typen
with length 1.
numeric
andp
are converted to the typep
with length 8 without decimal places.
x
andxsequence
are converted to the typex
with length 1.
ANY TABLE
andINDEX TABLE
are converted toSTANDARD TABLE
.
- For
ANY TABLE
,INDEX TABLE
, [STANDARD] TABLESORTED TABLE
, andHASHED TABLE
, the row type is set toc
with length 1.
- For generic table types without specification of a primary table key, the standard key is completed for standard tables and the entire table row (without any table-like parts) is completed as the key specification for sorted tables and hash tables.
- For generic table types, for which the primary table key is specified but uniqueness is not specified, the standard key is set to non-unique for standard tables and sorted tables, and to unique for hashed tables.
- This generic property is ignored for table types that are generic with respect to the secondary
table key. This applies even if the generic property was defined explicitly with the addition
WITH FURTHER SECONDARY KEYS
.
If a replacement parameter is specified, then the type attributes of this parameter are applied.
Note
When typing formal parameters, you can use the LIKE
addition to refer to formal parameters (in the same procedure), which have already been declared.
Example
In the following example, two generically typed field symbols are used in
LOOP
statement. To avoid syntax errors, <any_table>
must be defined as an internal table. However, the system does not check the type of <any_object>
until runtime, to ensure that the type of the data object assigned to it is compatible with the row type of the table.
FIELD-SYMBOLS: <any_object> TYPE ANY,
<any_table> TYPE ANY TABLE.
...
LOOP AT <any_table> INTO <any_object>.
...
ENDLOOP.