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 For Loop with Multiple Tables
Result:
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 loop with Let Statement for Multiple Tables
Result
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.
No comments:
Post a Comment