The Wayback Machine - https://web.archive.org/web/20240727030400/https://www.geeksforgeeks.org/sap-abap-decision-control-statements/
Open In App

SAP ABAP | Decision Control Statements

Last Updated : 01 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

SAP ABAP, or Advanced Business Application Programming, provides a robust set of tools for developing business applications within the SAP environment. Decision control statements are a crucial aspect of programming logic, allowing developers to make choices and guide the flow of a program based on certain conditions.

Decision Control statement have one or more block of statement that are to be evaluated by the program and is executed only when certain conditions are met.

SAP-ABAP--Decision-Control-Statements

Flow of Decision Control Statements in SAP ABAP

Before diving into the specifics of decision control statements, let’s visualize their flow. Decision control statements create branches in the code, directing the program’s execution path based on the evaluation of conditions. Here’s a simplified flow diagram:

Start
|
|-- [Condition A]
| |
| |-- Code Block A1
| |
| |-- Code Block A2
|
|-- [Condition B]
| |
| |-- Code Block B1
| |
| |-- Code Block B2
|
|-- [Default]
|
|-- Default Code Block

This diagram represents the typical structure of decision control statements, illustrating how the program follows different paths based on evaluated conditions.

Types of Decision Control Statements in SAP ABAP

There are several types of decision control statements in SAP ABAP, each serving specific programming needs:

1. IF Statement

If the condition is true, evaluates it and then executes a piece of code.

Syntax:

IF condition.
" Code to execute if the condition is true.
ENDIF.

Example:

DATA(age) = 25.

IF age < 30.
WRITE: 'You are young.'.
ENDIF.

2. IF-ELSE Statement:

Adds an alternative block of code to execute if the condition in the IF statement is false.

Example:

IF condition.
" Code to execute if the condition is true.
ELSE.
" If the condition is not true i.e false, code will executed.
ENDIF.

Example:

DATA(grade) = 'B'.

IF grade = 'A'.
WRITE: 'Excellent!'.
ELSE.
WRITE: 'Good effort!'.
ENDIF.

3. IF-ELSEIF-ELSE Statement

Evaluates multiple conditions in sequence and executes the block of code corresponding to the first true condition.

Example:

IF condition1.
" Code will execute if condition1 is true.
ELSEIF condition2.
" Code will execute if condition2 is true.
ELSE.
" If any of the criteria is not met, code will run.
ENDIF.

Example:

DATA(marks) = 75.

IF marks >= 90.
WRITE: 'A Grade.'.
ELSEIF marks >= 80.
WRITE: 'B Grade.'.
ELSE.
WRITE: 'C Grade.'.
ENDIF.

4. Nested IF Statements

Allows nesting of IF statements inside one another for more complex condition evaluations.

Example:

IF condition1.
IF condition2.
" If both the condition are met, code must run.
ENDIF.
ENDIF.

Example:

DATA(age) = 25.
DATA(income) = 50000.

IF age < 30.
IF income > 40000.
WRITE: 'Young and earning well.'.
ENDIF.
ENDIF.

5. CASE Statement

Provides a concise way to evaluate a variable against multiple values.

Example:

CASE variable.
WHEN value1.
" If value1 is equal to variable, code will run.
WHEN value2.
" If value2 is equal to variable, code will run.
WHEN OTHERS.
" Code will execute if none of the specified values match.
ENDCASE.

Example:

DATA(day) = 'Monday'.

CASE day.
WHEN 'Monday'.
WRITE: 'The start of the week.'.
WHEN 'Friday'.
WRITE: 'TGIF!'.
WHEN OTHERS.
WRITE: 'Another day.'.
ENDCASE.

Conclusion

In conclusion, effective programming requires a solid understanding of SAP ABAP’s Decision Control Statements. With the help of these statements, developers may design dynamic, adaptable, and efficient business solutions in the SAP environment by utilising CASE structures or IF-ELSE conditions.


Previous Article
Next Article

Similar Reads

SAP ABAP: A complete Guide to Events in ABAP Report
SAP created the high-level programming language known as SAP ABAP (Advanced Business Application Programming) to be used for creating business applications. Reports are an essential tool for extracting and presenting data in SAP development. To manage the execution flow and improve the functionality of their systems, developers must comprehend the
5 min read
SAP S/4 HANA Vs SAP HANA | Difference between SAP S/4 HANA , SAP HANA
SAP S/4HANA is the most recent ERP suite, with advanced architecture allowing for real-time processing. SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP S/4 HANA?SAP, which stands f
3 min read
SAP HANA Vs SAP ECC | Difference between SAP HANA and SAP ECC
SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP HANA?SAP HANA stands for High-performance analytic appliance, which is faster than any other database management system that we use
2 min read
SAP MM Vs SAP SRM | Difference Between SAP MM and SAP SRM
SAP MM helps companies optimize their material and logistics management procedures, guaranteeing effective and economical handling of items. SAP SRM stands for Supplier Relationship Management and is an efficient tool that helps companies optimize procurement operations and helps to improve relationships with suppliers and other business vendors. W
2 min read
SAP EWM Vs SAP WM | Difference Between SAP EWM and SAP WM
SAP EWM is a version created by enhancing the SAP Warehouse Management (SAP WM) solution, one of the world’s most popular warehouse management applications, with new features. What is SAP EWM?The SAP EWM solution was created to organize and manage goods storage in warehouses, distribution centers, and logistical centers. Its primary goal is to impr
3 min read
SAP ABAP | Basic Syntax &amp; Statements
The German software company SAP created the high-level programming language, ABAP (Advanced Business Application Programming) primarily, this language serves as a tool for developing applications within the SAP R/3 system. Designed with simplicity and ease of learning in mind, ABAP syntax allows efficient processing of large volumes of data. Simila
7 min read
Diffrence Between SAP and SAP ABAP(Advanced Business Application Programming)
In this article, we are going to learn the difference between an SAP and SAP ABAP. SAP ABAP is created by SAP which is a domain-specific language, it is 4th generation programming language. It is also called ABAP/4(Fourth Generation Language” or 4GL). What is SAP?SAP stands for Systems, Applications, and Products in Data Processing. It’s a German m
2 min read
Difference Between SAP ERP and SAP ABAP
In this article, we are going to learn the difference between an SAP ERP and SAP ABAP. SAP ABAP is created by SAP which is a domain-specific language, it is 4th generation programming language. It is also called ABAP/4(Fourth Generation Language” or 4GL). SAP Enterprise Resource Planning (ERP) systems are essential for simplifying and maximizing a
2 min read
SAP ABAP | Loop Control
Introduction to Loop Control in SAP ABAPIn SAP ABAP programming, loop control is an esse­ntial concept that allows you to execute­ a block of code multiple times. This is e­specially useful when proce­ssing data in an efficient manner. Loops help automate repetitive­ tasks and handle large datasets effectively. In ABAP, there are various types of l
4 min read
Difference between SAP S/4 HANA , SAP HANA and SAP ECC
SAP S/4HANA is the most recent ERP suite, with advanced architecture allowing for real-time processing. SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP S/4 HANA?SAP, which stands f
3 min read
Article Tags :
three90RightbarBannerImg