Corporate Training
Request Demo
Click me
Menu
Let's Talk
Request Demo

Tutorials

ABAP Operators and Expressions

ABAP Operators and Expressions:

In SAP's ABAP (Advanced Business Application Programming), operators and expressions are fundamental components for performing various operations and calculations within programs. Here's an overview of ABAP operators and expressions:

1. Arithmetic Operators:

  • + (Addition): Adds two operands.
  • - (Subtraction): Subtracts the second operand from the first.
  • * (Multiplication): Multiplies two operands.
  • / (Division): Divides the first operand by the second.
  • ** (Exponentiation): Raises the first operand to the power of the second.

Example:

       DATA lv_result TYPE i.
lv_result = 5 + 3. "lv_result will be 8

 

2. Comparison Operators:

  • EQ (Equal to)
  • NE (Not equal to)
  • GT (Greater than)
  • LT (Less than)
  • GE (Greater than or equal to)
  • LE (Less than or equal to)

Example:

DATA lv_result TYPE abap_bool.
lv_result = 5 GT 3. "lv_result will be ABAP_TRUE

 

3. Logical Operators:

  • AND (Logical AND)
  • OR (Logical OR)
  • NOT (Logical NOT)

Example:

DATA lv_result TYPE abap_bool.
lv_result = abap_true AND abap_false. "lv_result will be ABAP_FALSE
 

 

4. String Concatenation:

  • & (String concatenation operator): Combines two strings.

Example:

     DATA lv_string TYPE string.
lv_string = 'Hello' & ' ' & 'World'. "lv_string will be 'Hello World'

 

5. Assignment Operator:

  • = (Assignment operator): Assigns a value to a variable.

Example:

DATA lv_value TYPE i.
lv_value = 42.
     

 

6. Conditional Operators:

  • COND (Conditional operator): A shorthand for writing conditional expressions.

Example:

DATA lv_result TYPE i.
lv_result = COND #( WHEN 1 EQ 1 THEN 42 ELSE 0 ). "lv_result will be 42
     

 

7. Expression Evaluation:

  • ABAP evaluates expressions based on operator precedence, similar to other programming languages. Parentheses can be used to specify the order of evaluation.

Example:

DATA lv_result TYPE i.
lv_result = (5 + 3) * 2. "lv_result will be 16
     

 

8. Built-in Functions:

  • ABAP provides numerous built-in functions for performing operations on data, such as mathematical functions (ABS, CEIL, FLOOR), string functions (CONCATENATE, CONV, SUBSTRING), date and time functions, and more.

Example:

DATA lv_absolute_value TYPE i.
lv_absolute_value = ABS(-5). "lv_absolute_value will be 5