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

create object

Former Member
0 Likes
7,827

what is creat object XXXXX

where i can see it

what is the target?

9 REPLIES 9
Read only

FredericGirod
Active Contributor
0 Likes
6,991

Hi,

create object, will create the object reference to the class.

Double click on the object name, you will show something like that : obj_name type ref to cl... where cl is the class name that the object point to.

So go in SE24 with this class name and look the method CONSTRUCTOR. You will show the parameter, the code of the "create object"

Rgd

Frédéric

Read only

Former Member
0 Likes
6,991

hi liat,

create object is used in OO abap.

data: abc type ref to cl_gui_alv_grid. "reference

create object abc. "this will create the object of cl_gui_alv_grid class.

regards

vijay

Read only

Former Member
0 Likes
6,991

Hi,

This is from F1 on statement "Create"...

CREATE OBJECT

Syntax Forms

Defining a Class Implicitly

1. CREATE OBJECT oref [area_handle] [parameter_list].

Defining a Class Explicitly

2. CREATE OBJECT oref [area_handle]

TYPE {class|(name)} [parameter_list].

Effect

The CREATE OBJECT statement creates an instance of a class or object and assigns the object reference to the reference variable oref. Directly after the object has been created, the instance constructor of the class is executed.

By default, the object is created in the internal session of the current program and remains there as long as it is needed. When it is no longer referenced by any reference variable, it is deleted from the garbage collector . You can use the area_handle addition to create the object as a shared object.

The reference variable oref must be declared as an object reference variable. Instance components of an object created using CREATE OBJECT can only be accessed using object reference variables (see Data Objects in Operand Positions).

You can use the TYPE addition to specify the class of the created object. The static type of the object reference variable must be more general than or identical to the class of the created object, in accordance with the rules for Assignments Between Object Reference Variables.

With the parameter_list addition you must fill the non-optional input parameters of the first explicitly implemented instance constructor, which is on the path of the inheritance tree from the instantiated class to the root class object. You can also use the parameter_list addition to assign return values to the non-class-based exceptions of the instance constructor.

If an exception that can be handled occurs in the runtime environment during the creation of the object, it is not created and the object reference variable oref is initialized. If, after the object has been created, an exception that can be handled occurs in the instance constructor of the class or a message is sent using MESSAGE RAISING, the created object is deleted and the object reference oref is initialized.

Return Value

If the CREATE OBJECT statement is executed successfully, sy-subrc is set to 0. Values other than 0 are set by specifying EXCEPTIONS in parameter_spec when non-class-based exceptions of the instance constructor are handled.

Note

You can only create an instance of a class where permitted by the AB>CREATE addition to the CLASS DEFINITION statement.

Exceptions

Catchable Exceptions

CX_SY_CREATE_OBJECT_ERROR

Cause: You tried to instantiate an abstract class

Runtime Error: CREATE_OBJECT_CLASS_ABSTRACT (catchable)

Cause: The class specified in the TYPE addition does not exist

Runtime Error: CREATE_OBJECT_CLASS_NOT_FOUND (catchable)

Cause: You tried to instantiate a private class externally

Runtime Error: CREATE_OBJECT_CREATE_PRIVATE (catchable)

Cause: You tried to instantiate a protected class externally

Runtime Error: CREATE_OBJECT_CREATE_PROTECTED (catchable)

Non-Catchable Exceptions

Cause: You must specify a reference as the target variable

Runtime Error: CREATE_OBJECT_NO_REFTYPE:

Thanks,

Renjith

Read only

0 Likes
6,991

The CREATE OBJECT statement can also refer to the creation of an OLE object when working with Object Link Enablement.



report zrich_0003.



include ole2incl.

data: e_appl  type ole2_object.


* Start the application
create object e_appl 'EXCEL.APPLICATION'.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
6,991

Hi Liat,

CREATE OBJECT XXX

is the syntax for creating a reference(pointer) to an existing class, which is either a global class(which can be defined using SE24 or Class Builder) or a local class (which is defined and implemented in ABAP program itself).

If you are not new to Object Oriented Programming, then I must say that execution of this statement causes the constructor of the class to be executed.

In the above statement XXX is the object which is defined as

DATA: XXX type ref to YYY,

where YYY is the name of the class, so that XXX becomes the pointer of the class. After CREATE OBJECT statement is executed , we can access the functions of the class using the syntax

CALL FUNCTION XXX->function_name.

Hope this will help you in exploring more regarding OOP.

Thanks and regards,

Sylendra.

Read only

0 Likes
6,991

Sylendra:

XXX is not a pointer to a class but to object which is an instance of class.

Objects do not have functions but methods and you can call them with CALL METHOD

Read only

0 Likes
6,991

Hi Tomasz,

DATA: XXX type ref to YYY.

CREATE OBJECT XXX.

Here XXX is the name of the object. This second statement creates an instance XXX of the class YYY,so that by using the reference symbol '->' XXX can access the methods of YYY.

Sorry for mentioning FUNCTIONS instead of METHODS.

Regards,

Sylendra.

Read only

Former Member
0 Likes
6,991

Hi Liat,

A small correction.. The method of the class can be called using the syntax

CALL METHOD XXX->function_name.

Hope this has helped you.

If so, please award points by clicking on the left of reply.

If you have any doubts on OOP, you can contact me .

My mail id is sylendra.prasad@wipro.com

Thanks and regards,

Sylendra.

Read only

Former Member
0 Likes
6,991

hi experts,

My task is to display 2 radiobutton on the same screen as the alv grid display.on selection of the 1 radiobutton the grid need to display one internal table.. and on selection of 2nd radiobutton the grid sud display second internal table..

please explain wid some example...