Ansicht
Dokumentation

ABAPCREATE_DATA_TYPE_SIMPLE - CREATE DATA TYPE SIMPLE

ABAPCREATE_DATA_TYPE_SIMPLE - CREATE DATA TYPE SIMPLE

Vendor Master (General Section)   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

SIMPLETYPE Type Declarations in the CREATE DATA Statement

Alternatives:

1. {type|(name)} [LENGTH len] [DECIMALS dec]

2. LINE OF {type|(name)}

3. REF TO {type|(name)}

4. REF TO DATA

Effect

You can declare either a static or a dynamic type after the TYPE addition. If you declare the type dynamically, as (name), the system does not get the name of the type from the variable name until runtime.

Notes

  1. The type name in name must be completely in upper case.

  2. If you declare the type dynamically, you can also use an absolute type name.


Alternative 1

{type|(name)} [LENGTH len] [DECIMALS dec]


Effect

In its simplest form, declares a type after the TYPE addition, without any further additions.

If you want, you can also declare the length of elementary types C, N, P, and X using the LENGTH len addition. You specify default values and the maximum length similarly to the static DATA statement. Declaring an invalid length dynamically causes a runtime error.

You declare the number of decimal places for type p types using the DECIMALS dec addition. You specify default values and the maximum number of decimal places similarly to the static DATA statement.

Examples

Dynamically creating an instance of the type SFLIGHT

DATA: dref TYPE REF TO DATA.
...
CREATE DATA dref TYPE sflight.

Creating a data object, whose type is only received by the system at runtime from the variable TypeName.

DATA: TypeName TYPE string.
...
TypeName = 'SFLIGHT'.
...
CREATE DATA dref TYPE (TypeName).

Creating a variable whose type and length are not known until runtime.

DATA: len TYPE i.
...
TypeName = 'C'.
i = 36.
...
CREATE DATA dref TYPE (TypeName) LENGTH len.

Alternative 2

LINE OF {type|(name)}


Effect

You can reference the line type of an internal table statically or dynamically using the LINE OF addition. The table type that provides the line type must be completely (that is, not generically) typed.

Example

The following example shows a references a line type of an internal table type whose name is unknown until runtime. If TypeName does not contain a valid table type name, the system returns a runtime error.

TYPES: ItabType TYPE HASHED TABLE OF sflight
                     WITH UNIQUE KEY carrid connid.
...
TypeName = 'ITABTYPE'.
...
CREATE DATA dref TYPE LINE OF (TypeName).
...

Note

The table type that provides the line type must be completely typed. Otherwise, the system returns a runtime error..

Alternative 3

REF TO {type|(name)}


Effect

You can point to the reference type of a class or interface using the REF TO addition.

Example

The following example shows a reference to a dynamically declared interface type. If TypeName does not contain a valid interface name, the system returns a runtime error.

INTERFACE i_bike.
  METHODS drive.
ENDINTERFACE.
...
TypeName = 'I_BIKE'.
...
CREATE DATA dref TYPE REF TO (TypeName).
...

Alternative 4

REF TO DATA


Effect

You can point to a reference type for general data references using the REF TO DATA type declaration. You can only declare this type statically. If you try to declare the type dynamically using (name), where (name)contains the value DATA at runtime, you will cause a runtime error.






General Material Data   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.

Length: 5269 Date: 20240328 Time: 225821     sap01-206 ( 70 ms )