Application Development 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: 

Abap question

Former Member
0 Kudos

Hi people,

OK, I need to make some computations by group.

For example: Group 1, 2, 3 and 4 and divide the sum of the group by the totals of each column.

eg. column1 column2 column3 column4

total: 112,000 500.00 200.00 315.00

first_group_a = total_group1 / column1.

first_group_b = total_group1 / column2.

first_group_c = total_group1 / column3.

first_group_d = total_group1 / column4.

second_group_a = total_group2 / column1.

second_group_b = total_group2 / column2.

second_group_c = total_group2 / column3.

second_group_d = total_group2 / column4.

third_group_a = total_group3 / column1.

third_group_b = total_group3 / column2.

third_group_c = total_group3 / column3.

third_group_d = total_group3 / column4.

four_group_a = total_group4 / column1.

four_group_b = total_group4 / column2.

four_group_c = total_group4 / column3.

four_group_d = total_group4 / column4.

Exist other way to do that because if the total of the column is equal to '0' the system give me a error. So I don't whant to make a if for each variable to check is equals to '0' or not.

Thanks!!!

4 REPLIES 4

LucianoBentiveg
Active Contributor
0 Kudos

Just:

If total_group1 ne 0.

first_group_a = total_group1 / column1.

first_group_b = total_group1 / column2.

first_group_c = total_group1 / column3.

first_group_d = total_group1 / column4.

endif.

If total_group2 ne 0.

second_group_a = total_group2 / column1.

second_group_b = total_group2 / column2.

second_group_c = total_group2 / column3.

second_group_d = total_group2 / column4.

endif.

If total_group3 ne 0.

third_group_a = total_group3 / column1.

third_group_b = total_group3 / column2.

third_group_c = total_group3 / column3.

third_group_d = total_group3 / column4.

endif.

If total_group4 ne 0.

four_group_a = total_group4 / column1.

four_group_b = total_group4 / column2.

four_group_c = total_group4 / column3.

four_group_d = total_group4 / column4.

endif.

Former Member
0 Kudos

You can make a structure the same as the groups and move the data there and make validation only once for the structure fields.

Regards,

Orlando

<i>PD: Que clase e tipo...</i>

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please check this sample program. You can use a MACRO to keep the code neater.




report zrich_0001.

data: first_group_a type i.
data: total_group1 type i value 10.
data: column1 type i value 2.


define macro_do_division.

  if &2 > 0.
    &3 = ( &1 /  &2 ).
  else.
    &3 = 0.
  endif.

end-of-definition.


macro_do_division total_group1 column1 first_group_a.
*macro_do_division total_group1 column2 first_group_b.
*macro_do_division total_group1 column3 first_group_c.


write:/ first_group_a.

Regards,

Rich Heilman

Former Member
0 Kudos

Orlando Rivera:

Can you make a example?

Thanks!!

P.D. Gracias Nacho Libre jejeje