Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Access class attribute by class name

Hi experts,

Can anyone help me in next situation.

I need access class static attribute by class name and attribute name. I have two initialized variables

DATA: class_name(30) TYPE c,

attr_name(30) TYPE c.

In another words, I need to do attribute initializing like

ZCL_IM_BM_VPA10_IMPL=>P_VAR_ZPLV_CLM = loc_var_range-low.

but using char variables insead of reference to class.

Thanks in advance,

Max.

Tags:
replied

Hi

U can use the field-symbols:

CLASS LCL_MY_CLASS DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA: VAR1 TYPE C,
                VAR2 TYPE C.
ENDCLASS.

CLASS LCL_MY_CLASS IMPLEMENTATION.
ENDCLASS.


DATA: CLASS_NAME(30) TYPE C,
      CLASS_VAR(30)  TYPE C,
      CLASS_REF(100) TYPE C.

FIELD-SYMBOLS: <VAR> TYPE ANY.

CLASS_NAME = 'LCL_MY_CLASS'.
CLASS_VAR  = 'VAR1'.

CONCATENATE CLASS_NAME '=>' CLASS_VAR INTO CLASS_REF.
ASSIGN (CLASS_REF) TO <VAR>.
IF SY-SUBRC = 0.
  <VAR> = 'A'.
ENDIF.

WRITE: LCL_MY_CLASS=>VAR1.

Max

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question