Search on this Website

Saturday, June 14, 2008

Data Validation Using Matchcodes


Another useful way to maintain data integrity during user input is to use matchcodes. A matchcode is an object that is used to find data records in the SAP Data Dictionary. More specifically, matchcodes access data records in a way similar to an index in that all key fields are not necessary, but they differ from indexes in that matchcodes can contain more than one table in the selection range.

Here's how it works: First a matchcode object is defined with the pertinent primary and secondary tables and significant fields designated. This object then identifies all possible paths to the required data records. Next, matchcode IDs are created by mapping one path defined by the matchcode object. The only data fields that are allowable in this ID are based entirely on the matchcode object. At least one ID must be declared for each matchcode object. Matchcode objects are stored as a table pool, which is automatically generated for each matchcode ID that you declare.
A data pool is a logical pooled table that is used by SAP to internally store control data. This data, which is not pertinent externally, is mapped as a number of database tables to one SAP table.
A matchcode can be assembled in two different fashions:
Physically. In this setting, data is stored in a separate table in the SAP system. Update types A, P, and S are maintained in physical tables.

Logically. This option sets up matchcode data temporarily on access to the matchcode. This access is managed by a database view. In this respect, the logical method is the same as transparent storage. This includes update types I and K only.

In the following task, you will learn how to follow 12 easy steps to create and maintain matchcode objects. Start at the Data Dictionary screen and complete the following steps:

The initial screen of Data Dictionary.

Enter a name for your new object, click on the Matchcode radio button, and press the Create button.
Enter descriptive text as you enter your primary table on the Attributes screen and press the Save button. The primary table represents the primary source table for the subsequent field search. Secondary tables can also be maintained at this point by double-clicking on the primary table or pressing the Tables button. These tables must link to the primary table through foreign keys.

At this point you have the option of creating the matchcode as a local object or attaching it to a transport request. After you have done this, click on the Save button .

As the status bar reflects, the mandatory key fields are transferred automatically If you want, you can press the Fields button and maintain any selection fields you want. At this point you need to click on the green arrow to go back to the Maintain Attributes screen.
The next step in the creation process is to activate the matchcode object. The status of the object is New and Saved .
The status is now set to Active and Saved. Next you need to create a matchcode ID or your object will be incomplete. To do this, click the Matchcode IDs button.

The system will prompt you to create a new ID if one does not exist . To do this, click on the Yes button.
On the Create Matchcode ID screen shown in Figure 21.9, specify a matchcode ID number, valid input ranges from all of the alphabet, and any number. You can also click on the down arrow to view a range of valid entries.
The Create Matchcode ID dialog box.
Let's view some possible entries . As you can see, this list window shows a number of matchcode IDs and a short description of each. Choose one and click on the green arrow.

A Matchcode hit list.
Follow these steps we learned to maintain selection fields for this matchcode ID, be sure to enter an Update type, and click on Save . I will further discuss Update types later in this section. At this point, you can enter further selection criteria by pushing the Selection Criteria button.
Maintenance of matchcode attributes.
In the Maintain Selection Conditions screen, you can enter and maintain fields and selection criteria for your matchcode IDs. Here is an example of a requirement of a Material Number not greater than the value of 8888 . When finished, click Save and the green arrow to go back.
The Maintenance Selection Conditions dialog box.
Now all you have to do is activate your matchcode ID and your new object is ready to use.
Generate and use the matchcode.

NOTE
The Index sub-screen doesn't need to be maintained because these characteristics are merely for documentation purposes in the current version of the SAP system. Just leave this blank and ignore the subsequent warning that appears in the log of your object activation.

In those 12 easy steps you created a matchcode that you can now use for maintaining data integrity. You learned how the primary keys help you check possible values of linked tables and the concept of a pool of data fields. Remember, the manner in which the matchcode data is arranged varies according to which update type is selected during initial creation. Here is a description of each of these five types:

I-Arranged by the attributed database.
S-Arranged by the database interface.
A-Auto-arranged by the system program SAPMACO.
P-Arranged by an application program.
K-Also arranged by an application program.
Syntax for Using a Matchcode
The following is the syntax for using matchcodes for selection screen parameter input validation:

tables: saptab
parameter: example like saptab-field matchcode object exam.
select single field from saptab where field = example.

This example uses the matchcode object exam, which has already been defined with a matchcode ID, to validate the data input into the parameter field example. This object exam holds the relationship data necessary to maintain the integrity of the user input.

No comments: