REPORT ZTHOMAS_OO_INTERFACE.
"definition of interface
*----------------------------------------------------------------------*
* INTERFACE lif_employee
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE LIF_EMPLOYEE.
METHODS:
ADD_EMPLOYEE
IMPORTING IM_NO TYPE I
IM_NAME TYPE STRING
IM_WAGE TYPE I.
ENDINTERFACE. "lif_employee
"class definition
*----------------------------------------------------------------------*
* CLASS lcl_company_employees DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_COMPANY_EMPLOYEES DEFINITION.
PUBLIC SECTION.
INTERFACES LIF_EMPLOYEE.
TYPES:BEGIN OF T_EMPLOYEE,
NO TYPE I,
NAME TYPE STRING,
WAGE TYPE I,
END OF T_EMPLOYEE.
METHODS: CONSTRUCTOR,
DISPLAY_EMPLOYEE_LIST,
DISPLAY_NO_OF_EMPLOYEES.
PRIVATE SECTION.
CLASS-DATA: I_EMPLOYEE_LIST TYPE TABLE OF T_EMPLOYEE,
NO_OF_EMPLOYEES TYPE I.
ENDCLASS. "lcl_company_employees DEFINITION
*class lcl_companyemployees implementation
CLASS LCL_COMPANY_EMPLOYEES IMPLEMENTATION.
METHOD CONSTRUCTOR.
NO_OF_EMPLOYEES = NO_OF_EMPLOYEES + 1.
ENDMETHOD. "constructor
METHOD LIF_EMPLOYEE~ADD_EMPLOYEE.
"add a new employee to the list of employees
DATA:L_EMPLOYEE TYPE T_EMPLOYEE.
L_EMPLOYEE-NO = IM_NO.
L_EMPLOYEE-NAME = IM_NAME.
L_EMPLOYEE-WAGE = IM_WAGE.
APPEND L_EMPLOYEE TO I_EMPLOYEE_LIST.
ENDMETHOD. "lif_employee~add_employee
METHOD DISPLAY_EMPLOYEE_LIST.
"display all employees and their wage
DATA:L_EMPLOYEE TYPE T_EMPLOYEE.
WRITE:/ 'List of Employees'.
LOOP AT I_EMPLOYEE_LIST INTO L_EMPLOYEE.
WRITE:/ L_EMPLOYEE-NO,L_EMPLOYEE-NAME,L_EMPLOYEE-WAGE.
ENDLOOP.
ENDMETHOD. "display_employee_list
METHOD DISPLAY_NO_OF_EMPLOYEES.
"display total number of employees
SKIP 3.
WRITE:/ 'Total number of employees:', NO_OF_EMPLOYEES.
ENDMETHOD. "display_no_of_employees
ENDCLASS. "lcl_company_employees IMPLEMENTATION
"subclass definition
*----------------------------------------------------------------------*
* CLASS lcl_bluecollar_employee DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_BLUECOLLAR_EMPLOYEE DEFINITION
INHERITING FROM LCL_COMPANY_EMPLOYEES.
PUBLIC SECTION.
METHODS:
CONSTRUCTOR
IMPORTING IM_NO TYPE I
IM_NAME TYPE STRING
IM_HOURS TYPE I
IM_HOURLY_PAYMENT TYPE I,
LIF_EMPLOYEE~ADD_EMPLOYEE REDEFINITION.
PRIVATE SECTION.
DATA:NO TYPE I,
NAME TYPE STRING,
HOURS TYPE I,
HOURLY_PAYMENT TYPE I.
ENDCLASS. "lcl_bluecollar_employee DEFINITION
"subclass implementation
*----------------------------------------------------------------------*
* CLASS lcl_bluecollar_employee IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_BLUECOLLAR_EMPLOYEE IMPLEMENTATION.
METHOD CONSTRUCTOR.
"the super class constructor method must be called from the subclass
* constructor method
CALL METHOD SUPER->CONSTRUCTOR.
NO = IM_NO.
NAME = IM_NAME.
HOURS = IM_HOURS.
HOURLY_PAYMENT = IM_HOURLY_PAYMENT.
ENDMETHOD. "constructor
METHOD LIF_EMPLOYEE~ADD_EMPLOYEE.
"calculate wage an call the superclass method add_employee to add
"the employee to the employee list
DATA: L_WAGE TYPE I.
L_WAGE = HOURS * HOURLY_PAYMENT.
CALL METHOD SUPER->LIF_EMPLOYEE~ADD_EMPLOYEE
EXPORTING
IM_NO = NO
IM_NAME = NAME
IM_WAGE = L_WAGE.
ENDMETHOD. "lif_employee~add_employee
ENDCLASS. "lcl_bluecollar_employee IMPLEMENTATION
"subclass white collar employee
CLASS lcl_whitecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODs:
constructor
IMPORTING
im_no TYPE i
im_name TYPE string
im_monthly_salary TYPE i
im_monthly_deducations TYPE i,
lif_employee~add_employee REDEFINITION.
PRIVATE SECTION.
DATA:
no TYPE i,
name TYPE string,
monthly_salary TYPE i,
monthly_deducations TYPE i.
ENDCLASS.
"class whitecollar employee implementation
CLASS lcl_whitecollar_employee IMPLEMENTATION.
METHOD constructor.
"the superclass constructor method must be called from the subclass
"constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
monthly_salary = im_monthly_salary.
monthly_deducations = im_monthly_deducations.
ENDMETHOD.
METHOD lif_employee~add_employee.
"calculate wage an call the superclass method add_employee to add
"the employee to the employee list
DATA: l_wage TYPE i.
l_wage = monthly_salary - monthly_deducations.
CALL METHOD super->lif_employee~add_employee
EXPORTING
im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
DATA:
" object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
"create bluecollar employee object1
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Chandrasekhar'
im_hours = 38
im_hourly_payment = 75.
"add bluecollar employee to employee_list
CALL METHOD o_bluecollar_employee1->lif_employee~add_employee
EXPORTING
im_no = 1
im_name = 'vikram c'
im_wage = 0.
"create whitecollar employee object
CREATE OBJECT o_whitecollar_employee1
EXPORTING
im_no = 2
im_name = 'raghava v'
im_monthly_salary = 10000
im_monthly_deducations = 2500.
"add whitecollar to the employee_list
CALL METHOD o_whitecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.
阅读(897) | 评论(0) | 转发(0) |