Reputation: 4592
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
Upvotes: 5
Views: 5548
Reputation: 5554
You meant this, right?
report zstructsob.
*&---------------------------------------------------------------------*
*& Class MYCLASS
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
class myclass definition.
public section.
types: begin of mystruct, " ------------> The public type
field1 type i,
field2 type string,
end of mystruct.
methods print_data importing data type mystruct.
private section.
data mydata type mystruct.
endclass. "MYCLASS
*&---------------------------------------------------------------------*
*& Class (Implementation) MYCLASS
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
class myclass implementation.
method print_data.
write:/ data-field1, data-field2.
endmethod.
endclass. "MYCLASS
start-of-selection.
data ztype type myclass=>mystruct. " ------------> The public type of the class
data zclass type ref to myclass.
create object zclass.
ztype-field1 = 1.
ztype-field2 = 'Field2'.
zclass->print_data( ztype ).
Upvotes: 1
Reputation: 18483
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 =>
.
Upvotes: 7