ARTICLE
Generic and Complete Typing
The example shows how to access generically and completely typed formal
parameters.
ABAP_SOURCE_CODE
ABAP_EXEC
ABAP_DESCRIPTION
In the class demo_typing , three table types are declared:
itab1g has the line type struc1 with the components
cola and colb . It is generic since the primary table key
has not been specified.
itab2g has the line type struc2 with the components
colb and cola . It is generic since the primary table key
has not been specified.
itab2c has the line type struc2 with the components
cola and colb . It is complete since the primary table key
has been specified.
The method sort_itab has two formal parameters:
pg is typed generically with itab2g .
pc is typed completely with itab2c .
In the method start , an internal table tab is declared by
referring to itab1g . The key is specified implicitly. This table
is filled and passed to the formal parameters of sort_itab .
In sort_itab , both formal parameters are sorted twice. In the
first sort, the column cola is specified statically as a sort
criterion, in the second sort, it is specified dynamically. The
behaviour is as follows:
The first SORT statement statically accesses the generically
typed formal parameter pg . In this case, the typing with
itab2g takes priority in which cola is the second column.
The second SORT statement dynamically accesses the generically
typed formal parameter pg . In this case, the type of the actual
parameter itab1g takes priority in which cola is the first
colulmn.
The third and fourth SORT statements dynamically or statically
access the completely typed formal parameter pc . In these cases,
the typing with itab2c takes priority in which cola is the
second column.
If components of generically typed formal parameters are accessed
dynamically, a runtime error may occur if the components do not exist in
the actual parameter.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved