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

Run time creating data type from data element character string

Former Member
0 Likes
1,337

Hi

my problem is that i am getting data element or data type like 'CHAR_10' at run time AND I want to create a run time data type sometihng like the below but it does not execute.

create data dataref type 'CHAR_10'.

waht i do if at run time i am getting the data type in character string.

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,058

Was this question not answer yesterday at this link.

Regards,

Rich Heilman

Read only

0 Likes
1,058

sir

my problem is that i am getting data element or data type like 'CHAR_10' at run time AND I want to create a run time data type sometihng like the below but it does not execute.

create data dataref type 'CHAR_10'.

waht i do if at run time i am getting the data type in character string.

predefined data types ok but i am getting even length at run time and i am also expecting data elements as character string.

Read only

alejandro_lpez
Contributor
0 Likes
1,058

Hi,

Try using Dynamic creation of data object, like this:

DATA: dref TYPE REF TO DATA,

tdata TYPE string.

FIELD-SYMBOLS: <f> TYPE any.

tdata = 'CHAR_10'.

CREATE DATA dref TYPE (tdata).

ASSIGN dref->* TO <f>.

Then you can use <f> like data object of type 'CHAR_10'

regards,

Alejandro.

Read only

0 Likes
1,058

it dumps me

Runtime Errors CREATE_DATA_UNKNOWN_TYPE

Except. CX_SY_CREATE_DATA_ERROR

Date and Time 10/12/2006 09:50:49

CREATE DATA: Der angegebene Typ "CHAR_10" ist kein gültiger Datentyp.

Read only

0 Likes
1,058

First, where is the 'CHAR_10' coming from? Is this a valid data element or domain in your SAP system? If so you can hit against tables DD04L and DD01L to get the data type.

Regards,

Rich Heilman

Read only

0 Likes
1,058

CHAR_10 is neither a domain nor a data element in my system. So where is it coming from. If it does not exist in the system, I guess the incoming string would have to be a certain format, meaning tha the data type would always be on the left of the _ and the length would be on the right. If that is the case, you can simply do something like this.



report zrich_0001.

data: xchar_type(1) type c.
data: xlength(3) type c.
data: xstring(20) type c value 'CHAR_10'.
data: dataref type ref to data.

split xstring at '_' into xchar_type xlength.

create data dataref type (xchar_type) length xlength.

check sy-subrc  = 0.

Regards,

Rich Heilman