我创建了一个具有属性(名称,地址,年龄,工资)的类。我在内部表中创建了员工对象,定义如下
Data itab_employees TYPE TABLE OF REF TO lcl_employee.
是否可以创建一个方法来计算内部表(itab_employees)内员工对象的工资平均值?
这是我到目前为止所尝试的
METHOD get_avg_salary.
DATA: r_employee TYPE REF TO lcl_employee,
getsalary TYPE i,
average TYPE i,
sum_salary TYPE i,
no_employee TYPE i.
getsalary = r_employee->get_salary( ).
no_employee = lcl_employee=>get_n_o_employee( ).
LOOP AT it_employees INTO r_employee.
AT LAST.
SUM .
sum_salary = getsalary.
average = sum_salary / no_employee.
ENDAT.
ENDLOOP.
re_avg_salary = average.
ENDMETHOD.
但我不确定这条线
getsalary = r_employee->get_salary( ).
答案 0 :(得分:0)
感谢您的评论@gkubed。我想出了一些适合我的东西
METHOD get_avg_salary.
DATA: r_employee TYPE REF TO lcl_employee,
average TYPE i,
sum_salary TYPE i.
LOOP AT it_employees INTO r_employee.
sum_salary = sum_salary + r_employee->get_salary( ).
ENDLOOP.
average = sum_salary / sy-tfill.
re_avg_salary = average.
ENDMETHOD.