Application Development 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: 

Creating Dynamic Variable

Former Member
0 Kudos

Hi Friends ,

I have one table which contains three fields ,1) unique identifier ,2) number of digits before decimal and 3) number of decimals.

In one other table there are 2 fields,1)unique identifier , and 2) VALUE in float format e.g 4.000000000000000E+01

4.000000000000000E+00

Identifier is common field between this two tables.

I wan to write the VALUE field in my report,by the number of decimals given in first table.

So how can i create dynamic variable at runtime that will contain number of decimals as given in my table.

Thanks,

Brij

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

If you want to dynamically create variable names, you will have to use CREATE DATA, or maybe even use the CL_ABAPDESCR classes.

Some examples for Dynamic Creation of Data Objects:

TYPES: BEGIN OF struc,

a TYPE i,

b TYPE c LENGTH 8,

END OF STRUC.

DATA: dref TYPE REF TO DATA,

tname TYPE string,

str TYPE struc,

int TYPE i.

FIELD-SYMBOLS: <int> TYPE i,

<str> TYPE struc,

<f> TYPE any.

dref

CREATE DATA dref TYPE struc.

ASSIGN dref->* TO <str>.

<str>

36 ABC

<str>-a = 36. <str>-b = 'ABC'.

CREATE DATA dref LIKE int.

ASSIGN dref->* TO <int>.

<int>

5

<int> = 5.

tname = 'SFLIGHT'.

CREATE DATA dref TYPE (tname).

ASSIGN dref->* TO <f>.

<f>

SELECT SINGLE * FROM (tname) INTO <f>.

Regards,

Vind

1 REPLY 1

Former Member
0 Kudos

Hi

If you want to dynamically create variable names, you will have to use CREATE DATA, or maybe even use the CL_ABAPDESCR classes.

Some examples for Dynamic Creation of Data Objects:

TYPES: BEGIN OF struc,

a TYPE i,

b TYPE c LENGTH 8,

END OF STRUC.

DATA: dref TYPE REF TO DATA,

tname TYPE string,

str TYPE struc,

int TYPE i.

FIELD-SYMBOLS: <int> TYPE i,

<str> TYPE struc,

<f> TYPE any.

dref

CREATE DATA dref TYPE struc.

ASSIGN dref->* TO <str>.

<str>

36 ABC

<str>-a = 36. <str>-b = 'ABC'.

CREATE DATA dref LIKE int.

ASSIGN dref->* TO <int>.

<int>

5

<int> = 5.

tname = 'SFLIGHT'.

CREATE DATA dref TYPE (tname).

ASSIGN dref->* TO <f>.

<f>

SELECT SINGLE * FROM (tname) INTO <f>.

Regards,

Vind