Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how open cursor statement works

Former Member
0 Likes
811

hi,

OPEN CURSOR [WITH HOLD] dbcur FOR

SELECT result

FROM source

[[FOR ALL ENTRIES IN itab] WHERE sql_cond]

[GROUP BY group] [HAVING group_cond]

[ORDER BY sort_key].

i want to know what does open cursor statement do, how it works, what does dbcur contain?

5 REPLIES 5
Read only

Former Member
0 Likes
664

Hi,

dbcur is cursor name gn by u....

Its like select statement....u hav used for all entries right....so if der are 3 records in ur int table and corresponding 3 records ll be fetched in select-endselect query right.....

here in open cursor statement u don hav INTO(destination) right

so after opening cursor......

FETCH NEXT CURSOR dbcur into wa1.

FETCH NEXT CURSOR dbcur into wa2.

FETCH NEXT CURSOR dbcur into wa3.

wa1,wa2,wa3 ll have the 3 records....

close cursor.....................

Cheers,

jose.

Read only

0 Likes
664

Thank u jose,

Can i Know what is the advantage of using this, instead of other select statements

Read only

0 Likes
664

It does depend on why you are using open cursor functionality. It is all about removing the dependance on reading data into a work area from the select statement.

There is a very good example of this in saphelp - see the example of selecting smoking and non-smoking seats from the same table and the inner join simulation

[Using a Cursor to Read Data |http://help.sap.com/saphelp_nw04s/helpdata/en/fc/eb3b23358411d1829f0000e829fbfe/frameset.htm]

Read only

Former Member
0 Likes
664

hi,

A SELECT statement defines and creates a result table with the name result_table_name .

An OPEN CURSOR statement is not permitted for result tables created with this SELECT statement.

The SELECT statement is subject to the rules that were specified for the DECLARE CURSOR statement and those that were specified for the OPEN CURSOR statement.

Depending on the search strategy, either all the rows in the result table are searched when the SELECT statement is executed and the result table is physically generated, or each next result table row is searched when a FETCH statement is executed, without being physically stored. This must be taken into account for the time behavior of FETCH statements.