‎2006 Aug 28 7:28 PM
HI EXPERTS,
I HAVE ONE INTERNAL TABLE HAVING ONE FIELD FILLED WITH VALUES FROM ONE TABLE.
SUPPOSE THE FIRST FIELD CONTAINS VALUES 1, -2, 3 , 1, 3, -4.
BASED ON THE ABOVE VALUES I NEED TO CALCULATE ONE VALUE THAT IS G_SUM1 = SUM OF ALL FIELD VALUES WHICH ARE GREATER THAN ZERO.
G_SUM2 = SUM OF ALL FIELD VALUES WHICH R LESS THAN ZERO.
THIS TWO SUMS SHOULD BE DISPLAYED AS THE SUMMARY OF THE REPORT.
COULD SOME PLZ SUGGEST ME HOW TO DO THIS CALCULATION.
REGARDS,
SIRI.
‎2006 Aug 28 7:31 PM
you could try the below logic.....
LOOP AT ITAB.
IF ITAB-VAL1 GT 0.
G_SUM1 = G_SUM1 + ITAB-VAL1.
ELSEIF ITAB-VAL1 LT 0.
G_SUM2 = G_SUM2 + ITAB-VAL1.
ENDIF.
ENDLOOP.
END-OF-PAGE.
WRITE:/ G_SUM1,
G_SUM2.
Cheers,
Abdul Hakim
‎2006 Aug 28 7:36 PM
Hi,
Check this code :
x_sum1 and x_sum2 are the variables after data process.
loop at i_tab.
if i_tab-fld1 > 0.
x_sum1 = x_sum1 + i_tab-fld1.
elseif i_tab-fld1 < 0.
x_sum2 = x_sum2 + i_tab-fld1.
endloop.
x_sum1 will contain sum of all positive values.
x_sum2 will contain sum of all negetive values.
regards
Appana
‎2006 Aug 28 7:39 PM
Loop at itab.
if itab-qty >= 0.
g_sum1 = itab-qty + g_sum1.
else.
g_sum2 = itab-qty + g_sum2.
endif.
endloop.
write : / g_sum1, g_sum2.
‎2006 Aug 28 8:11 PM
Hello Sireesha
I prefer to use the COLLECT statement to calculate sums.
In your case, you would need to define to additional itabs:
DATA:
gt_itab_positive TYPE ...,
gt_itab_negative TYPE ... .
LOOP AT gt_itab INTO ls_entry.
IF ( ls_entry-value > 0 ).
COLLECT ls_entry INTO gt_itab_positive.
ELSE.
COLLECT ls_entry INTO gt_itab_negative.
ENDIF.
ENDLOOP.Regards
Uwe
‎2006 Aug 28 10:35 PM
Hi sireesha,
you can declare ur internal table as sorted table with non unique key specfying ur fields as keys leaving the fields u want to sum(these fields should be specifically numeric).
And then when u want to append ur data use collect statement on the internal table.
Regards,
DS