SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development PDF Download

ABAP provides a rich set of operators to manipulate variables. All ABAP operators are classified into four categories −

  • Arithmetic Operators
  • Comparison Operators
  • Bitwise Operators
  • Character String Operators

Arithmetic Operators

Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following list describes arithmetic operators. Assume integer variable A holds 20 and variable B holds 40.

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

Example

REPORT YS_SEP_08. 

DATA: A TYPE I VALUE 150, 

B TYPE I VALUE 50, 

Result TYPE I. 

Result =  A / B. 

WRITE / Result.

The above code produces the following output −

3

Comparison Operators

Let’s discuss the various types of comparison operators for different operands.

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

Note − If the data type or length of the variables does not match then automatic conversion is performed. Automatic type adjustment is performed for either one or both of the values while comparing two values of different data types. The conversion type is decided by the data type and the preference order of the data type.

Following is the order of preference −

  • If one field is of type I, then the other is converted to type I.
  • If one field is of type P, then the other is converted to type P.
  • If one field is of type D, then the other is converted to type D. But C and N types are not converted and they are compared directly. Similar is the case with type T.
  • If one field is of type N and the other is of type C or X, both the fields are converted to type P.
  • If one field is of type C and the other is of type X, the X type is converted to type C.

Example 1

REPORT YS_SEP_08. 

DATA: A TYPE I VALUE 115,

      B TYPE I VALUE 119.

      IF A LT B.

      WRITE: / 'A is less than B'.

      ENDIF

The above code produces the following output −

A is less than B 

Example 2

REPORT YS_SEP_08. 

DATA: A TYPE I.

      IF A IS INITIAL.

      WRITE: / 'A is assigned'.

      ENDIF.

The above code produces the following output −

A is assigned.

Bitwise Operators

ABAP also provides a series of bitwise logical operators that can be used to build Boolean algebraic expressions. The bitwise operators can be combined in complex expressions using parentheses and so on.

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

For example, following is the truth table that shows the values generated when applying the Boolean AND, OR, or XOR operators against the two bit values contained in field A and field B.

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

Character String Operators

Following is a list of character string operators −

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

Example

REPORT YS_SEP_08. 

DATA: P(10) TYPE C VALUE 'APPLE',

      Q(10) TYPE C VALUE 'CHAIR'.

      IF P CA Q.

    

      WRITE: / 'P contains at least one character of Q'.

      ENDIF.

The above code produces the following output −

P contains at least one character of Q.

The document SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development is a part of the Software Development Course Learn and Master SAP ABAP.
All you need of Software Development at this link: Software Development
73 videos|68 docs

Top Courses for Software Development

73 videos|68 docs
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Semester Notes

,

pdf

,

Viva Questions

,

Free

,

Summary

,

past year papers

,

practice quizzes

,

Important questions

,

study material

,

video lectures

,

shortcuts and tricks

,

Exam

,

Previous Year Questions with Solutions

,

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

,

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

,

Objective type Questions

,

ppt

,

MCQs

,

Extra Questions

,

SAP ABAP - Operators | Learn and Master SAP ABAP - Software Development

,

mock tests for examination

,

Sample Paper

;