Cursors are found in database and it is used to define how the screen elements of the program should be placed. When a table's data is displayed in screen, the cursor automatically is set on the first field of table. Through ABAP programming one can define the screen element which should be indicated by the cursor. The screen element is not necessarily an input field. It can be a display field and the cursor can be defined in a user friendly manner to enable easy viewing of the screens and data.
Static and Dynamic Cursors
There are two types of cursor defined in ABAP programming: Static cursor and Dynamic cursor.
1. In static cursor one can define the position of the cursor. To define the position statistically, the name of the screen element should be placed in the cursor position screen attributes, which is found in the Screen painter.
2. To set up dynamic cursor position, ABAPs standard programs can be used.
There are many components provided in SAP which are used to improve the performance of a code. In ABAP programming the aim is to speed up performance and a number of techniques are used to get a better result.
Drawbacks of Nested loop as compared to Parallel loops
There are two methods used for searching a data in a table - Nested Loops or parallel Cursor. Both the methods are used to deliver the desired result. In a LOOP, the "Where" clause is used to search for the needed data and in case the data is checked in heavy tables, the technique of LOOP can be very lengthy and time consuming. To prevent delays parallel cursors can be used.
The program code uses a variable which prevents the code from starting the search all over again from the first position and it controls the loops at a specified index. The prerequisite for the method is that the tables should have key fields and should be sorted according to the key fields.
In ABAP programming the user has to see if there is any entry from the first table's loop to the second table to get the desired result. The program uses the method of READ WITH KEY and BINARY SEARCH to get the result.
In case of nested loops, for two tables the code executes in the following manner without using the parallel cursors
Loop at Tablename1 into (search result).
Loop at Tablename2 into (search result).
In case of parallel cursor, the code executes in the following manner:
TABLES: *Define tables, data, types and variables
SELECT * FROM T1 INTO TABLE (tablename).
CHECK T1 IS NOT INITIAL.
SELECT * FROM T2 FOR ALL ENTRIES IN T1 WHERE FIELD1=FIELD2.
SORT T1 BY (INDEX),
T2 BY (INDEX).
LOOP AT T1 ASSIGNING <VARIABLE>.
READ TABLE T2 TRANSPORTING NO FIELDS
WITH KEY (INDEX) = <VARIABLE > - INDEX
lv_tabix = sy-tabix. * Set tabix number
LOOP AT T2 FROM lv_tabix ASSIGNING <FIELD2> .
* End the LOOP, when there is no more record with similar key