Entering content frameThe TYPE Addition Locate the document in its SAP Library structure

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

Referring to Known Data Types

You can use the addition

TYPE <type>

to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression

LINE OF <table-type>

In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.

ABAP Statements with TYPE References

TYPES <t> TYPE <type>.

The new data type <t> has the same type as <type>.

DATA <f> TYPE <type>.

CLASS-DATA <f> TYPE <type>.

CONSTANTS <f> TYPE <type>.

STATICS <f> TYPE <type>.

PARAMETERS <f> TYPE <type>.

The data object <f> has a data type corresponding to the type <type>.

CREATE DATA <dref> TYPE <type>.

FORM <sub> ... USING|CHANGING <p> TYPE <type> ...

The technical attributes of the formal parameter <p> are inherited from those of the declared data type <type>. You can then only pass actual parameters that have these attributes.

METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> TYPE <type> ...

The technical attributes of the formal parameter <p> are inherited from those of the declared data type <type>. You can then only pass actual parameters that have these attributes.

FIELD-SYMBOLS <fs> TYPE <type>.

The technical attributes of the field symbol <FS> are inherited from those of the declared data type <type>. You can then only pass actual parameters that have these attributes.

Visibility of Data Types

When you refer to known data types using the TYPE addition, the visibility of the data types is important.

The graphic shows the visibility of local and ABAP Dictionary data types:

This graphic is explained in the accompanying text

The system searches from the inside out. If you specify TYPE1 in a TYPE addition in the program , the system uses the ABAP Dictionary type both in the procedure and the main program. If you specify TYPE2 in the procedure, the system uses the local type from the procedure. However, if you specify TYP2 in the main program, the system uses the type from the main program. TYPE2 from the ABAP Dictionary is obscured. If you specify TYPE3 either in the procedure or the main program, the system uses the type from the main program TYPE3 from the ABAP Dictionary is obscured.

Constructing New Data Types

The TYPE addition allows you to construct new data types in the TYPES, DATA; CONSTANTS; and STATICS statements. In the TYPES statement, these are local data types in the program. In the other statements, they are attributes of new data objects.

You can use the following type constructors with the TYPE addition:

REF TO <class>|<interface>

BEGIN OF <struct>.
  ...
END OF <struct>.

<tabkind> OF <linetype> [WITH <key>]

These data types only exist during the runtime of the ABAP program.

Referring to Generic Types When Specifying a Type

There is a set of predefined generic types in ABAP syntax that you can use to specify the types of interface parameters and field symbols. You can only use them after the TYPE addition in the FORM, METHODS, and FIELD-SYMBOLS statements.

Generic Types for Type Specification

ANY

Fully generic type

ANY TABLE

Generic table for any internal table

INDEX TABLE

Generic type for tables with a linear index

TABLE

STANDARD TABLE

Generic type for unsorted tables with a linear index

SORTED TABLE

Generic type for sorted tables with a linear index

HASHED TABLE

Generic table for tables with hash administration

You cannot use these types to define local data types in a program or data objects. They only allow you to check the data type of fields that you pass to procedures or of field symbols.

 

Leaving content frame