Monday, April 9, 2012

Mathematical operations in Abap



There seems to be less information on how to do the different arithmetic operations in abap.Abap supports the basic arithmetic operations namely addition, subtraction, division and multiplication. The basic operations can be done using the keywords ADD, SUBTRACT,DIVIDE and MULTIPLY.
The operands to be used for the operations should always be numeric fields. Even if the fields differs in data type, SAP ensures the conversion by doing converting the operands and result into highest data type in the given statement.
Also please note in division operations, divisor is not allowed to be zero if dividend is not zero.In case of integer division, MOD provides the remainder.

Operation

Mathematical expression
Abap statement
Addition
 a = b + c.
ADD b TO c.
Subtraction
 a = b – c.
SUBTRACT c FROM b.
Multiplication
 a = b * c.
MULTIPLY b BY c.
Division
 a = b / c.
DIVIDE b BY c.

A demo program is provided by SAP which is DEMO_DATA_CALCULATE for showing the various arithmetic operations possible in SAP.
Please note the arithmetic operations involving move corresponding  and sequences in fields are obsolete from ECC version onwards.

2 comments:

  1. Thank You For Sharing Your Knowledge .good information keep it up.
    SAP ABAP


    ReplyDelete