SAP EXEC CURSOR ABAP Statements
Get Example source ABAP code based on a different SAP table
EXEC SQL - OPEN, CLOSE, FETCH
In embedded
• OPEN FOR SELECT EXEC SQL
ABAP Syntax
What does it do? Opens a database cursor
• FETCH EXEC SQL
ABAP Syntax
What does it do? Reads data using an open database cursor
• CLOSE EXEC SQL
ABAP Syntax
What does it do? Closes an opened database cursor
Latest notes:It depends on the database system whether the database cursor in the database is closed implicitly after the extraction of the final row of the results set or not. For this reason, it is advisable to use the statement
Example ABAP Coding
Reads multiple rows from the database table
DATA: connid TYPE spfli-connid,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto.
EXEC SQL.
OPEN dbcur FOR
SELECT connid, cityfrom, cityto
FROM spfli
WHERE mandt = :sy-mandt AND
carrid = :p_carrid
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT dbcur INTO :connid, :cityfrom, :cityto
ENDEXEC.
IF sy-subrc <(><<)>> 0.
EXIT.
ELSE.
...
ENDIF.
ENDDO.
EXEC SQL.
CLOSE dbcur
ENDEXEC.
Return to menu