2011 Nov 28 4:07 PM
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
2011 Nov 28 7:21 PM
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.
2011 Nov 28 4:37 PM
Hi
You can use the field-symbol, have you tried to give a look to the help?
Max
2011 Nov 28 6:57 PM
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
2011 Nov 28 7:21 PM
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.