How to access a public type of an object
abap
Solution
You have to use the appropriate component selector:
Defined character that can be used to address components of upper units. There is a structure component selector (`-`), a class component selector (`=>`), an interface component selector (`~`), and an object component selector (`->`).
In this case, you're accessing a type (component) of a class, so you have to use `=>`.
Problem
I have a class named ZCL_RM_SPREADSHEETML. It has in the Types tab a type called TY_STYLE with visibility 'Public' and it is defined with Direct Type Entry. When I try to declare in the caller code the following : ``` DATA : wa_blue_style TYPE zcl_rm_spreadsheetml-ty_style. ``` I get the following: ``` The type "ZCL_RM_SPREADSHEETML" has no structure and therefore no component called "TY_STYLE". . ``` This makes some sense I guess as ZCL_RM_SPREADSHEETML is a class, also double-clicking `TY_STYLE` does absolutely nothing. Then I tried the following with a tilda: ``` DATA : wa_blue_style TYPE zcl_rm_spreadsheetml~ty_style. ``` I got the following: ``` Type "ZCL_RM_SPREADSHEETML~TY_STYLE" is unknown ``` Double clicking TY_STYLE will bring me though to the definition of TY_STYLE, so I must be close. The last time I had a similar issue it was because I was accessing a private method, but I marked the type clearly as Public. Any ideas of what I am doing wrong? EDIT I also tried per the comment ``` DATA : wa_blue_style TYPE ref to zcl_rm_spreadsheetml->ty_style. "and DATA : wa_blue_style TYPE zcl_rm_spreadsheetml->ty_style. ``` which gives ``` Field "ZCL_RM_SPREADSHEETML" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. ``` Which gave me the idea to try this the 'class' way, ``` DATA : wa_blue_style TYPE zcl_rm_spreadsheetml=>ty_style. ``` This works