How do i calculate the average salary of all employees from an internal table in abap?
<p>I created a class that has the attributes (name ,address ,age ,salary). I created employee objects in an internal table defined as follows</p>

<pre><code> Data itab_employees  TYPE TABLE OF REF TO lcl_employee.
</code></pre>

<p>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)?</p>

<p>This what i tried so far </p>

<pre><code>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-&gt;get_salary( ).
no_employee = lcl_employee=&gt;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.
</code></pre>

<p>But i am not sure about the line
<code>getsalary = r_employee-&gt;get_salary( ).</code>  </p>