ABAP OBJECT-ORIENTED PROGRAMMING-EXAMPLE01

原创 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).

 

<?XML:NAMESPACE PREFIX = O />


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.

Principles:

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.

Methodes:

  • 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.

 


Result:


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

ABAP常用函数总结

函数名 描述 SD_VBAP_READ_WITH_VBELN 根据销售订单读取表vbap中的信息 EDIT_LINES 把READ_TEXT返回的LINES中的行按照TDFORMAT=“*”重新组...
  • qq_36617521
  • qq_36617521
  • 2016年12月28日 09:20
  • 637

ABAP 7.4新特性(三): VALUE 操作符

关于VALUE前面也提到过了,其主要是用来给一个结构、内表等对象初始化值。主要有下面三个方式: ...value dtype\#()  构造一个任意类型的初始值 ...value dtype\#( c...
  • yang362046076
  • yang362046076
  • 2016年06月06日 17:32
  • 1794

ABAP 屏幕容器ALV显示

抬头: ************************************OO ALV属性声明及定义*************** DATA: gcl_alv       TYPE REF ...
  • u012413770
  • u012413770
  • 2013年10月12日 09:36
  • 601

ABAP开发常用的表

1 两个内表相拷可用表达式: ITABA[] = ITABB[]. 2. 为了提高程序的运行速度: Uesing ABAP sort clause instead of order by. 3...
  • zhongguomao
  • zhongguomao
  • 2016年05月13日 12:11
  • 954

ABAP总结-转载,好全啊

后续本人添加: 事件流(6个):   INITIALIZATION(初始化)   AT SELECTION-SCREEN(屏幕跳出前)   START-OF-S...
  • zliguangyu
  • zliguangyu
  • 2013年04月10日 11:26
  • 19218

SAP ABAP入门学习-基本语法

SAP ABAP入门学习-基本语法
  • happy987852720
  • happy987852720
  • 2016年12月16日 14:41
  • 1359

ABAP开发 ~消息处理 (Messages)

14.         Messages 14.1.     00消息ID中的通用消息 00消息ID中的001消息本身未设置任何消息串,这条消息可以传递8个参数,在用于拼接消息时很有用 ME...
  • qq_37625033
  • qq_37625033
  • 2017年03月13日 15:13
  • 2293

ABAP数据库—更新数据

Open SQL中使用INSERT、UPDATE、MODIFY和DELETE语句进行数据的更新操作,其中当SY-DBCNT返回为0,则表示操作成功,此外还将返回实际操作的数据行数。需要指明的是Open...
  • zhongguomao
  • zhongguomao
  • 2016年11月26日 14:52
  • 3205

abap中制作word文档并排版打印SAPscript

这次要完成的功能是,在abap中制作一个事务码,通过普通的输入框获取数据,然后将数据排版到一个word文档中,并可以打印这个文档。 对于word文档的制作需要用到事务码se71 也就是SAPscrip...
  • charliefromkansas
  • charliefromkansas
  • 2015年08月31日 13:08
  • 912

对abap语言的一点猜想和逆推,优缺…

对abap语言的一点猜想和逆推。这个语言整体用大写字母。其风格跟sql和fortrun很像。我感觉整个就是sql的扩展。其他语言要链接数据库,必须输入用户名和密码。然后还有数据库的地址。不同的数据库要...
  • u010770993
  • u010770993
  • 2017年04月21日 10:51
  • 262
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ABAP OBJECT-ORIENTED PROGRAMMING-EXAMPLE01
举报原因:
原因补充:

(最多只允许输入30个字)