‎2008 Feb 18 11:01 AM
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?
‎2008 Feb 18 11:09 AM
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.
‎2008 Feb 19 3:41 AM
Thank u jose,
Can i Know what is the advantage of using this, instead of other select statements
‎2008 Feb 19 4:15 AM
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]
‎2008 Feb 19 4:33 AM
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.
‎2008 Feb 19 4:35 AM
hi
good
please check this links hope these would give you the idea for the open cursor.
http://www.sapdb.org/7.4/htmhelp/40/1311f42fa511d3a98100a0c9449261/content.htm
http://www.sapdb.org/7.4/htmhelp/7b/0bdea252d746429420007a69bd06c7/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3b23358411d1829f0000e829fbfe/content.htm
thanks
mrutyun^