What is a local Class in OOABAP ? Properties of local class in OOABAP


Local classes in SAP ABAP programming, properties of local classes in SAP ABAP

A+ A-

Classes are two types in SAP Classes, one is Global class which can be created in SE24 and second one is local class.Local class is a class which have definition and implementation in a program .

Syntax for creating local class is :
*CLASS DEFINITION
CLASS <CLASS NAME> DEFINITION.  "THIS IS CLASS DEFINITION
<ATTRIBUTES>
<METHODS>
<EVENTS>
<CONSTRUCTOR>
ENDCLASS.

*CLASS IMPLEMENTATION
CLASS <CLASS NAME> IMPLEMENTATION.
*METHODS, EVENTS IMPLEMENTATION
ENDCLASS. 

Defining attributes, methods and events in local classes

All the attributes, methods, events must be defined in between CLASS DEFINITION and ENDCLASS.
Syntax for declaring attributes in local classes
CLASS CL_EXAMPLE DEFINITION. "CLASS DEFINITION
PUBLIC SECTION. "VISIBILITY 
DATA : <ATTRIBUTE NAME> TYPE <TYPING>. "DECLARING INSTANCE ATTRIBUTE
CLASS-DATA: <ATTRIBUTE STATIC> TYPE <TYPING> . "DECLARING STATIC ATTRIBUTE
ENDCLASS.
Syntax for declaring methods in local classes
CLASS CL_EXAMPLE DEFINITION. "CLASS DEFINITION
PUBLIC SECTION. "VISIBILITY 
*DECLARING INSTANCE METHOD
METHODS : <METHOD NAME>
          IMPORTING <PARAMETER> TYPE <TYPING>
          EXPORTING <PARAMETER> TYPE <TYPING>.

*DECLARING STATIC METHOD
CLASS-METHODS : <METHOD NAME>
                IMPORTING <PARAMETER> TYPE <TYPING>
                EXPORTING <PARAMETER> TYPE <TYPING>.
ENDCLASS.
Syntax for declaring EVENTS in local classes
CLASS CL_EXAMPLE DEFINITION. "CLASS DEFINITION
PUBLIC SECTION. "VISIBILITY 
*DECLARING INSTANCE EVENT
EVENT : <event_name>.

*DECLARING STATIC EVENT
CLASS-EVENT : <event_name>.
ENDCLASS.
Syntax for declaring CONSTRUCTOR in local classes
CLASS CL_EXAMPLE DEFINITION. "CLASS DEFINITION
PUBLIC SECTION. "VISIBILITY 
*DECLARING INSTANCE CONSTRUCTOR
METHODS : CONSTRUCTOR
            IMPORTING <parameter> TYPE <typing>.
*DECLARING STATIC CONSTRUCTOR(CLASS CONSTRUCTOR)
CLASS-METHODS: CLASS_CONSTRUCTOR.


ENDCLASS.


Was this lesson helpful to you? Yes No 63 People out of 69 think this lesson helpful

Lesson Navigation

Inheritance in SAP OOABAP← Previous Lesson
Next Chapter →