原创 2005年03月01日 09:47:00
1. Simple class

This example shows how to create a simple employee class. The constructor method is used to initialize number and name of thje employee when the object is created. A display_employee method can be called to show the attributes of the employee, and CLASS-METHOD dosplay_no_of_employees can be called to show the total number of employees (Number of instances of the employee class).



2. Inheritance and polymorphism

This example uses a superclass lcl_company_employees and two subclasses lcl_bluecollar_employee and lcl_whitecollar_employee to add employees to a list and then display a list of employees and there wages. The wages are calcukated in the method add_employee, but as the wages are calculated differently for blue collar employees and white collar emplyees, the superclass method add_employee is redeifined in the subclasses.


Create super class LCL_CompanyEmployees.

The class has the methods:

  • Constructor
  • Add_Employee - Adds a new employee to the list of employees
  • Display_Employee_List - Displays all employees and there wage
  • Display_no_of_employees - Displays total number of employees

Note the use of CLASS-DATA to keep the list of employees and number of employees the same from instance to instance.

Create subclasses lcl_bluecollar_employee and lcl_whitecollar_employee. The calsses are identical, except for the redifinition of the add_employee method, where the caclculation of wage is different.


  • Constructor. The constructor is used to initialize the attributes of the employee. Note that the constructor in the supclasss has to be called from within the constructor of the subclass.
  • Add_Employee. This is a redinition of the same method in the superclass. In the redefined class the wage is calcuated, and the superclass method is called to add the employees to the emploee list.:

The program





The resulting report

List of Employees
1 Karen Johnson 2.850
2 John Dickens 7.500

Total number of employees: 2

3. Interfaces

This example is similiar to th eprevious example, however an interface is implemented with the method add_employee. Note that the interface is only implemented in the superclass ( The INTERFACE stament), but also used in the subclasses.

The interface in the example only contains a method, but an iterface can also contain attrbutes, constants, types and alias names.

The output from example 3 is similiar to the output in example 2.

All changes in the program compared to example 2 are marked with red.





4. Events

This is the same example as example 4. All changes are marked with red. There have been no canges to the subclasses, only to the superclass and the report, sp the code for th esubclasses is not shown.

For a simple example refer to Events in Examples.



Employee added to list Karen Johnson
Employee added to list John Dickens
List of Employees
1 Karen Johnson 2.850
2 John Dickens 7.500

Total number of employees: 2

Object-Oriented Programming With Abap Objects_Original

  • 2014年12月02日 16:10
  • 53.41MB
  • 下载

学习SAP OO可用的资料

1 Basic ABAP OO eLearnings http://scn.sap.com/people/thomas.jung/blog/2009/08/11/basic-abap-oo-elear...
  • fengyan5022
  • fengyan5022
  • 2015-12-23 11:47:41
  • 803

abap 面向对象编程方法-CLASS创建 step by step

  • 2009年07月24日 16:37
  • 387KB
  • 下载

The Object-Oriented Thought Process (3rd Edition)

  • 2008年12月05日 22:06
  • 3.36MB
  • 下载

Object-Oriented Software Construction 2nd

  • 2008年11月10日 19:56
  • 11.55MB
  • 下载

《Object-Oriented Programming With ANSI-C》之第四章(继承——代码重用和改进)

第四章     继承——代码重用和改进   4.1 一个超级类——点        我们将在这章以一个基本的画图程序作为开始。这里是是我们乐意拥有的其中一个类的快速测试如下: #include...
  • besidemyself
  • besidemyself
  • 2011-07-06 13:35:18
  • 2569

Design Patterns Elements of Reusable Object-Oriented Software(一)Introduction(介绍)

1.Introduction(介绍) Designing object-oriented software is hard,and designing reusable object-oriented...
  • liuzuyi200
  • liuzuyi200
  • 2013-07-17 10:29:45
  • 1429

Object-Oriented Software Construction 中文版 + 英文

  • 2012年12月30日 14:34
  • 11.55MB
  • 下载

【Java】Java学习笔记之一 ----面向对象(Object-Oriented)

  • GO_D_OG
  • GO_D_OG
  • 2017-07-17 17:53:34
  • 151