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

Create a Variable Dynamically.

Former Member
0 Likes
1,266

Hi all,

Suppose i have a variable var type i.I want to create More variables Dynamically.Can Anyone tell me if possible how to do it.

suppose my requirement is to create 3 variables.

i want to create the remaining 2 var dynamically.

regards

Ahsan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,237

Did you look at the CREATE DATA statement.

Regards,

Ravi

6 REPLIES 6
Read only

Former Member
0 Likes
1,238

Did you look at the CREATE DATA statement.

Regards,

Ravi

Read only

0 Likes
1,237

No Can u tell me something abt it

Regards

Ahasan

Read only

Former Member
0 Likes
1,237

Hi,

Just check the documentation on Create DATA.

<b>SIMPLETYPE Type Declarations in the CREATE DATA Statement</b>

check this..

DATA: len TYPE i. 
... 
TypeName = 'C'. 
i = 36. 
... 
CREATE DATA dref TYPE (TypeName) LENGTH len.

Regards

Vijay

Read only

Former Member
0 Likes
1,237

Hi,

Use like this,

CREATE DATA ls_struct TYPE (lv_struct).

The above statement creates a structure what ever value the variable lv_struct currently holds.

Regards,

Venkat Ramanan

Read only

0 Likes
1,237

Hi

you try something like this:

DATA: my_dyn_var TYPE REF TO data,

my_dyn_vars TYPE REF TO data.

FIELD-SYMBOLS: <my_vars> TYPE table,

<my_var> TYPE ANY.

  • Create the single variable as MY_TYPE

CREATE DATA my_dyn_var TYPE (my_type).

ASSIGN my_dyn_var->* TO <my_var>.

  • Create n variables as MY_TYPE:

CREATE DATA my_dyn_vars TYPE STANDARD TABLE OF (my_type).

ASSIGN my_dyn_vars->* TO <my_vars>.

DO n TIMES.

APPEND <my_var> TO <my_vars>.

ENDDO.

Max

Read only

Former Member
0 Likes
1,237

Hi ,

<b>Creating variables dynamically.</b>

You can use the statement Create data. This allows you to create fields in a pre-defined or user-defined data type. The statement has following variants:

<b>Create Data dref Type typ.</b>

<b>Create Data dref Type (typename).

Create Data dref Like field.

Create Data dref Type Line of Itab.

Create Data dref Like Line of Itab.</b>

Eg :

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.

<b>In the above example, the content of a specific field of a database table is read, whereby the field and table names are not known until runtime.</b>

Regards,

Kunal