Typing Formal Parameters and Field Symbols

Formal parameters in FORM and FUNCTION, and field symbols (FIELD-SYMBOLS) may be typed in ABAP. To do so, you use the ... TYPE dataType or ... LIKE dataObject additions to specify a type.

Typed formal parameters and field symbols make programs safer, and easier to understand and maintain. They also allow the ABAP generator to generate optimized intermediate code, thus improving the performance of your programs.

If a formal paramter or field symbol is typed, the syntax check (if possible), or the runtime environment will check whether the actual parameter and formal parameter are compatible.

Typing with Complete Types

Compatibility in this context means that the two objects have the same technical type. Two types are compatible if they have exactly the same technical attributes.

The technical attributes of a simple field are its elementary data type and the field length (in the case of type P fields, the number of decimal places as well). These are considered in the type check. The conversion exit and help ID are not. Note that the types STRING and C as well as XSTRING and X, are not compatible.

In structures, the form of the structure is considered in addition to the component types. Two structures may have the same sequence of elementary components, but if that sequence is divided into substructures in different ways in the two structures, they are not compatible in the sense of the technical ABAP type check.

Two internal tables are compatible if their line types are compatible. The OCCURS value is not considered in the type check.

Typing with Generic Types

A formal parameter or a field symbol can be typed incompletely by choosing a generic type which restricts the type of the actual parameter or runtime type to a subset of specific runtime types. Generic type specifications can be performed as follows.

The type ANY allows all generic and elementary types.

The following generic types make a restriction to the elementary runtime types.

The following generic types make a restriction to the types of internal tables.

The following overview shows all ways of generic typing.


                                           +---I,INT2,INT1
                   +-----------NUMERIC-----+---P
                   |                       +---F
                   |
                   |                       +---X
      +---SIMPLE---+-----------XSEQUENCE---+---XSTRING
      |            |
      |            +---CLIKE-+-CSEQUENCE---+---STRING
ANY---+                      |             +---C
      |                      |
      |                      |             +---N
      |                      +-------------+---D
      |                                    +---T
      |                                    +---STRUC(C,N,D,T)
      |
      +---TABLE



Other Comments on Typing with Generic Types

If a formal parameter or a field symbol is not typed or not typed completely, the formal parameter inherits the type attributes of the actual parameter. However, if a complete typing was made, the formal parameter always has the type attributes specified through typing.

In other words, this means that concerning the type attributes not considered by the type check (such as conversion exit and help ID) and which can therefore be different even for compatible actual and formal parameters,