Creating Data Objects Dynamically
The CREATE DATA statement prior to Release 6.10
CREATE DATA allows you to create fields in a pre-defined or user-defined data type. The statement has the following variants:
CREATE DATA dref TYPE typ.
CREATE DATA dref TYPE (typname).
CREATE DATA dref LIKE feld.
CREATE DATA dref TYPE LINE OF itab.
CREATE DATA dref LIKE LINE OF itab.
In the following example, a specific field is read from database table X031L. Note that neither the field name nor the table name is known until runtime:
Example
* Read a field from the table X031L
PARAMETERS:
TAB_NAME LIKE SY-TNAME, "Table name
TAB_COMP LIKE X031L-FIELDNAME, "Field name
ANZAHL TYPE I DEFAULT 10. Number of lines
FIELD-SYMBOLS: <WA> TYPE ANY,
<COMP> TYPE ANY.
DATA: WA_REF TYPE REF TO DATA.
CREATE DATA WA_REF TYPE (TAB_NAME). "Suitable work area
ASSIGN WA_REF->* TO <WA>.
SELECT * FROM (TAB_NAME) INTO <WA>
UP TO anzahl ROWS.
WRITE: / TAB_COMP, <COMP>.
ENDSELECT.
The CREATE DATA statement for internal tables
Another variant of CREATE DATA allows you to create table objects at runtime. The line type and table key can be entered statically or dynamically.
CREATE DATA dref (TYPE [STANDARD|SORTED|HASHED] TABLE
OF (LineType | (Name) |REF TO DATA | REF TO Obj))
| (LIKE [STANDARD|SORTED|HASHED] TABLE OF LineObj
[ WITH (UNIQUE|NON-UNIQUE)
(KEY (k1 ... kn | (keytab) | TABLE_LINE )| DEFAULT KEY ) ]
[ INITIAL SIZE m ]
The following constraints apply to this variant:
The CREATE DATA statement with built-in generic types
You can also use the basic generic types, C, N, X, and P with the CREATE DATA statement. You can specify the length and number of decimal places (for type P) using additions.
CREATE DATA dref TYPE (t | (typeName))
[ LENGTH len ]
[ DECIMALS dec ].
You can only use the LENGTH addition for types C, N, X, and P and you must always include it after the TYPE keyword. A catchable runtime error occurs if you do not comply with syntax conventions when entering LENGTH or DECIMALS values.