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

Dynamic Table

Former Member
0 Likes
324

Hi,

I got error when it comes to the following code.

error " CREATE DATA: The specified type " " is no valid data type.

  • dynamically create appropriate internal table

create data dref type table of (tabname).

assign dref->* to <tab>.

can anyone identify the error? Please help. Thanks

&----


*& Report Z_ZRVSL0013

*&

&----


*& This program is used to remove logs created in z-tables.

*&

&----


REPORT Z_ZRVSL0013.

data : begin of it_tbl occurs 0.

include structure ztabl_log.

data : end of it_tbl.

data : num_days type sy-datum,

num_days1 type string,

query type string,

status(80) type c.

data : tabname type tabname,

fieldname type fieldname.

data : xref type ref to cx_dynamic_check,

message_txt type string,

dref type ref to data.

parameters : chckbox as checkbox default 'X'.

field-symbols: <tab> type standard table.

  • dynamically create appropriate internal table

create data dref type table of (tabname).

assign dref->* to <tab>.

if chckbox is not initial.

select * from ztabl_log into table it_tbl.

else.

exit.

endif.

try.

loop at it_tbl.

tabname = it_tbl-tabname.

fieldname = it_tbl-fname.

num_days = sy-datum - it_tbl-zdays.

concatenate '''' num_days '''' into num_days1.

concatenate fieldname '<' num_days1 into query separated by space.

select *

from (tabname)

into table <tab>

where (query).

if sy-subrc eq 0.

delete (tabname) from table <tab>.

concatenate 'Last update is on' sy-datum into status separated by space.

it_tbl-status = status.

modify (tabname) from it_tbl.

endif.

endloop.

catch cx_sy_dynamic_osql_error

cx_sy_create_data_error into xref.

message_txt = xref->get_text( ).

message message_txt type 'E'.

endtry.

Edited by: Hui Leng Yeoh on Feb 29, 2008 4:18 AM

1 REPLY 1
Read only

Former Member
0 Likes
289

Hi,

I thing wrong with syntax...

Correct One:

create data dref type (tabname).

Your code :

create data dref type table of (tabname).

See the docu..

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:

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

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.

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

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

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.

Reward if useful