SAP ABAP | While Loop Last Updated : 17 Oct, 2023 Comments Improve Suggest changes Like Article Like Report A fundamental control structure in SAP ABAP is the while loop. The while loop in SAP ABAP can be used to iterate a part of code while the given condition remains true. This construct the while loop facilitates iterative running a block of code continues to execute until the specified condition within that same loop becomes false. Programmers, through the incorporation of while loops, can automate processes; manipulate data, and control program flow based on dynamic conditions. Table of Content Syntax for While Loop in SAP ABAP:Flow Diagram for While loop in SAP ABAP:Examples of While Loop in SAP ABAP:Syntax for While Loop in SAP ABAP:WHILE condition " Statements to be executed ENDWHILE. Flow Diagram for While loop in SAP ABAP: Flow Diagram of SAP ABAP | While Loop Examples of While Loop in SAP ABAP:Example 1: Simple while loop to print numbers from 1 to user defined limitDATA: counter TYPE i VALUE 1.WRITE 'Enter the limit:'.READ VALUE counter.WHILE counter <= limit. WRITE: / counter. counter = counter + 1.ENDWHILE.Input: Enter the limit: 7 Output: 1234567 Explanation: First, the code prompts the user for a limit input. Subsequently, it enters a while loop; in each iteration of this loop until reaching the limit defined by the user, it prints out and updates (increments) its counter variable: initially set to 1. Example 2: Find factorial of a user-provided number:DATA: factorial TYPE i VALUE 1, i TYPE i VALUE 1.WRITE 'Enter the number:'.READ VALUE i.WHILE i <= number. factorial = factorial * i. i = i + 1.ENDWHILE.WRITE: / 'Factorial of', number, 'is', factorial.Input: Enter the number: 5 Output: Factorial of 5 is 120 Explanation: The user is prompted by this code to input a number for factorial calculation. A while loop within it calculates the entered number's factorial. The factorial variable initializes at 1, and with each iteration of the loop from one to the user-provided value, every value multiplies into it. Example 3: While loop to concatenate a user-provided string a certain number of times:DATA: input_string TYPE string, repetitions TYPE i, counter TYPE i VALUE 1,output_string TYPE string VALUE space.WRITE 'Enter a string:'.READ VALUE input_string.WRITE 'Enter the number of repetitions:'.READ VALUE repetitions.WHILE counter <= repetitions. CONCATENATE output_string input_string INTO output_string. counter = counter + 1.ENDWHILE.WRITE: / 'Concatenated string:', output_string.Input: Enter a string: ABAPEnter the number of repetitions: 3 Output: Concatenated string: ABAPABAPABAP Explanation: The user is prompted by this code to input a string and specify the number of times it should be repeated; subsequently, a while loop concatenates the input string as directed. Each iteration involves concatenating the initially empty output_string with the input_string until or unless the counter aligns with specified repetitions. For more reference Please visit: SAP ABAP Loop Control Comment More infoAdvertise with us Next Article SAP ABAP | Do Loop R rahul769311 Follow Improve Article Tags : Software Engineering Geeks Premier League 2023 SAP-ABAP SAP R/3 Similar Reads SAP Advanced Business Application Programming (ABAP) SAP ABAP stands for Advanced Business Application Programming. SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which i 6 min read What is SAP ABAP: A Brief Overview SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which includes enterprise resource planning (ERP) systems and other bu 8 min read SAP ABAP | Basic Syntax & 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 eff 9 min read SAP ABAP | Understanding Variables What is a Variable?Variable are named data objects that refer to the memory location allocated during the program execution for processing. As the name indicates, users can use refer to the range of values that may be stored inside and the range of actions that can be carried out on the variable.Syn 7 min read SAP ABAP Keywords The core of many global enterprises, SAP ABAP stands for Advanced Business Application Programming. It is the heart and soul of SAP systems. It gives users the ability to expand and modify SAP apps to satisfy particular business needs. The fundamental building blocks of SAP ABAP are its keywords, wh 5 min read SAP ABAP | Constants & Literals Explained In the world of SAP ABAP (Advanced Business Application Programming), the use of Constants and Literals is necessary for the effective handling of data. Literals are used to denote specific data types such as numbers, characters, strings, and boolean values.Constants & Literals in SAPWhat are Li 7 min read SAP ABAP | Data Types Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of t 6 min read Relational operators in SAP ABAP Relational operators in SAP ABAP are symbols or combinations of symbols that compare values and return a Boolean result (either true or false). These operators allow developers to establish relationships between variables, constants, or expressions, facilitating decision-making processes in the prog 6 min read Operators in SAP ABAP High-level programming languages like SAP ABAP (Advanced Business Application Programming) are used to create apps in the SAP environment. Operators are essential for the execution of many different operations in SAP ABAP, ranging from straightforward arithmetic computations to complex logical analy 7 min read Loop concept in SAP ABAPSAP ABAP | Decision Control StatementsSAP 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 3 min read SAP ABAP | Loop ControlIntroduction 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 4 min read SAP ABAP | While LoopA fundamental control structure in SAP ABAP is the while loop. The while loop in SAP ABAP can be used to iterate a part of code while the given condition remains true. This construct the while loop facilitates iterative running a block of code continues to execute until the specified condition withi 3 min read SAP ABAP | Do LoopDO loop in SAP ABAP is an unconditional loop that executes a block of code several times without providing a specific condition. It is a fundamental construct that facilitates the iterative execution of a code block until a specified condition is met. Programmers, through the incorporation of do loo 5 min read Prime numbers from 1 to n in SAP ABAPSAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP (Systems, Applications, and Products in Data Processing). It was developed in the 1980s for building business applications in the SAP environment. SAP ABAP is primaril 2 min read Nested Loop in SAP ABAPA nested loop means a loop statement inside another loop statement. That is why nested loops are also called âloop inside loopsâ. NesteÂd loops in SAP ABAP are a valuable tool when you need to iterate within another loop. They come in handy for processing hieÂrarchical data or performing complex dat 3 min read Like