Many of you already know to work with For loop in SAP ABAP. However, those who are new to the ABAP 7.4 syntax often struggle at some places to achieve the expected result using new syntax. One of the scenario, I am covering below so that new learner can find help with this post.

Scenario:

When we process multiple internal table inside the for loop(in which the where condition of the second internal table will be from the first internal table inside the For Loop). In this case, the result in the final internal table will be only the common data in which they find in both the internal tables.

As you can see below, GT_N has two rows. While GT_C has only one row. When we are processing these two internal tables, only the common data between these two tables is processed completely. If the data with the similar key is not present in both the internal tables then it does not process and skips the complete execution for that particular row and moves to the next row in the first table. Finally the result will be only the common data between the two tables.

Multiple%20For%20Loop%20with%20Multiple%20Tables

Multiple For Loop with Multiple Tables

 

Result:

Result%20for%20Multiple%20For%20Loop%20with%20Multiple%20Tables

Result for Multiple For Loop with Multiple Tables

 

Sometimes, we have a case, even if the record is not found in the second table then too we need to append the data of first table to the final internal table with the blank values for which the record is not found in the second tables. To achieve this, we can use LET keyword inside the for loop.

For%20loop%20with%20Let%20Statement%20for%20Multiple%20Tables

For loop with Let Statement for Multiple Tables

Result

Result%20-%20For%20loop%20with%20Let%20Statement%20for%20Multiple%20tables

Result – For loop with Let Statement for Multiple tables

 

Using the LET keyword, For loop does not skip the record and process every record completely. Also, every record is appended in the final internal table. For the one which does not have the records in the second internal table is appended in the final table with the blank value for that particular column.

Thanks for taking your time to read this blog. I hope this will help you to achieve these kind of scenario easily. Also, you can check SAP Help site to see more examples with For Loop with different expressions.

Kindly share your comments, if you find this useful. Also, share your ideas in comments if you have used different expression with new ABAP 7.4 syntax to meet your scenario.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x