2010 Jun 02 8:22 AM
Hi all
I have a class with many public static attributes. To provide a generic solution I want to access the value of such an attribute dynamically at run-time. Unfortunately am I not able to do it. Can you help me with this issue?
The following code fragment for instance is not allowed. In this case I receive the syntax error that 'Dynamic attribute declarations are not supported in the current statement'.
DATA:
lv_txt TYPE string,
lv_attribute TYPE string.
lv_attribute = 'TEST'.
lv_txt = Z_TEST=>(lv_attribute).
Any hint is welcome...
Thanks, Mathias
2010 Jun 02 9:16 AM
You have to access it using dynamic assing
FIELD-SYMBOLS <attr> TYPE string.
ASSIGN cl_abap_char_utilities=>('HORIZONTAL_TAB') TO <attr>.
Regards
Marcin
For reference [Accessing Class Components |http://help.sap.com/abapdocu_70/en/ABENCLASS_COMPONENTS_ADDRESSING.htm]
Edited by: Marcin Pciak on Jun 2, 2010 10:16 AM
Hi all
I have a class with many public static attributes. To provide a generic solution I want to access the value of such an attribute dynamically at run-time. Unfortunately am I not able to do it. Can you help me with this issue?
The following code fragment for instance is not allowed. In this case I receive the syntax error that 'Dynamic attribute declarations are not supported in the current statement'.
DATA:
lv_txt TYPE string,
lv_attribute TYPE string.
lv_attribute = 'TEST'.
lv_txt = Z_TEST=>(lv_attribute).
Any hint is welcome...
Thanks, Mathias
2010 Jun 02 8:48 AM
hi,
you could do a little workaround by calling a get-method dynamicly, which will return the attribute you would like to read:
CALL METHOD Z_TEST=>(ld_methodname)
greetings,
dsp
2010 Jun 02 9:08 AM
Hi dsp
I don't think that this will do the trick. If I just call a get method and provide the name of the attribute as import parameter, I get method must now determine the attribute dynamically. I want to avoid in any case any SWITCH or IF cases, I want to access attribute values dynamically.
Regards, Mathias
2010 Jun 02 9:12 AM
hi,
you could concatenate the methodname, but you would still need to implement a real method which will returnjust the specific attribute:
concatenate 'get_' ld_attribute into ld_methodname
2010 Jun 02 9:16 AM
You have to access it using dynamic assing
FIELD-SYMBOLS <attr> TYPE string.
ASSIGN cl_abap_char_utilities=>('HORIZONTAL_TAB') TO <attr>.
Regards
Marcin
For reference [Accessing Class Components |http://help.sap.com/abapdocu_70/en/ABENCLASS_COMPONENTS_ADDRESSING.htm]
Edited by: Marcin Pciak on Jun 2, 2010 10:16 AM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |