Application Development 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: 

Class-DEFERRED?

Former Member
0 Kudos

Hi,

In creation of CLASSES, we use the DEFERRED, INHERETED, LOAD and for declaring the Methods & Import paras., we use PUBLIC SECTION, PRIVATE SECTION, So What does they mean?

ThanQ.

Message was edited by:

Srinivas

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor

Hi,

Here is a small example on using class deferred.

Suppose you have 2 class ... Class1 and Class2

Using the Class deferred, you are indicating the system that the class what you are defining is in the same context.

For example.

Class Class2 defination deferred.

CLASS Class1 DEFINITION.

DATA ABCD TYPE REF TO Class2.

"here you can still able use the reference variable of Class 2 although you haven't declared it as yet.

ENDCLASS.

CLASS Class2 DEFINITION.

DATA XYZ TYPE REF TO Class1.

ENDCLASS.

Otherwise, SAP would have looked for Class2 in the global library and would have given you error. So, in simple words its an indication to the system that 'Do not look in the higher level context'.

Regards,

Ferry Lianto

7 REPLIES 7

ferry_lianto
Active Contributor

Hi,

Here is a small example on using class deferred.

Suppose you have 2 class ... Class1 and Class2

Using the Class deferred, you are indicating the system that the class what you are defining is in the same context.

For example.

Class Class2 defination deferred.

CLASS Class1 DEFINITION.

DATA ABCD TYPE REF TO Class2.

"here you can still able use the reference variable of Class 2 although you haven't declared it as yet.

ENDCLASS.

CLASS Class2 DEFINITION.

DATA XYZ TYPE REF TO Class1.

ENDCLASS.

Otherwise, SAP would have looked for Class2 in the global library and would have given you error. So, in simple words its an indication to the system that 'Do not look in the higher level context'.

Regards,

Ferry Lianto

0 Kudos

Thank you Ferry, really helpful and meaningful answer. Really appriciate your explanation.

0 Kudos

Thank you. good explanation with example

Former Member
0 Kudos

hi,

chk this help

The variant with the DEFERRED addition makes a class known provisionally in the program.

Without the PUBLIC addition, this variant makes a local class known before its actual definition. The program must contain an actual declaration part for class at a later point in the program. You cannot access individual components of the class before it is actually defined. You need to use this statement if you want to make a reference to a local class before it is defined.

With the PUBLIC addition, this variant makes a global class known and defers loading the class until the end of the current program unit. You can only access individual components of the class after it has been loaded. This statement can be used to prevent unwanted recursion when making references to global classes.

Former Member
0 Kudos

hi,

<b>Deferred.</b>

Used to refer to a class at some point in a code and the class is not defined before the line.

CLASS C2 DEFINITION DEFERRED.
 CLASS C1 DEFINITION.
  PUBLIC SECTION.
    DATA O2 TYPE REF TO C2.
 ENDCLASS.
 CLASS C2 DEFINITION.
  public section.
    data : num type i value 5.
ENDCLASS.
start-of-selection.
 data : obj1 type ref to C1.
  CREATE OBJECT obj1.
  create object obj1->o2.
  write:/5 obj1->o2->num .

<b>Load</b>

The compiler normally loads the description of a global class from the class library the first time you use the class in your program . However, if the first access to a global class in a program is to its static components or in the definition of an event handler method , you must load it explicitly using the statement CLASS class DEFINITION LOAD. This variant has no corresponding ENDCLASS statement.

<b>Visibility of Components</b>

Each class component has a visibility. In ABAP Objects the whole class definition is separated into three visibility sections: PUBLIC, PROTECTED, and PRIVATE. One can never change component visibility via inheritance.

<b>PUBLIC:</b> This section is made up of the subclass' own public components together with all public components of all superclasses. There is unrestricted access to the public section of the subclass.

<b>PROTECTED:</b> This section is made up of the subclass' own protected components together with all protected components of all superclasses .

<b>PRIVATE:</b> This section is made up of the subclass' own private components accessible only in that subclass. Each subclass works with its own private components and can't even use the private components of its superclasses. But as long as a method inherited from a superclass is not redefined, it still uses the private attributes of the superclass, not those of the subclass, even if the subclass has private attributes of the same name.

Hope this helps.

Regards,

Richa

Former Member
0 Kudos

hi Srinivas,

Public components:
     -  visibile to all
Protected components:
     - visible within class
     - visible within subclasses
Private componets:
     - only visible within the class

Hope this helps,

Sajan Joseph.

0 Kudos

Thanx to all.