ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 03.04.2021
Просмотров: 2386
Скачиваний: 41
BC430
Lesson: Consistency Through Input Checks
Specifying fixed values causes the value range of the domain to be restricted by
these values. Fixed values are immediately used as check values in screen entries.
There is also F4 help.
Fixed values can either be listed individually or defined as an interval.
Figure 45: Value table
The value range of a field can also be defined by specifying a value table in the
domain.
In contrast to fixed values, however, simply specifying a value table does not
cause the input to be checked. There is no F4 help either.
If you enter a value table, the system can make a proposal for the foreign key
definition.
A value table only becomes a check table when a foreign key is defined. If
you refer to a domain with a value table in a field, but no foreign key was
defined at field level, there is no check
.
2006/Q2
© 2007 SAP AG. All rights reserved.
103
Unit 4: Input Checks
BC430
Figure 46: Inserting a Data Record
A customer wants to book a flight with American Airlines (AA). This flight with
flight number 0017 is to be on November 22, 1997. The booking should be made
at counter 8.
Table SBOOK contains all the flight bookings of the airlines.
Table SCOUNTER contains all the valid counters of the airlines.
If an entry is made in field COUNTER of table SBOOK, you must make sure that
only valid counters can be entered This means that the counters must be stored
in table SCOUNTER.
Question:
Are you allowed to insert the above data record in table SBOOK?
104
© 2007 SAP AG. All rights reserved.
2006/Q2
BC430
Lesson: Consistency Through Input Checks
Figure 47: Violation of the Foreign Key Check
The flight cannot be booked because American Airlines (AA) does not have
a counter 8.
No data record is selected in table SCOUNTER for the entries in the example.
The entry for table SBOOK is rejected.
In the ABAP Dictionary, sucsh relationships between two tables are called
foreign
keys
and they must be defined explicitly for the fields.
Foreign keys are used to ensure that the data is consistent. Data that has been
entered is checked against existing data to ensure that it is consistent.
2006/Q2
© 2007 SAP AG. All rights reserved.
105
Unit 4: Input Checks
BC430
Figure 48: Foreign key fields / Check fields
EXAMPLE:
In this example, the
foreign key table
is table SBOOK. The purpose of the
foreign key is to ensure that only valid counters of carriers can be assigned to a
booking. The
check table
SCOUNTER contains exactly this information. Each
counter is identified with three key fields in this table: MANDT, CARRID, and
COUNTNUM.
In order to define the foreign key, these three fields are assigned to the fields of
the foreign key table (foreign key fields) with which the input to be checked is
entered on the screen. In table SBOOK, these are the fields: MANDT, CARRID,
COUNTER. The entry is accepted if it represents a valid counter; otherwise the
system will reject it.
The foreign key is defined for field SBOOK-COUNTER (check field), which
means that the entry in this field is checked. The COUNTER field is therefore
called the
check field
for this foreign key.
A foreign key is defined for field COUNTER, table SBOOK, resulting in the
following field assignment:
Check table
Foreign key table
SCOUNTER-CLIENT
SBOOK-MANDT
SCOUNTER-CARRID
SBOOK-CARRID
SCOUNTER-COUNTNUM
SBOOK-COUNTER
106
© 2007 SAP AG. All rights reserved.
2006/Q2
BC430
Lesson: Consistency Through Input Checks
Figure 49: Data Consistency through Foreign Keys
A combination of fields in a table is called a foreign key if this field combination
is the primary key of another table.
A foreign key links two tables.
The check table is the table whose key fields are checked. This table is also called
the
referenced table
.
An entry is to be written in the foreign key table. This entry must be consistent
with the key fields of the check table.
The field of the foreign key table to be checked is called the
check field
.
Foreign keys can only be used in screens. Data records can be written to the table
without being checked using an ABAP program.
Example:
A new entry is to be written in table SPFLI (flight schedule). There
is a check whether the airline carrier entered is stored in table SCARR (carrier)
for field SPFLI-CARRID. The record is only copied to table SPFLI (foreign key
table) if this is the case. A foreign key is defined for field SPFLI-CARRID (check
field), for example, the checks are on this field. The corresponding check table is
table SCARR with the primary key fields CLIENT and CARRID.
2006/Q2
© 2007 SAP AG. All rights reserved.
107