Never Lose Your command on ABAP Controlling keywords Again

Updated: May 31



Controlling keywords are used to control the flow of the data execution.

There are 7 types of controlling keywords—>

  1. IF——ENDIF.

  2. IF——ELSE——ENDIF.

  3. IF——ELSEIF——ENDIF.

  4. CASE——WHEN——ENDCASE.

  5. DO——ENDDO.

  6. WHILE——ENDWHILE.

  7. LOOP——ENDLOOP (to be used in internal table concept)

Note—As an ABAPER we always create custom programs, and as per coding standards name of the program should always start with either ‘y’ or ‘z’.

All programs starting with alphabets other than ‘y’ and ‘z’ are known as standard programs, which are created and developed by SAP labs.

Transaction code—>

Transaction in SAP is a 4 digit short cut key to access he requested transaction. Transaction code provides direct access to the desired transaction from anywhere within the SAP system.

Transaction code or T-code for ABAP editor screen is “se38”.

Some more transaction codes in ABAP—>

KNOWLEDGE CLOUD——>

When you are compiling the program try to follow the following steps—>

  1. Click on SAVE.

  2. Then Check (

  3. Then Active it.

  4. Click on Execute.


  1. IF——ENDIF—>

‘IF’ is a control statement used to specify one or more conditions. You may also nest the IF control structures in an ABAP program.

If the ‘IF’ CONDITION is true then only it will execute coding otherwise it will directly jump to ENDIF.

SYNTAX—>


IF (CONDITION).

CODING.

ENDIF.

Flow Diagram—>




CODING SCREEN—>




INPUT 1—>



OUTPUT 1—>



INPUT 2—>



OUTPUT 2—>



2. IF——ELSE——ENDIF.

In case of IF….ELSE statements, if the expression evaluates to true then the IF block of code will be executed. Otherwise, ELSE block of code will be executed.


SYNTAX—>

IF (CONDITION).

CODING.

ELSE.

CODING.

ENDIF.

Flow Diagram—->


CODING SCREEN—>


INPUT 1—>



OUTPUT 1—>


INPUT 2—>



OUTPUT 2—>


3. IF—ELSEIF—ENDIF—>

In case of IF….ELSEIF statements, the expression is checked at every condition. It will execute only when the condition is true.


SYNTAX—>


IF(CONDITION).

CODING.

ELSEIF(CONDITION).

CODING.

ELSEIF(CONDITION).

CODING.

ENDIF.

CODING SCRREN—>


INPUT 1—>



OUTPUT 1—>



INPUT 2—>



OUTPUT 2—>


4. CASE—WHEN—ENDCASE—>

The CASE control statement is used when you need to compare two or more fields.

SYNTAX—>

CASE <field>.

WHEN <abc>.

<statement block>.

WHEN <def>.

<statement block>.

WHEN <pqr>.

<statement block>.

......

......

......

WHEN <xyz>.

<statement block>.

WHEN OTHERS.

<statement block>.

ENDCASE.

The following rules apply to a CASE statement −

  • NO logical expressions can be used for <field> field.


  • The field strings uses in CASE statement are used as type C variables

  • The statement block following a WHEN clause is executed if the contents of the fields shown in the <field> is similar to one of the fields <abc>, <def>, <ghi> up to <xyz>.


  • After executing all the conditions specified in the WHEN statement, the program continues to process the remaining statements after the ENDCASE statement.

  • The WHEN OTHERS clause is executed in a program when the value of the <field> does not match with any value specified in the <abc> up to <xyz> fields of the WHEN clause.

  • If the WHEN OTHERS clause is omitted and the value of the <field> does not match with any value specified in the <abc> up to <xyz> fields of the WHEN clause, the program continues to process the remaining statements after the ENDCASE statement.


Flow Diagram—>