Database Views

In the relational data model, data for one application object are often distributed among several database tables. Database systems therefore offer the possibility of defining application-specific views on the distributed data.

Database views can be defined in the ABAP Dictionary. The view defined in the ABAP Dictionary is implemented with an equivalent view in the database. The view is automatically created on the database when it is activated in the ABAP Dictionary.

Application programs can access the data of a database view using the database interface. The actual data selection, however, is made in the database.

If more than one table is contained in the view, only read access is allowed. Since the join operation for database views takes place in the database in this case, such views can be used to minimize the number of database accesses.

Database views implement an inner join, that is, you get only those records of the primary table for which records of the secondary tables which were selected with the join also exist. Inconsistencies between primary and secondary table can therefore lead to a reduced selection set.

Database views should be created if want to select logically connected data from different tables simultaneously. Selection with a database view is generally faster than accessing individual tables. When selecting with views you should also ensure that there are suitable indexes in the tables contained in the view.

Since a database view is implemented on the database, only transparent tables can be used in such a view.

Buffering Database Views

The data read with a database view can be buffered. The buffering of view data behaves just the same as the buffering of tables. The technical settings of a database view control whether view data may be buffered (see Buffering Permission) and how it should be buffered (see Buffering Type). The same settings are possible as when buffering tables.

The buffered view data is invalidated as soon as the data in one of the base tables of the view has changed.

Includes for Database Views

It is possible to include entire tables in a database view. In this case all the fields of the included table will become fields of the view (whereby you can explicitly exclude certain fields). If new fields are included in the table or existing fields are deleted, the view is automatically adjusted to this change. A new or deleted field is thus included in the view or deleted from the view in this case.

The Flight Model describes the customer’s flight bookings. A booking can be made for example by a travel agency. The data on the travel agencies is stored in table STRAVELAG. The number, name, address, etc. is entered there for each travel agency. Table SBOOK contains all the bookings made.

The carrier and the travel agencies need an overview of the bookings made by an agency. Since the data required to do this is distributed in tables STRAVELAG and SBOOK, the overview must be implemented with a view. The join condition of view SACY_BOOK is as follows:

STRAVELAG-MANDT = SBOOK-MANDT

STRAVELAG-AGENCYNUM = SBOOK-AGENCYNUM

The fields of both tables needed for this special view on the data can now be included in the view. For example, fields MANDT, CARRID, AGENCYNUM, CONNID, FLDATE, BOOKID, CLASS, CANCELLED in table SBOOK and fields NAME, STREET, POSTBOX, POSTCODE, CITY, COUNTRY in table STRAVELAG.

You can display the bookings which have not yet been cancelled with the following selection condition:

SBOOK-CANCELLED NE ‘X’

See also:

Inner and Outer Join

Buffering Database Tables

Creating a Database View

Inserts with Database Views