Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  OPEN CURSOR 

OPEN CURSOR - mainquery_clauses

Other versions: 7.31 | 7.40 | 7.54

Syntax


... { FROM source 
      FIELDS select_clause }
  | { select_clause
      FROM source }
    [[FOR ALL ENTRIES IN itab]
      WHERE sql_cond]
    [GROUP BY group] [ HAVING group_cond]
    [ORDER BY sort_key]
    [db_hints] ...

Effect

Possible clauses and additions of the main query after OPEN CURSOR. All the same clauses are possible as for a standalone a SELECT statement except for SINGLE. The clauses define the results set, which can be accessed using the FETCH statement. The results set is regarded as having multiple rows.

The addition FOR ALL ENTRIES cannot be used if common table expressions are defined using WITH.


Example

Statement OPEN CURSOR with all possible clauses.

OPEN CURSOR @DATA(dbcur) FOR 
  SELECT FROM sflight 
         FIELDS carrid, 
                connid, 
                SUM( seatsocc ) AS seatsocc 
         WHERE  carrid = 'LH' 
         GROUP BY carrid, connid 
         HAVING SUM( seatsocc ) > 1000 
         ORDER BY carrid, connid.