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
Get and print the type of an object: type() type() returns the type of an object. You can use this to get and print the type of a variable and a literal like typeof in other programming languages. The return value of type() is type object such as str or int .
You're talking about the same object reference, and yes it is possible. All objects are effectively public as all Object methods are public. If you can get a reference to it via any means, you have access to that object.
How to access the object in the class? Explanation: Objects in the method can be accessed using direct member access operator which is (.).
The java “instanceof” operator is used to test whether the object is an instance of the specified type (class or subclass or interface). It is also known as type comparison operator because it compares the instance with type. It returns either true or false.
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 =>
.
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 ).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With