![]() |
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:![]() 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.
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,
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,
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 |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |