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

Object creation problem

Former Member
0 Likes
1,066

Hi,

I'm working on a small transaction, in which I already defined some classes. In the TOP include for this transaction, I'm trying to define a reference to an object by writing:

DATA objref TYPE REF TO student.

Student is a class, inheriting from the Person abstract class.

This doesn't work, I get an error saying that 'STUDENT' is unknown. The weird thing is, if I do:

DATA objref TYPE REF TO person.

It works fine...

I really don't understand this at all, so if someone have an idea of what's going on, please give me a hand

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,024

hi Thomas,

As i understand, there are some already defined classes. and you are trying to define a reference to an object which is the child of some class(person) in TOP include.

The subclass(student) does not exist in the include that is the reason you are not able to crreate the ref to this. However, as the parent class(person) exist in this include you can create an object ref to this class.

I would suggest you to either define the subclass in the top include or define the reference to the object(student) in the main program.

Regards,

Richa

5 REPLIES 5
Read only

Former Member
0 Likes
1,024

Hello,

Where you defined the classes and where are you trying to create object.

Regs,

Venkat

Read only

Former Member
0 Likes
1,024

Thomas,

As u said here that student is inherted from person. Object reference should be created first for that.

Check the below links for OO ABAP:

/people/sap.user72/blog/2005/05/10/a-small-tip-for-the-beginners-in-oo-abap

http://www.geekinterview.com/Interview-Questions/Concepts/OOPS

http://www.geocities.com/victorav15/sapr3/abap_ood.html

http://www.erpgenie.com/abap/OO/eg.htm

http://www.brabandt.de/html/abap_oo.html

http://www.erpgenie.com/sap/abap/OO/index.htm

Also check the transaction ABAPDOCU there are lot of programs related to OOPS.

Regards,

Prakash.

Read only

Former Member
0 Likes
1,025

hi Thomas,

As i understand, there are some already defined classes. and you are trying to define a reference to an object which is the child of some class(person) in TOP include.

The subclass(student) does not exist in the include that is the reason you are not able to crreate the ref to this. However, as the parent class(person) exist in this include you can create an object ref to this class.

I would suggest you to either define the subclass in the top include or define the reference to the object(student) in the main program.

Regards,

Richa

Read only

Former Member
0 Likes
1,024

Here is my program (orders of the different includes):

INCLUDE ZSRS_OBJ_TOP.

INCLUDE ZSRS_OBJ_CLASSES.

...

All my classes (including Person) are defined and implemented in the ZSRS_OBJ_CLASSES include. That means I even shouldn't be able to do:

DATA objref TYPE REF TO person.

in my TOP ?

Read only

Former Member
0 Likes
1,024

Problem solved: I removed the classes include from the program code and put in on top of the TOP include, just after the PROGRAM statement.

Thanks for the help.