Show TOC

Database AccessLocate this document in the navigation structure

Concept

Open SQL is a subset of Standard SQL used for access to relational database tables of the central SAP system database defined in ABAP Dictionary. If required, Native SQL or ADBC can be used for database-specific SQL statements. Furthermore, interfaces and classes in Object Services provide the option of saving persistent objects to the database.

Open SQL

The statement SELECT is used to read any column from database tables to ABAP data objects. Either the columns of a single row can be read or the columns of multiple rows. The data can be taken from one or more database tables. In the latter case, the database tables are joined using a join expression. In multi-row results sets, the ABAP target objects can either have multiple rows (internal tables) or an ENDSELECT statement has to follow the SELECT statement. The rows in the results set are then passed to the single-row target fields in a loop.

The statements INSERT, UPDATE, MODIFY, and DELETE are used to modify data in database tables. To keep the data on the database consistent, modifying SQL statements can only be executed within an LUW (Logical Unit of a Work). The SAP LUW concept is based on the paging out of modifying statements to update function modules and on a logical lock concept. Initially, update modules are registered using the addition IN UPDATE TASK of the statement CALL FUNCTION and then triggered using the statement COMMIT WORK. The statement ROLLBACK WORK is used to roll back registrations.

Example

Reads multiple columns and rows from the database table spfli to the internal table flights_tab.

               DATA flights_tab TYPE STANDARD TABLE OF spfli.

SELECT carrid connid cityfrom cityto
       FROM spfli
       INTO CORRESPONDING FIELDS OF TABLE flights_tab
       WHERE carrid = 'LH'.