ABAP OPEN CURSOR statement for open a database cursor

OPEN CURSOR statement is used for open a database cursor in ABAP programs. A database cursor is similar to a reference variable. Using normal SELECT statement will directly store the results, but with OPEN CURSOR it will decouple the process from the SELECT statement. The cursor name should define with DATA statement. CLOSE CURSOR statement is used for closing an opened database cursor. We can open any number of cursor for a single database.

Syntax

OPEN CURSOR [WITH HOLD] <c> FOR SELECT      <result>

FROM      <source>

[WHERE    <condition>]

[GROUP BY <fields>]

[HAVING   <cond>]

[ORDER BY <fields>].

 

 

FETCH statement is used for reading the data from opened cursor. It usage is as follows

FETCH NEXT CURSOR <c> INTO <target>.

 

Using this we can read data by data and can do other processing, than store the entire data using normal SELECT statement. And we can also reuse this opened cursor in our program.

Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes