Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

creating objects at runtime

Former Member
0 Likes
997

Can anyone give me idea on using CREATE DATA

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
789

Hi Sandhya,

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: * Read a field from the table X031L

PARAMETERS: TAB_NAME LIKE SY-TNAME, "Table name TAB_COMP LIKE X031L-FIELDNAME, "Field name NUMBER 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 NUMBER ROWS.

ASSIGN COMPONENT TAB_COMP OF STRUCTURE <WA> TO <COMP>.

WRITE: / TAB_COMP, <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:

1. m is a variable or a constant without a sign, whose content at runtime must be of the type NUMLIKE.

2. keytab is a table of the type CHARLIKE, which must not be empty, and whose components must not contain any offset, length, or overlapping key entries. You can use the TABLE_LINE addition, if the table contains only one line.

3. The system returns a syntax error if either the type, or line declaration and the key declaration are static.

4. If you do not define a key, the system uses the DEFAULT-KEY.

__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.

reward if useful

3 REPLIES 3
Read only

Sm1tje
Active Contributor
0 Likes
789

data: gr_table type ref to data.

field-symbols: <itab> type any table

parameters: p_tab type tabname default 'SFLIGHT'

start-of-selection.

create data gr_table type standard table of (p_tab).

assign gr_table->* to <itab>.

select * from (p_tab) into table <itab>.

Via create data you have created a internal table reference to the data structure 'SFLIGHT' (in this case).

Read only

Former Member
0 Likes
789

Hi sandya

All of the data objects that you define in the declaration part of a program using statements such as DATA are created statically, and already exist when you start the program. To create a data object dynamically during a program, you need a data reference variable and the following statement:

CREATE DATA dref {TYPE type}|{LIKE dobj}.

This statement creates a data object in the internal session of the current ABAP program. After the statement, the data reference in the data reference variable dref points to the object. The data object that you create does not have its own name. You can only address it using a data reference variable. To access the contents of the data object, you must dereference the data reference.

You must specify the data type of the object using the TYPEor LIKE addition. In contrast to the use of the TYPEaddition in other ABAP statements, you can use the CREATE DATA addition to dynamically specify the data type as the contents of a field.

CREATE DATA dref TYPE (name).

Reward Me Points

By

Pari

Read only

Former Member
0 Likes
790

Hi Sandhya,

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: * Read a field from the table X031L

PARAMETERS: TAB_NAME LIKE SY-TNAME, "Table name TAB_COMP LIKE X031L-FIELDNAME, "Field name NUMBER 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 NUMBER ROWS.

ASSIGN COMPONENT TAB_COMP OF STRUCTURE <WA> TO <COMP>.

WRITE: / TAB_COMP, <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:

1. m is a variable or a constant without a sign, whose content at runtime must be of the type NUMLIKE.

2. keytab is a table of the type CHARLIKE, which must not be empty, and whose components must not contain any offset, length, or overlapping key entries. You can use the TABLE_LINE addition, if the table contains only one line.

3. The system returns a syntax error if either the type, or line declaration and the key declaration are static.

4. If you do not define a key, the system uses the DEFAULT-KEY.

__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.

reward if useful