Application Development 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: 

Datebase Cursor

AJeB
Participant

what is the purpose of this variable -> dbcursor ? because sometimes it becomes 1 or 2

open cursor with hold @data(dbcursor) for

select * from scarr.

2 REPLIES 2

matt
Active Contributor

You can have more than one cursor at a time - up to 17. You have a different dbcursor for each cursor open, allowing you to specify which cursor you're fetching from or closing.

The help for the FETCH statement has a nice example https://help.sap.com/doc/abapdocu_753_index_htm/7.53/en-US/abapfetch.htm

OPEN CURSOR @DATA(dbcur1) FOR
  SELECT carrid, COUNT(*) AS count
         FROM spfli
         GROUP BY carrid
         ORDER BY carrid.

OPEN CURSOR @DATA(dbcur2) FOR
  SELECT *
         FROM spfli
         ORDER BY carrid.

DATA: BEGIN OF counter,
        carrid TYPE spfli-carrid,
        count  TYPE i,
      END OF counter,
      spfli_tab TYPE TABLE OF spfli.
DO.
  FETCH NEXT CURSOR @dbcur1 INTO @counter.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  cl_demo_output=>next_section( |{ counter-carrid
                              }, { counter-count }| ).
  FETCH NEXT CURSOR @dbcur2
    INTO TABLE @spfli_tab PACKAGE SIZE @counter-count.
  cl_demo_output=>write( spfli_tab ).
ENDDO.

CLOSE CURSOR: @dbcur1,
              @dbcur2.

cl_demo_output=>display( ).

Sandra_Rossi
Active Contributor

It's explained in the documentation. Why not pressing F1?