Monday, January 20, 2014

TAW10 - INPUT CHECKS

FIXED VALUES


If you can input only a limited set of values while creating a domain, then these values are defined as fixed values. These can either be listed individually or defined as an interval. Moreover, fixed values generate F4 Help. As soon as screen entries are made, the fixed values are immediately used as check values.
When fixed values are specified, the value range of the domain gets limited by these values. The value range of a field is determined by its data type and field length.


VALUE TABLE

The value range of a field can be defined using a value table. You can define the value range of a field by specifying a value table in the domain. Validation occurs only after a foreign key is defined for a field or component. In such cases, the system proposes the value table as a check table.

INSERTING A DATA RECORD

This slide illustrates the flight booking details of a customer with American Airlines (AA). The user places an inquiry whether the booking can be made at counter 8. While Table SBOOK mentions 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 ensure that only valid counters are entered. Therefore, these counters must be stored in table SCOUNTER.

VIOLATION OF THE FOREIGN KEY CHECK


The booking entries made in table SBOOK are rejected as no corresponding data record for COUNTER is selected from table SCOUNTER. The customer’s request for booking this particular flight at counter 8 is rejected as the counter for American Airlines (AA) is 1 rather than 8. Such relationships between two tables are defined in the ABAP Dictionary using foreign keys which must be defined explicitly for the fields. By using foreign keys, consistency of data is ensured as data that is entered is matched against the existing data.


FOREIGN KEY FIELDS/CHECK FIELDS

Let us understand how to use foreign key fields using two tables, SBOOK and SCOUNTER. Here, Table SBOOK is the foreign key table. Its purpose is to ensure that only valid carrier counters can be assigned to a booking.
On the other hand, Table SCOUNTER is the check table and contains exactly the same information. Each counter in this table has three key fields; namely MANDT, CARRID, and COUNTNUM.
You can define the foreign key by assigning these three fields to the fields of the foreign key table which is used to enter the input on the screen. The entry is accepted only if the entry represents a valid counter. The COUNTER field is called the check field for this foreign key defined for field SBOOK-COUNTER. This means that the entry in this field is checked.
In the example shown here, a foreign key is defined for field COUNTER leading to three check tables, SCOUNTER-CLIENT, SCOUNTER-CARRID, and SCOUNTER-COUNTNUM; and three foreign key tables, SBOOK-MANDT, SBOOK-CARRID, and SBOOK-COUNTER.


DATA CONSISTENCY THROUGH FOREIGN KEYS

The check field is the field of the foreign key table that is to be checked. A foreign key is a group of fields of a table that is also the primary key for another table. Therefore, a foreign key links two tables, the check table and the foreign key table. The check table, also known as the referenced table, is the table whose key fields are checked. The foreign key table contains entries which must be consistent with the key fields of the check table.



FOREIGN KEY DEFINITIONS IN THE CHECK FIELD

Domain equality between the check field and the referenced key field of the check table is a mandatory requirement in the ABAP Dictionary. By using the same domain for the check field and the referenced key field of the check table, there will not be any need to compare fields with different data types and field lengths. While you can use different data elements, they must always refer to the same domain. If domains are not equal, the foreign key will not be consistent. If the domain of the check field contains a value table, the value table can act as check table, if the value table does not have any foreign key.
However, for all other foreign key fields, only the data type and the field length are required to be equal.


CHECK TABLE NOT EQUAL TO VALUE TABLE
This slide illustrates an example of a foreign key definition. It shows the system proposal for the field AGENCYNUM in SBOOK, on the basis of the value table in the domain.
Let us assume that SBUSPART is the check table. For check table SBUSPART-CLIENT, the foreign key table is SBOOK-CLIENT, while for check table SBUSPART-BUSPARTNUM, the foreign key table is SBOOK-AGENCYNUM.
However, this proposal is not correct. The SBUSPART table contains all the business partners of airline carriers. However, only agencies are allowed for field SBOOK-AGENCYNUM. Table SBUSPART, therefore, contains invalid data for this field. In fact, table STRAVELAG is the correct check table. It is a subset of table SBUSPART owing to its foreign key definition on field AGENCYNUM.



SEMANTIC ATTRIBUTES


Cardinality is a semantic attribute that describes the foreign key relationship with regard to the number of records of the check table that are assigned to records of the foreign key table. The cardinality must be defined with regards to the check table.
A foreign key field can identify a table entry based on its type. There are four types of foreign key fields:
Not specified means that there is no information about the kind of foreign key field.
No key fields or candidates suggests that the foreign key fields are neither primary key fields of the foreign key table nor do they uniquely identify a record of the foreign key table.
Key fields or candidates indicates that the foreign key fields are either primary key fields of the foreign key table or they uniquely identify a record of the foreign key table.
Key fields of a text table means that the foreign key table acts as a text table in the check table in cases where the key of the foreign key table only differs from the key of the check table in an additional language key field.


TEXT TABLE

Table SMEAL depicts information about in-flight meals provided to the passengers. The meal names are maintained in another table, SMEALT. Table SMEALT is the text table for table SMEAL as the key of SMEALT comprises the key of SMEAL and an additional language key field. An explanatory text for all the key entries of SMEAL can also be given in Table SMEALT.
You must link the text table SMEALT with table SMEAL using a foreign key to link the key entries with the text. Key Fields of a text table must be selected for the type of the foreign key fields.

No comments:

Post a Comment