SAP Operator: Arithmetic and Comparison Operation

SAP Operator: Arithmetic Operators

Following are the basic SAP Operator using which Arithmetic operations can be performed upon ABAP variables:

  1. Assign Values to variables

To assign value to a variable, we can use equal to “=” sign or Keyword MOVE.

DATA:   LV_NUMBER1 TYPE      n,

LV_NUMBER2   TYPE     n.

LV_NUMBER1 = 10.

MOVE LV_NUMBER1 TO LV_NUMBER2.

WRITE: / LV_NUMBER1, LV_NUMBER2.

OUTPUT:

  1. Apply Sum, Subtraction, Multiplication and division on two or more variables

DATA:           LV_NUMBER1 TYPE      n             VALUE  10,

LV_NUMBER2   TYPE     n             VALUE  20,

LV_ADD                TYPE     n,

LV_SUB                 TYPE     n,

LV_MUL               TYPE     n,

LV_DIV                 TYPE     n.

LV_ADD = LV_NUMBER1 + LV_NUMBER2.

(OR)

A = ADD LV_NUMBER2 TO LV_NUMBER1.

LV_SUB = LV_NUMBER1 – LV_NUMBER2.

(OR)

B = SUBTRACT LV_NUMBER2 FROM LV_NUMBER1

LV_MUL = LV_NUMBER1 * LV_NUMBER2.

(OR)

C = MULTIPLY LV_NUMBER1 BY LV_NUMBER2

LV_DIV                 = LV_NUMBER2 / LV_NUMBER1.

(OR)

D = DIVIDE LV_NUMBER2 BY LV_NUMBER1

WRITE: / LV_ADD, LV_SUB, LV_MUL, LV_DIV.

(OR)

WRITE: / A, B, C, D.

 

  1. Clear Variables

Keyword CLEAR is used to clear the values in variable to default values i.e. 0 for numeric and “ ” for character field.

WRITE: / “BEFORE CLEAR”.

WRITE: / A, B, C, D.

CLEAR: A, B, C, D.

WRITE: / “AFTER CLEAR”.

WRITE: / A, B, C, D.

 

 

ABAP MATHS FUNCTIONS

ABAP provides predefined built-in maths functions that you can use according to your requirement.

Following are some of the Maths Functions:

FUNCTIONSSUPPORTED NUMERIC DATA TYPESDESCRIPTION
ABSALLTO CALCULATE ABSOLUTE VALUE
SIGNALLTO DETERMINE SIGN, RETURNS 1 FOR (+) 0 FOR (-)
CEILALLIt gives next highest integer i.e.  ceil (2.1) = 3
FLOORALLIt gives next lowest integer  i.e. floor (2.1) = 2
TRUNCALLIt gives truncated part of the input
FRACALLIt gives fractional part of input i.e. FRAC(1.2) = .2
COS,SIN,TANFIt will implement the given trigonometry function
EXPFIt will implement Exponential function
LOGFIt will implement Natural Log on that number
SQRTFIt will return square root of the input
MODNIt will return remainder mod(12,5) = 2

 

SAP Operator: Comparison Operators

Following are the SAP Operator provided for ABAP Comparison Operation:

OperatorAlternate FormMeaning
=EQEquality Test returns 1 if equal
<>NEInequality Test return 1 if True
>GTGreater Than Test
<LTLess Than Test
>=GEGreater than or Equal
<=LELess than or Equal
BETWEENInterval Test returns value between two value
IS INITIALInitial Test returns True if variable have no value
IS NOT INITIALNot Initial Test returns True if variable is not empty

 

Apart from above operators ABAP also provide Bitwise Operators and Character String Operators

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.