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 DATA declaration

Former Member
0 Likes
10,621

Hi All,

How do i declare a variable in ABAP so that the type is dynamic?

I've seen dynamic parameters, internal tables and select-options.

But, I need to declare a variable and declare the type dynamic, Something like below:

DATA gv_field LIKE (gv_dynamic_type).

Any help will be appreciated.

Thanks

7 REPLIES 7
Read only

Former Member
0 Likes
2,674

Use field symbols.

Read only

Former Member
Read only

Former Member
0 Likes
2,674

Check out this code:

PARAMETERS: P_TABLE LIKE DD03L-TABNAME.

FIELD-SYMBOLS: <FS_TABLE> TYPE TABLE,

<WA_TABLE> TYPE ANY.

DATA: XTABLE TYPE REF TO DATA." It tells compiler that the data object type will be defined at runtime

CREATE DATA XTABLE TYPE TABLE OF (P_TABLE)." It creates data XTABLE at runtime

ASSIGN XTABLE->* TO <FS_TABLE>." before using this field symbol in LOOP, its must be assigned

SELECT * FROM (P_TABLE) INTO TABLE <FS_TABLE> ORDER BY PRIMARY KEY.

LOOP AT <FS_TABLE> ASSIGNING <WA_TABLE>.

ENDLOOP.

Read only

Former Member
0 Likes
2,674

Hi Ali,

As also said by others use field symbols.......Search field symbols in SDN, you will get a lot of examples.

/message/6187499#6187499 [original link is broken]

With luck,

Pritam.

Read only

Former Member
0 Likes
2,674

Thanks for the reply guys.....

Read only

Former Member
0 Likes
2,674

Hi,

Did u get the way for doing that dynamic declaration types...

If so could u please help me with the sample code on how to do that

Regards

kishore

Read only

0 Likes
2,674

FIELD-SYMBOLS: <fs_field> type any.



data g_field type ref to data.

data g_name type string.



g_name = 'BUT021_FS-ADDRNUMBER'."could be any name



create data g_field type (g_name).



ASSIGN g_field->* TO <FS_FIELD>."is now of type BUT021_FS-ADDRNUMBER