Overview
1. Data objects
2. Table objects
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, the content of a specific field of a database table is read, whereby the field and table names are not known until runtime.
Example
PARAMETERS:
tab_name TYPE tname,
"Table name
tab_comp TYPE tfieldname, "Field
name
line_num TYPE i DEFAULT 10. "Line
number
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>.
CHECK SY-DBCNT < line_num.
ASSIGN COMPONENT tab_comp OF STRUCTURE <wa> TO
WRITE: / tab_comp,
ENDSELECT.
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:
Note
You can also use the generic Basis types C, N, X, and P with the CREATE DATA statement, along with additions to specify the length and (for type P) the number of decimal places.
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.