07-12-2006 6:49 PM
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!!!
07-12-2006 6:54 PM
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.
07-12-2006 6:57 PM
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>
07-12-2006 7:00 PM
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
07-12-2006 7:04 PM
Orlando Rivera:
Can you make a example?
Thanks!!
P.D. Gracias Nacho Libre jejeje