SAP ABAP Tutorial for Beginner – Previously we have learned how to do calculation in ABAP using Arithmetic  and Math Functions, Now we will learn ABAP Flow Control, this article cover how to add logic to our ABAP Programming. As another programming, we also know logic operation such as  : IF .. ELSE , WHILE, etc.

## 1.IF Statements

An IF statement evaluates whether a certain condition is true or false. If that condition is true, the code within the statement will execute; otherwise, it will continue.

Following table contain lists of condition operator in ABAP .

OpoeratorsDescription
!ERROR! undefined variable 'oryoucanuseeq'Equal: true if both values are equal to each other
< > or NENot equal: true if both values do not equal each other
< or LTLess than: true if the number on the left is less than
the number on the right
> or GTGreater than: true if the number on the left is greater
than the number on the right
<= or LELess equal: true if the number on the left is less than
or equal to the number on the right
>= or GEGreater equal: true if the number on the left is greater
than or equal to the number on right
BETWEEN n and n1Between: true if the number on the left is between n
and n1

For Example :

As long as the value of lv_test is 1, you’ll see “Your Value is TRUE” printed on the screen.

You also can combine multiple operators using the AND and OR key- AND/OR IF words. For AND, both operators must return true before the code statements within the IF statement will run.

For example we will use IF .. AND :

“Your Values is TRUE” will not be written in screen because lv_test and lv_test2 not equal 2.

### IF Parenthesis for complex IF Statements

Just as with the arithmetic calculations, we can use parentheses to create more complex IF statements. Parentheses group IF statement tests together; those IF statements can be combined with an AND or OR, as in the following example.

### IF .. ELSE Statements

When the initial condition is evaluated as false, you can add the ELSE keyword, which will run the code within the ELSE and ENDIF keywords when the test for IF is false.

For Example : ‘ELSE’ would be written to the screen, because the value of d_test is not between 5 and 10, causing the code under the ELSE to be executed.

### IF .. ELSEIF Statements

You may want to evaluate multiple conditions before utilizing the ELSE statement, which is a case in which the ELSE IF keyword can be useful. ELSE IF will only evaluate its condition if the IF /ELSE IF before it was evaluated as false.

For example : ELSE IF lv_test = 1 was true, it wasn’t evaluated because the test before it was found to
be true, so ‘ELSEIF’ was written to the screen.

## 2.CASE Statements

A CASE statement works like an IF statement, except that the CASE CASE statement will always evaluate only one variable and only uses the equal to condition. The CASE statement uses the keyword WHEN to evaluate
the variable against a value and WHEN OTHERS to handle any value that was not caught by the existing tests. The example shown below will write ‘1’ to the screen and not execute any of the other WRITE commands.

## 3.DO Loops

Using the keyword DO, you can execute a block of code any number of times. Define the number of times by adding a number and the keyword TlMES. The block of code that will run is between DO and ENDDO. In the following example, the code within the loop will be executed 5 times and the number 5 will be written to the screen.

## 4.WHILE Loops

A WHILE loop works like a DO loop, but instead of indicating a number of times that the loop content is to be run, it indicates a condition that will cause the loop to stop. Any operation condition that is valid in an IF statement will be valid for the WHILE loop.

In the example below, the code within the loop will be executed until the value of lv_test is no longer less than 5. As a result, the number 5 will be written to the screen since 5 is not less than 5.

Next lesson we will learn how to create Classic selection screen programming as interface with user.