Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to access Instance Attribute in a Class Interface from FM ?

Former Member
0 Likes
11,633

Hi Experts

I have the following function module code, that passes the syntax, however in the class interface ABC, I have an attribute IJK that is Instance Attribute (Public). When I modify the code like ABC->IJK but it does not like it, the error is :-

Field "ABC" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. "DATA" statement.

Question : How do I declare the Class Interface ABC in my Function Module that will allow me to access the Instance Attribute ?

Thanks in advance.

FUNCTION XYZ.

if not ABC=>EFG is initial.

output = ABC=>EFG.

shift output left deleting LEADING space.

endif.

ENDFUNCTION.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,398

Do like this :

data : reference typ ref to abc.

create object reference.

output = reference->ijk

Edited by: pr@t on Aug 19, 2010 8:53 AM

3 REPLIES 3
Read only

Former Member
0 Likes
3,399

Do like this :

data : reference typ ref to abc.

create object reference.

output = reference->ijk

Edited by: pr@t on Aug 19, 2010 8:53 AM

Read only

uwe_schieferstein
Active Contributor
0 Likes
3,398

Hello

You question only makes sense if

(1) the class / interface is part of the FM's interface (i.e. an IMPORTING - or perhaps CHANGING - parameter)

(2) the class / interface is defined as global variable in the TOP include of the function group

If either of these two options is applicable then the coding may look like this:


" (1) IMPORTING parameter: e.g. IO_INSTANCE TYPE REF TO class / interface name

IF ( io_instance IS BOUND ).
  io_instance->abc = 'New value'.
ENDIF.


" (2) Global variable of function group, e.g. GO_INSTANCE TYPE REF TO class / interface name:
IF ( go_instance IS BOUND ).
  go_instance->abc = 'New value'.
ENDIF.

Obviously, the public attribute ABC must be changeable (i.e. not READ-ONLY).

Regards

Uwe

Read only

Former Member
0 Likes
3,398

Thanks for your responses and helpful hints.

I awarded the points. Before your response I managed to resolve it with following syntax, similar to the one proposed.

DATA dref TYPE REF TO ABC.

DATA: f2 LIKE dref->EFG.

if not ABC->EFG is initial.

output = ABC->EFG.

shift output left deleting LEADING space.

endif.