Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Static Method to calculate ' Average '.

Former Member
0 Likes
939

Hi

I am wondering which one is preferred?  Static or Instance methods for calculating 'average' (e.g average sales).

My class lcl_company is having attributes name and sales. which represents name = name of the company, sales = total sales of one company under department: automobiles.

eg output:

Department: automobiles.

name = abc company

sales = 1000

name = xyz company

sales = 2000

total companies added: 2.

now i want to calculate the average sales of the companies under department automobiles.

I prefer using a static method (is it good choice), if not, why instance method. while using the static method, I noticed that i need to stick just with the defined attributes.

Please advice on calculating average.

Thank you.

4 REPLIES 4
Read only

Former Member
0 Likes
717

Hi Pawan,

You`d better declare a another object, say 'Accountant', in this object, have a method used to calculating average, which importing parameters is a itab. In this itab, havd appended this two companies. I think no mater this calculating average method is static or instance, it`s ok, that`s depened on you how to abstract 'Accountant'.

BTW, static method has a small memory footprint than instance .

regards,

Archer

Read only

0 Likes
717

Thank you Archer.

Read only

0 Likes
717

Hi archer

I did the same as you told.

i brought the two company into an it_tab which i defined as attribute.

private section.

data it_tab type table of ref to department.

my internal table is showing the records of both the companies but m face a new problem how to write this records to output.

Read only

0 Likes
717

Hi Pawan,

There are so many ways,:

One, as you said, you defined this itab as a attribute of this Object, then you need define another attribute 'AverNum' as public. Of cause, this Object have a method using to calculate the average number, passing the value to public attribute 'AverNum', then you can access this public attribute from outside.

Another way:  Define this itab as a importing parameter of your average method, same time, this average method have a return parameter. Then you can call this static object method or instance object method from outside, and return your output by return parameter.

regards,

Archer