Get Example source ABAP code based on a different SAP table
Generic Typing and Complete Typing This example demonstrates how generically and completely typed formal parameters are accessed.
ABAP_SOURCE_CODE DEMO CL_DEMO_TYPING
ABAP_DESCRIPTION Three table types are declared in the class demo_typing>:
itab1g> has the line type struc1> with the components cola> and colb>. It is generic since the primary table key is not specified.
itab2g> has the line type struc2> with the components colb> and cola>. It is generic since the primary table key is not specified.
itab2c> has the line type struc2> with the components cola> and colb>. It is complete since the primary table key is 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 with reference to itab1g>. The key specification is added 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 and dynamically in the second sort as a sort criterion. The behavior is as follows:
The first SORT> statement accesses the generically typed formal parameter pg> statically. In this case, the typing with itab2g > takes place, where cola> is the second column.
The second SORT> statement accesses the generically typed formal parameter pg> dynamically. In this case, the type of the actual parameter itab1g> takes place, where cola> is the first column.
The third and fourth SORT> statements access the completely typed formal parameter pc> dynamically or statically. In these cases, the typing with itab2c> takes place, where cola> is the second column. If components of generically typed formal parameters are accessed dynamically, a runtime error can also occur if the components do not exist in the actual parameter.