|
In this chapter we will teach you how to create classes in ABAP. In ABAP, classes can be of two types: Local and Global. As the name suggests Local classes can be used locally inside the declared program only, while the global classes are available globally to be used across different programs. A local class is created within a program (ABAP Editor) while a global class is created with class builder (transaction SE24) A Class can have 2 parts - Definition and Implementation. In class definition we will define the attributes and methods of class (static and instance both) and in class implementation we will implement the methods of class. Local Classes As stated above the local classes are visible only inside the program that they are created in. The below example shows how to create a local class. Please note the syntax also. The key words are shown in CAPS ******************************************************************* CLASS human DEFINITION.
PUBLIC SECTION { "Define attributes, methods and events here. }
PRIVATE SECTION { "Define attributes, methods and events here. }
PROTECTED SECTION { "Define attributes, methods and events here. }
ENDCLASS.
CLASS human IMPLEMENTATION. METHOD kick. ** Implement the method to Kick here ENDMETHOD.
ENDCLASS. ****************************************************************** Global Classes Global classes are declared in the class editor (transaction SE24). When you create a class here, just give the class name and press create button. On the new screen give a description for the class. Leave all other fields as defaulted. These will be explained in further chapters. Here you will see different tabs provided to define the attributes and methods of the class. Define the attributes and methods. To implement a method, double click on the method name to open the standard ABAP editor. Here you can write your code.
|