ABAP - Keyword Documentation →  ABAP - Dictionary →  Classic Objects in ABAP Dictionary →  Views →  Classic Views → 

Database Views

A database view is a general view for one or more basis tables. If there are multiple basis tables, they are joined using an inner join. A matching SQL view is created on the database when the view is activated. The structure type defined using the view fields of the database view can be referenced in ABAP programs using TYPE. A database view can be accessed using both Open SQL and Native SQL.

Notes

Basis Tables

The basis tables of database views must be transparent tables, so that the SQL view can access them. The actual join operation is performed on the database.

Note

The basis tables of CDS database views, which are generated for CDS views, can also be other database views.

View Fields

An include mechanism can be used to add individual fields or all fields from the basis tables as view fields of a database view. When individual fields are used, a different name can be defined for a view field than the name in the basis tables. This name can have a maximum of 30 characters, must meet the naming conventions for component names of structures, and cannot be a reserved name. The reserved names that cannot be used are in the database table TRESE.

To use all fields, the * character is used instead of the field name. If the - character is used for individual fields of a basis table included using *, all fields up to the fields specified with - become view fields. If the structure of a database table whose fields were added in this way is modified, the structure of the view is also modified.

Notes

Join Conditions

The join conditions for the inner join can be formulated using equality relationships between any two table fields in the basis tables. The inner join joins the rows of the basis tables in question as a results set containing all combinations of rows whose columns together meet the join conditions. If there are no rows that meet the join conditions in the basis tables in question, no row is created in the results set. If there is a suitable foreign key dependency (including generic and constant foreign keys) between two basis tables, this dependency can be used as a default for defining join conditions in ABAP Dictionary.

Maintenance Status

The Access setting in the maintenance status of a database view can have the following values:

The database view can only be used to read data with Open SQL.
If the database view contains only a single basis table, data can be changed using Open SQL.

A database view with multiple basis tables can only be read with Open SQL. If a database view contains only a single table, data can be inserted in this table using the view with the Open SQL statements INSERT or MODIFY. The following options are available for the content of the table fields not in the view:

Notes

SAP Buffering

Just like in database tables, it is possible to define for a database view whether the data in the SAP buffer is buffered. The same buffering types can be defined and SAP buffering in Open SQL is handled in the same way for views and for database tables with the only difference being that, when data is modified in one of the basis tables, the entire buffer is invalidated when the buffers are synchronized, regardless of the buffering type In client-specific views, however, this only affects the content of the current client.

The following prerequisites must be met before a database view can be buffered:

Example

The database view DEMO_SCARR_SPFLI contains fields of the tables SCARR and SPFLI. Other names are assigned to these fields in the view.

The associated database object could be as follows:

CREATE VIEW DEMO_SCARR_SPFLI
   (CLIENT,
   ID,
   CARRIER,
   FLIGHT,
   DEPARTURE,
   DESTINATION )
AS SELECT
   T1."MANDT",
   T2."CARRID",
   T1."CARRNAME",
   T2."CONNID",
   T2."CITYFROM",
   T2."CITYTO"
FROM
    "SCARR" T1,
    "SPFLI" T2
WHERE
    T1."MANDT"  = T2."MANDT" AND
    T1."CARRID" = T2."CARRID"

The view could be accessed as follows using Open SQL:

SELECT *
       FROM demo_scarr_spfli
       ORDER BY id, carrier, flight
       INTO TABLE @DATA(result).

cl_demo_output=>display( result ).