Ansicht
Dokumentation

ABENDB_INTEGRITY - DB INTEGRITY

ABENDB_INTEGRITY - DB INTEGRITY

BAL_S_LOG - Application Log: Log header data   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

Database Integrity

A database is a model of a part of the real world. It should be consistent and its content should match the part of reality it is modeling. Data integrity is one of the most important aspects to be taken into consideration when programming application software. The following aspects of integrity can be distinguished:

  • Semantic integrity
  • Relational integrity
  • Operational integrity

Semantic Integrity

Semantic integrity refers to the consistency and completeness of the data. In a flight reservation system, for example, the 'Occupied Seats' field for each flight must always contain a value which is less than or equal to the content of the 'Maximum number of seats' field. This avoids overbooked flights. If this is not the case, the data is inconsistent. In addition, each new booking in the flight reservations table must increase the content of the field 'Occupied seats' for the booked flight in the flights table. Together, both these operations form a unit and, if only one is executed, the database becomes incomplete.

In many database systems, semantic integrity conditions can be checked using constraints or triggers. Due to their lack of standardization, however, these methods are not used in AS ABAP. This means that, in AS ABAP, the semantic integrity of the database must be verified by the programmer of the application programs.

As the flight reservation example shows, the data is usually in an inconsistent or incomplete state in the course of a transaction. For this reason, programmers need to be able to confirm the end of the transaction and thus the restoration of the semantic integrity of the data. This is known as the database commit.

Relational Integrity

Relational integrity refers to the observation of the integrity rules governing the relational model. Since data modeling in AS ABAP is based on the relational data model, these rules must be observed. They include:

  • Primary key integrity
Each database object must be identified uniquely by a primary key.
Contrary to relational data model theory, tables can be created without a primary key in most database systems. In ABAP Dictionary, each table must have a primary key. For this reason, primary key integrity is automatic.
  • Value range integrity
Each value of a table field must exist in the value range of this field. In a flight reservation system, for example, it must be possible to distinguish between private and business customers. This means that the 'Business/Private Customer' field can contain only the value 'B' (for 'business customer') or 'P' (for "private customer").
In most database systems, value ranges can be specified as constraints when defining a table field. The database system then automatically prevents the occurrence of an invalid value in a database table. Due to its lack of standardization, however, this method is not used in AS ABAP. Despite this, value ranges can be defined for domains and database fields in ABAP Dictionary and used to guarantee the integrity of the database: In dialog transactions, this knowledge is used to check user input and to display possible entries.
  • Foreign key integrity (referential integrity)
Each foreign key must reference an existing primary key. In a flight reservation system, for example, the content of the 'Airline Carrier' field must exist in the airline carriers table for each flight.
In most database systems, foreign key dependencies can be specified as a constraint when defining a table. The database system then automatically prevents the occurrence of an invalid row in a database table. Due to its lack of standardization, however, this method is not used in AS ABAP. Despite this, foreign key relationships can be defined between tables in ABAP Dictionary and used to guarantee the integrity of the database: In dialog transactions, this knowledge is used to check user input and to display possible entries.

Operational Integrity

Operational integrity guarantees protection for the dataset against inconsistencies caused by multiple users attempting to gain access at the same time. The necessity of this is demonstrated by the next example, where clerks S1 and S2 both want to make a booking in the flight reservation system at the same time.

  • S1 reads the row of the planned flight from the flights table. The value of 'Occupied Seats' is less than the value of 'Maximum Number of Seats'.
  • S2 reads the row of the planned flight from the flights table. The value of 'Occupied Seats' is less than the value of 'Maximum Number of Seats'.
  • S1 makes a new flight reservation.
  • S1 increases 'Occupied Seats' by 1.
  • S2 makes a new flight reservation.
  • S2 increases 'Occupied Seats' by 1.

Since both clerks see the same value in the field 'Occupied Seats', the flight could now be overbooked.

Database systems guarantee operational integrity automatically by enqueueing competing accesses. This is done by using a database lock mechanism. The following variant of the above example demonstrates this:

  • S1 reads the row of the planned flight from the flights table with the intention to change. The value of 'Occupied Seats' is less than the value of 'Maximum Number of Seats'.
  • S2 reads the row of the planned flight from the flights table with the intention to change. Since the row is locked by S1, S2 must wait.
  • S1 makes a new flight reservation.
  • S1 increases 'Occupied Seats' by 1.
  • S1 ends the LUW (Logical Unit of Work) and thus releases the database locks.
  • S1 can now access the row of the planned flight from the flights table. The value of 'Occupied Seats' is less than the value of 'Maximum Number of Seats'.
  • S2 makes a new flight reservation.
  • S2 increases 'Occupied Seats' by 1.
  • S2 ends the LUW (Logical Unit of Work) and thus releases the database locks.





PERFORM Short Reference   General Data in Customer Master  
This documentation is copyright by SAP AG.

Length: 7652 Date: 20240328 Time: 101123     sap01-206 ( 138 ms )