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

Changing public instance attribute

Former Member
0 Likes
3,321

Hi all,

i'm a newbie in programming OO. So i have a little Problem with my Coding.

i have to change a value vom a structure. It an public instance attribute from the superclass. So how can i change it?

coding it like this:

go_busobj_created-ms_detail-nr = '1020'.

shows an error that go_busobj_created ist an objectreferenz and does'n own a component "ms_detail-snunr" - But in debugging i can navigate with doubleclick into ms_detail and ich can change manually thy value.

The other way i tried is using the method from a superclass that my object (go_busobj_created) inherits during runtime. But i don't know how to call it.

call METHOD CL_SUPERCLASS=>('SET_NR')
or
call METHOD ('IF_SUPERCLASS~SET_NR')

I can call static or dynamic - everytime it dumps..

Thanks for your help.

Stefan

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,445

Hello Stefan

Based on my knowledge from RE-FX I assume that GO_BUSOBJ is a very generic object reference. Thus, in order to access the instance attribute MS_DETAIL you have to do a narrowing cast:

DATA:
  go_busobj       TYPE REF TO <generic class>,
  go_specific      TYPE REF TO <specific class which is a subclass of generic class>.

  go_specific ?= go_busobj.  " narrowing cast
  go_specific_created->ms_detail-nr = '1020'.

For example, the BDT function modules in RE-FX pass most (if not all) object references as TYPE REF TO cl_reca_storable. The actual object may be a contract (CL_RECN_CONTRACT), a building (CL_REBD_BUILDING) or some other RE object.

Regards

Uwe

4 REPLIES 4
Read only

Peter_Inotai
Active Contributor
0 Likes
1,445

Hi Stefan,

If it's an instance attribute, first you have to create an object reference to your class. Then you can modify the attribute of that instance.


data: gro_something type ref to cl_myclass.
...
create object gro_something.
...
gro_something-ms_detail-nr = '1020'.

Best regards,

Peter

Read only

Former Member
0 Likes
1,445

Hi,

i defined it like this:

DATA go_busobj_created TYPE REF TO IF_BUS_OBJECT.

in this IF the Object doesn't know the methods or the attribute.

it's known only during program runtime.

the go_busobj_created is created by another method i called (create obj by template)

is it relevant?

Message was edited by:

Stefan Mett

Message was edited by:

Stefan Mett

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,446

Hello Stefan

Based on my knowledge from RE-FX I assume that GO_BUSOBJ is a very generic object reference. Thus, in order to access the instance attribute MS_DETAIL you have to do a narrowing cast:

DATA:
  go_busobj       TYPE REF TO <generic class>,
  go_specific      TYPE REF TO <specific class which is a subclass of generic class>.

  go_specific ?= go_busobj.  " narrowing cast
  go_specific_created->ms_detail-nr = '1020'.

For example, the BDT function modules in RE-FX pass most (if not all) object references as TYPE REF TO cl_reca_storable. The actual object may be a contract (CL_RECN_CONTRACT), a building (CL_REBD_BUILDING) or some other RE object.

Regards

Uwe

Read only

Former Member
0 Likes
1,445

Great! Thank you!

Now it works.

Have a nice day

Stefan