Tuesday, 7 January 2014

Select Loops in SAP ABAP

Select Loops in SAP ABAP

This next section will discuss iteration statements, otherwise known as looping state-ments. These are used to execute a block of ABAP code multiple times.
Create another new program and call it Z_ITERATIONS_1.
There are various ways to loop through blocks of code in an ABAP program, and these can be separated into those which have conditions attached and those which do not. The SELECT statement is a form of loop which has already been used. This statement allows you to iterate through a record set.
                                            
Select Loops in SAP ABAP
The asterisk (*) tells the program to select everything from the zemployees table, and this is followed by a WRITE statement to write the table to the output screen. The SELECT loop closed with ENDSELECT, at which point the loop returns to the start, writing each record in turn until there are no more records to process in the table.
This last example had no conditions attached. To add a condition is quite simple
Select Loops in SAP ABAP

                                        
Here, only records where the surname is Mills will be selected and written to the output screen
Select Loops in SAP ABAP


2 comments: