简体   繁体   English

我如何从abap的内部表中计算所有员工的平均工资?

[英]How do i calculate the average salary of all employees from an internal table in abap?

I created a class that has the attributes (name ,address ,age ,salary).我创建了一个具有属性(姓名、地址、年龄、工资)的类。 I created employee objects in an internal table defined as follows我在定义如下的内部表中创建了员工对象

 Data itab_employees  TYPE TABLE OF REF TO lcl_employee.

Is it possible to create a method that calculates the average of the salaries of the employee objects that are inside internal table (itab_employees)?是否可以创建一个方法来计算内部表 (itab_employees) 中员工对象的平均工资?

This what i tried so far这是我到目前为止所尝试的

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.

But i am not sure about the line getsalary = r_employee->get_salary( ).但我不确定getsalary = r_employee->get_salary( ).

Thanks for your comments @gkubed.感谢您的评论@gkubed。 I figured something out which worked out for me我想出了一些对我有用的东西

  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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 f4 帮助字段中的所有可能值获取到 ABAP 中的内部表中? - How to get all possible values from the f4 help fields into an internal table in ABAP? ABAP - 按成本中心对员工进行分组并计算总和 - ABAP - Group employees by cost center and calculate sum 如何将内部表分配到结构中,然后分配到 ABAP 中的字段 - How to assign internal table into a structure and then to a field in ABAP 如何在abap中获取内部表的行数? - How to get rows count of internal table in abap? 如何从第二张表的薪水列中查找第一张表中第二高薪水和第三低薪水的员工姓名,而无需在 ABAP 中排序 - how to find the name of employee from 1st table with 2nd highest and 3rd lowest salary from salary column in 2nd table without sort in ABAP 如何在ABAP中检索层次结构的所有子节点? - How do I retrieve all child nodes of a hierarchical structure in ABAP? ABAP:从现有数据库表创建内部表的语法 - ABAP: Syntax for creating internal table from existing database table 如何从abap中的日期获取天数? - How do I get day number from a date in abap? abap:从现有的内部表创建动态内部表 - abap: create dynamic internal table from existing one ABAP-在“应用程序日志”详细信息上,单击“显示内部表中的记录” - ABAP - On Application log details click show records from internal table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM