2007 Mar 14 4:25 AM
I have this column named "Price" and I need to add up all the entries to that column. I know I can run through each row and calculate the sum but is there any function or method already available in ABAP development that I can use? Can you pls show me other math operations available already? Any list? im a newbie. <b>big thanks.</b>
2007 Mar 14 4:34 AM
you can use control break statements for the same
loop at itab.
AT LAST.
SUM.
write : itab-price. <-------writes the sum of price field
ENdAT.
endloop.
In Internal Tables we have Control Structures for Control Level Processing.
The Control Structures we have are
1. ... FIRST
2. ... |{END OF} comp
3. ... LAST
The Math Operation Performed on the internal tables is <b>SUM.</b>
The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables.
The statement SUM calculates the component total with the numeric data type ( i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST , and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.
example :
Control level processing for creating a list. At the end of line groups, the total of reserved places is calculated and issued.
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
sflight_wa LIKE LINE OF sflight_tab.
SELECT *
FROM sflight
INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
AT END OF carrid.
SUM.
ULINE.
WRITE: / 'Carrier Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
NEW-PAGE.
ENDAT.
AT LAST.
SUM.
WRITE: / 'Overall Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
ENDAT.
ENDLOOP.
If Helpful ,Reward Points
Regards,
Satish
2007 Mar 14 4:34 AM
you can use control break statements for the same
loop at itab.
AT LAST.
SUM.
write : itab-price. <-------writes the sum of price field
ENdAT.
endloop.
2007 Mar 15 3:51 PM
2007 Mar 14 4:40 AM
Hi,
Go through the attached doc for all math functions in SAP.
Mathematical Functions
The argument arg of a mathematical function must represent a numeric value. The data type of the return value is determined either by the argument of the function (overloaded functions) or by the function itself (floating point functions).
Outside of an arithmetic expression, the argument of a mathematical function must be a single, numeric data object. Within an arithmetic expression - that is, in the statement COMPUTE - the argument of a mathematical function can also be an arithmetic expression. In particular, a mathematical function in an arithmetic expression can have a different built-in function or a functional method as argument.
Overloaded Functions
The following table shows the overloaded functions where the data type of the argument determines the data type of the return value.
Function func Return value
abs Absolute value of the argument arg
sign Plus/minus sign of the argument arg: -1, if the value of arg is negative; 0 if the value of arg is 0; 1 if the value of arg is positive.
ceil Smallest integer number that is not smaller than the value of the argument arg.
floor Largest integer number that is not larger than the value of the argument arg.
trunc Value of the integer part of the argument arg
frac Value of the decimal places of the argument arg
If the argument of an overloaded function does not have any numeric data type i, p, or f, its data type determines the type of return value as follows:
d and t give i
c, n and string give p
x and xstring give i
Before the function is calculated, the argument is converted into the respective type:
Floating Point Functions
The following table shows the floating point functions where the return value is always of the type f. Floating point functions expect an argument of the type f. Data objects of other data types are converted, before calculation of the function, into the data type f.
Funktion func Meaning Definition Area
acos Arcuscosinus [-1,1]
asin Arcussinus [-1,1]
atan Arcustangens
cos Cosinus
sin Sinus
tan Tangens
cosh Hyperbelcosinus
sinh Hyperbelsinus
tanh Hyperbeltangens
exp Exponential function for basis e [-709, 710]
log Natural logarithm > 0
log10 Logarithm for basis 10 > 0
sqrt Square root >= 0
For the functions for which a definition area is specified, the value of arg must be in the specified limits. For the exponential function exp an error-free execution is guaranteed for the arguments within the definition ares, because the results then lie within the value range for floating point numbers according to IEEE-754. For arguments smaller than -709, the result is always 0, depending on the platform, or as of a certain value a treatable exception of class CX_SY_ARITHMETIC_OVERFLOW is triggered. For arguments greater than +718, it also leads to this exception. The trigonometry functions sin, cos, and tan are defined for arbitrary arguments, but the results are inexact whenever the amount of the argument is greater than approximately 100.000.000.
Note
The function atan may be undefined for odd-numbered multiples of pi/2, but the definition area for atan is not limited, because an argument of the functions can never contain exactly the value of pi/2.
Exceptions that can be handled
The exceptions that can be handled and can occur during calculation of a mathematical function are subclasses of the classes CX_SY_ARITHMETIC_ERROR und CX_SY_CONVERSION_ERROR.
reward if useful
Regards,
Anji
2007 Mar 14 4:47 AM
Hi...
There is a statement <b>SUM</b>.
Go through the following link:
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/frameset.htm
see the following Ex:
REPORT ZTEST.
DATA:
BEGIN OF ITAB OCCURS 0,
NAME(10) TYPE C,
SALARY TYPE I,
END OF ITAB.
ITAB-NAME = 'Suresh'.
ITAB-SALARY = 1000.
APPEND ITAB.
ITAB-NAME = 'xyz'.
ITAB-SALARY = 2000.
APPEND ITAB.
ITAB-NAME = 'dddd'.
ITAB-SALARY = 3000.
APPEND ITAB.
ITAB-NAME = 'abc'.
ITAB-SALARY = 5000.
APPEND ITAB.
ITAB-NAME = 'zzzz'.
ITAB-SALARY = 10000.
APPEND ITAB.
LOOP AT ITAB.
AT FIRST.
<b> SUM.</b>
WRITE: ' Total salary is :', ITAB-SALARY.
ENDAT.
ENDLOOP.
Reward points if useful......
Suresh......
2007 Mar 14 4:48 AM
I had a similar requirement and i could't find any existing function which could do this.
2007 Mar 14 4:54 AM
In Internal Tables we have Control Structures for Control Level Processing.
The Control Structures we have are
1. ... FIRST
2. ... |{END OF} comp
3. ... LAST
The Math Operation Performed on the internal tables is <b>SUM.</b>
The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables.
The statement SUM calculates the component total with the numeric data type ( i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST , and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.
example :
Control level processing for creating a list. At the end of line groups, the total of reserved places is calculated and issued.
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
sflight_wa LIKE LINE OF sflight_tab.
SELECT *
FROM sflight
INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
AT END OF carrid.
SUM.
ULINE.
WRITE: / 'Carrier Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
NEW-PAGE.
ENDAT.
AT LAST.
SUM.
WRITE: / 'Overall Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
ENDAT.
ENDLOOP.
If Helpful ,Reward Points
Regards,
Satish
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |