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: 

Step by step procedure to Define Class

Former Member
0 Kudos

Hi Experts!!

Anybody please tell me step by step procedure do develop the class.

Thanks

Anee

1 ACCEPTED SOLUTION
2 REPLIES 2

Former Member
0 Kudos

Hi

Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class.

components of the class describe the state and behavior of objects.

Local and Global Classes: Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository.

Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined.

When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class.

Apart from the visibility question, there is no difference between using a global class and using a local class.

Certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.

Defining Local Classes:

A complete class definition consists of a declaration part and, if required, an implementation part.

The declaration part of a class <class>

CLASS <class> DEFINITION. ... ENDCLASS.

It contains the declaration for all components (attributes, methods, events) of the class.

The declaration part belongs to the global program data.

If you declare methods in the declaration part of a class, you must also write an implementation part for it. This consists of a further statement block:

CLASS <class> IMPLEMENTATION. ... ENDCLASS

The implementation part of a local class is a processing block. Subsequent coding that is not itself part of a processing block is therefore not accessible.

REPORT YSUBOOPS17 .

CLASS c1 DEFINITION.

PUBLIC SECTION.

data : w_num type i value 5.

methods : m1.

ENDCLASS.

CLASS c1 IMPLEMENTATION.

METHOD M1.

WRITE:/5 'I am M1 in C1'.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : oref1 TYPE REF TO c1 .

CREATE OBJECT : oref1.

write:/5 oref1->w_num.

CALL METHOD : oref1->m1 .

Defined in the global area of a local program :-

CLASS <class name> DEFINITION.

…..

ENDCLASS.

All the attributes , methods, events and interfaces are declared here.

Cannot be declared inside a subroutine/function module.

Class definition cannot be nested.

REPORT YSUBOOPS17 .

CLASS c1 DEFINITION.

PUBLIC SECTION.

data : w_num type i value 5.

methods : m1.

ENDCLASS.

CLASS c1 IMPLEMENTATION.

METHOD M1.

WRITE:/5 'I am M1 in C1'.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : oref1 TYPE REF TO c1 .

CREATE OBJECT : oref1.

write:/5 oref1->w_num.

CALL METHOD : oref1->m1 .

Local class in a program is implemented as follows:-

CLASS <class name> IMPLEMENTATION.

…..

ENDCLASS.

Methods used by the class are described here.

A class can be implemented

At the end of the program( like subroutines).

After the class definition.

If the latter is adopted, one must then assign subsequent non-declarative statements explicitly to a processing block, such as START-OF-SELECTION, so that they can be accessed.