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

[How-to] Evaluate dynamically an ABAP Constant

laurent_chavanis
Associate
Associate
0 Likes
2,113

Hello,

Do you know how I can dynamically/programatically retrieve the value of a defined constant in an ABAP Class having the name of the Constant.

I tried using the CLASSDESCR of the class to retrieve all attributes of type "constant", but I am not able to get the constant-value.

Thanks for your help,

Laurent

1 ACCEPTED SOLUTION
Read only

rajesh_paruchuru
Active Participant
1,406

Hello,

>

> Do you know how I can dynamically/programatically retrieve the value of a defined constant in an ABAP Class having the name of the Constant.

>

> I tried using the CLASSDESCR of the class to retrieve all attributes of type "constant", but I am not able to get the constant-value.

>

> Thanks for your help,

> Laurent

Seems you are trying to do something like this, not sure though

DATA:
  lv_const_name TYPE char30 VALUE 'ALIGN_AT_BOTTOM'.

FIELD-SYMBOLS:
 <fs_cons_value> TYPE ANY.

ASSIGN cl_gui_calendar=>(lv_const_name) TO <fs_cons_value>.
IF sy-subrc IS INITIAL.
  WRITE :<fs_cons_value>.
ENDIF.

You can only access constants defined as 'Public' using the above technique.

-Rajesh.

Hello,

Do you know how I can dynamically/programatically retrieve the value of a defined constant in an ABAP Class having the name of the Constant.

I tried using the CLASSDESCR of the class to retrieve all attributes of type "constant", but I am not able to get the constant-value.

Thanks for your help,

Laurent

3 REPLIES 3
Read only

Former Member
0 Likes
1,406

Hi

You can use the field-symbol, have you tried to give a look to the help?

Max

Read only

naimesh_patel
Active Contributor
0 Likes
1,406

You can simply move the constant to get the value (or am I missing something?)


CONSTANTS: c_test TYPE char5 VALUE 'TEST'.
data: lv_temp type string.
write: / c_Test.
lv_temp = c_test.
write: / lv_temp.

Little more fancy way:


CONSTANTS: c_test TYPE char5 VALUE 'TEST'.
DATA: lo_data TYPE REF TO data.
GET REFERENCE OF c_test INTO lo_data.
FIELD-SYMBOLS: <lfs_test> TYPE ANY.

ASSIGN lo_data->* TO <lfs_test>.
WRITE: / c_test.
WRITE: / <lfs_test>.

Regards,

Naimesh Patel

Read only

rajesh_paruchuru
Active Participant
1,407

Hello,

>

> Do you know how I can dynamically/programatically retrieve the value of a defined constant in an ABAP Class having the name of the Constant.

>

> I tried using the CLASSDESCR of the class to retrieve all attributes of type "constant", but I am not able to get the constant-value.

>

> Thanks for your help,

> Laurent

Seems you are trying to do something like this, not sure though

DATA:
  lv_const_name TYPE char30 VALUE 'ALIGN_AT_BOTTOM'.

FIELD-SYMBOLS:
 <fs_cons_value> TYPE ANY.

ASSIGN cl_gui_calendar=>(lv_const_name) TO <fs_cons_value>.
IF sy-subrc IS INITIAL.
  WRITE :<fs_cons_value>.
ENDIF.

You can only access constants defined as 'Public' using the above technique.

-Rajesh.