6 Columns with Active Background
6 Columns with Active Background
Active List Item Background

24OOP3108 – Steps to Create object for the class

In ABAP, objects are created using the keyword “CREATE OBJECT”. There are three ways to create objects in ABAP – based on reference, based on reference to the class and based on reference to the object.

 

  1. Based on Reference:

Creating an object based on reference means that the object is created using a reference variable. This reference variable points to an existing object and is used to access its methods and attributes. To create an object based on reference, we use the following syntax:

Syntax:

CREATE OBJECT <reference_variable> TYPE <class_name>.

 

Example:

DATA: lo_object TYPE REF TO <class_name>.

CREATE OBJECT lo_object TYPE <class_name>.

In this example, we have created an object of type <class_name> using the reference variable lo_object. This object can now be used to access the methods and attributes of the class.

  1. Based on Reference to the Class:

Creating an object based on reference to the class means that the object is created using the class name itself. This is similar to creating an object in other programming languages. To create an object based on reference to the class, we use the following syntax:

Syntax:

CREATE OBJECT <reference_variable> TYPE <class_name>.

Example:

DATA: lo_object TYPE REF TO <class_name>.

CREATE OBJECT lo_object TYPE <class_name>.

In this example, we have created an object of type <class_name> using the class name itself. This object can now be used to access the methods and attributes of the class.

  1. Based on Reference to the Object:

Creating an object based on reference to the object means that the object is created using an existing object. This is useful when we want to create a new object with the same attributes and values as an existing object. To create an object based on reference to the object, we use the following syntax:

Syntax:

CREATE OBJECT <reference_variable> LIKE <existing_object>.

Example:

DATA: lo_object1 TYPE REF TO <class_name>,

      lo_object2 TYPE REF TO <class_name>.

CREATE OBJECT lo_object1 TYPE <class_name>.

lo_object1->attribute = ‘value’.

CREATE OBJECT lo_object2 LIKE lo_object1.

 

In this example, we have created an object lo_object1 of type <class_name> and set a value for its attribute. Then, we have created another object lo_object2 using the LIKE keyword, which creates a new object with the same attributes and values as lo_object1.

 

Author : Aniket Pawar, 9373518385                                                     

24OOP3108 – Steps to Create object for the class

In ABAP, objects are created using the keyword “CREATE OBJECT”. There are three ways to create objects in ABAP – based on reference, based on reference to the class and based on reference to the object.

 

  1. Based on Reference:

Creating an object based on reference means that the object is created using a reference variable. This reference variable points to an existing object and is used to access its methods and attributes. To create an object based on reference, we use the following syntax:

Syntax:

CREATE OBJECT <reference_variable> TYPE <class_name>.

 

Example:

DATA: lo_object TYPE REF TO <class_name>.

CREATE OBJECT lo_object TYPE <class_name>.

In this example, we have created an object of type <class_name> using the reference variable lo_object. This object can now be used to access the methods and attributes of the class.

  1. Based on Reference to the Class:

Creating an object based on reference to the class means that the object is created using the class name itself. This is similar to creating an object in other programming languages. To create an object based on reference to the class, we use the following syntax:

Syntax:

CREATE OBJECT <reference_variable> TYPE <class_name>.

Example:

DATA: lo_object TYPE REF TO <class_name>.

CREATE OBJECT lo_object TYPE <class_name>.

In this example, we have created an object of type <class_name> using the class name itself. This object can now be used to access the methods and attributes of the class.

  1. Based on Reference to the Object:

Creating an object based on reference to the object means that the object is created using an existing object. This is useful when we want to create a new object with the same attributes and values as an existing object. To create an object based on reference to the object, we use the following syntax:

Syntax:

CREATE OBJECT <reference_variable> LIKE <existing_object>.

Example:

DATA: lo_object1 TYPE REF TO <class_name>,

      lo_object2 TYPE REF TO <class_name>.

CREATE OBJECT lo_object1 TYPE <class_name>.

lo_object1->attribute = ‘value’.

CREATE OBJECT lo_object2 LIKE lo_object1.

 

In this example, we have created an object lo_object1 of type <class_name> and set a value for its attribute. Then, we have created another object lo_object2 using the LIKE keyword, which creates a new object with the same attributes and values as lo_object1.

 

Author : Aniket Pawar, 9373518385