CLASS - DEFINITION - ABAP Keyword Documentation (2024)

SAP NetWeaver AS ABAP Release 752, ©Copyright 2017 SAP AG. All rights reserved.

ABAP - Keyword Documentation→ABAP - Reference→Declarations→Declaration Statements→Classes and Interfaces→CLASS→

CLASS - DEFINITION

Syntax

CLASS class DEFINITION [class_options].
[PUBLIC SECTION.
[components]]
[PROTECTED SECTION.
[components]]
[PRIVATE SECTION.
[components]]
ENDCLASS.

Effect

The statement block CLASS class DEFINITION - ENDCLASS declares a class named class.Naming conventions apply to the name class.componentsof the class are declared between CLASS and ENDCLASS. Each component must be included in avisibility sectionafter one of the statements PUBLIC SECTION, PROTECTEDSECTION, or PRIVATE SECTION. These statements must be specified in the order above. The class does not need to include all the SECTION statements.

The class options additionsof the statement CLASS can be used to publish a class globally in the class library, define an inheritance relationship, make the class abstract or final, control where the class can be instantiated, and offerfriendship to other classes or interfaces.

Notes

  • The class is the smallest encapsulation unit in ABAP Objects. A method can therefore use all componentsof all instances of the same class apart from the components of its own instance. An exception to this rule are subclasses that cannot access the private components of superclasses, if they are not theirfriends.
  • The declaration part of a class can only be specified in the context described under CLASS.

Example

Declaration part of a class with statements for declaringstatic components andinstance components.

CLASS cls DEFINITION FINAL.
PUBLIC SECTION.
TYPES:
type1 TYPE ...
CLASS-DATA:
attr1 TYPE ...
...
CLASS-METHODS:
meth1 ...
...
CLASS-EVENTS:
evt1 ...
...
DATA:
attr2 TYPE ...
...
METHODS:
meth2 ...
...
EVENTS:
evt2 ...
...
ENDCLASS.

Continue
CLASS - class_options
PUBLIC SECTION
PROTECTED SECTION
PRIVATE SECTION
CLASS - components

CLASS - DEFINITION - ABAP Keyword Documentation (2024)
Top Articles
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6235

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.