📄 ch21.htm
字号:
is referred to as the check (or reference) table.<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
The foreign key field and the primary key of a parent table must share the same domain and a value table for that domain must also be specified. This extends, in a way, the data integrity check usually provided by the value table alone.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Some check tables can have multiple primary key fields. In such
cases, assignments must be made for each field when initiating
a foreign key relationship. Three options are as follows:
<UL>
<LI><I>Use a partial foreign key.</I> In this case, some fields
will not be a factor when validating acceptable values for entries
in the foreign key field. Certain fields are flagged as generic
in this case and thus ignored by the system on validation.
<LI><I>Use a constant foreign key.</I> In order for the field
input to be valid, the value must match that of the constant in
the check table.
<LI><I>Create a field-to-field assignment.</I> This is the most
thorough of the three choices. Every primary key field in the
check table is matched with a field in the foreign key table and
all key fields are then used to determine valid entries in the
foreign key table.
</UL>
<P>
Basically, the way a foreign key works resembles that of a direct
<TT>select</TT> statement against the check table of the field
with the foreign key. More specifically, when a foreign key check
field is populated, the <TT>select</TT> statement that was generated
by the SAP system when it defined the foreign key is sent by the
program. If the table returns a value from that selection, the
entry is valid. If the record is not found, the field input is
invalid.
<P>
The following code shows the syntax for a system-generated <TT>select</TT>
statement:
<BLOCKQUOTE>
<PRE>
select * from table_1 where table_1-exam1 = fk_exam1
and table_1-exam2 = fk_exam2.
</PRE>
</BLOCKQUOTE>
<P>
This bit of code shows an example of a system-generated <TT>select</TT>
statement that is called when data is entered into the field with
the foreign key definition. In this scenario, an entry in this
screen field is permitted only if the <TT>select</TT> statement
produces valid data from the check table using the data entries
made in fields <TT>fk_exam1</TT> and <TT>fk_exam2</TT> as keys.
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
One thing that you must keep in mind while creating foreign key relation-ships is the cardinality. The cardinality of a foreign key, together with its type, is referred to as the semantic attributes of the foreign key. Each cardinality of a foreign key of these entries is optional. The cardinality should not be overlooked, however, because the entry is good practice and becomes necessary when you want to create certain types of aggregates such as help views, for example.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
<I>Cardinality</I> is a description of the relationship between
one or more data elements to one or more of another data element.
If a foreign key linking two tables has been defined, the record
of the foreign key table refers to a record of the check table.
This reference is constructed by assigning fields of one table,
the foreign key table, to the primary key fields of the other
table, the check table.
<P>
The relationship exists only if the foreign key fields are of
the same data type and length as the corresponding primary key
fields. A check or parent table is the table that is referenced
by the foreign key itself. This is usually a <I>value</I> table,
but it can also be a table consisting of a subset of the contents
of a value table. A value table dictates the valid values that
are assigned to the data element's domain.
<P>
In some cases, a constant foreign key might best suit your needs.
This is the case when all valid entries in the input field contain
a specific value in the key field of the cited check table. Upon
the <TT>select</TT> statement's query, the constant field is checked
against the primary key field that contains the fixed value.<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>TIP</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
It is good programming practice to utilize naming conventions that are descriptive and user friendly. In addition, SAP has agreed never to begin the name of a development object with the letters <I>Z </I>or <I>Y</I>. If you create all your objects with names that begin with one of these two letters, you will ensure that you will have no trouble with name conflicts when you upgrade your SAP system.
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H2><A NAME="DataValidationUsingMatchcodes"><FONT SIZE=5 COLOR=#FF0000>
Data Validation Using Matchcodes</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
Another useful way to maintain data integrity during user input
is to use matchcodes. A <I>matchcode</I> 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.
<P>
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.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
A <I>data pool</I> 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.
<P>
A matchcode can be assembled in two different fashions:
<UL>
<LI><I>Physically.</I> 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.
<LI><I>Logically. </I>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.
</UL>
<P>
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 shown in Figure 21.2 and complete the following steps:
<P>
<A HREF="javascript:popUp('f21-2.gif')"><B>Figure 21.2 : </B><I>The initial screen of Data Dictionary</I>.</A>
<OL>
<LI>Enter a name for your new object, click on the Matchcode radio
button, and press the Create button.
<LI>Enter descriptive text as you enter your primary table on
the Attributes screen shown in Figure 21.3 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.<BR>
<A HREF="javascript:popUp('f21-3.gif')"><B>Figure 21.3 : </B><I>The Maintain Matchcode Object attributes
screen</I>.</A>
<LI>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 (see Figure 21.4).
<BR>
<A HREF="javascript:popUp('f21-4.gif')"><B>Figure 21.4 : </B><I>The Create Object Catalog Entry screen</I>.</A>
<LI>As the status bar reflects, the mandatory key fields are transferred
automatically (see Figure 21.5). 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.<BR>
<A HREF="javascript:popUp('f21-5.gif')"><B>Figure 21.5 : </B><I>The Maintain Matchcode Object (Fields)
screen</I>.</A>
<LI>The next step in the creation process is to activate the matchcode
object. The status of the object is New and Saved (see Figure
21.6).<BR>
<A HREF="javascript:popUp('f21-6.gif')"><B>Figure 21.6 : </B><I>The matchcode attributes prior to activation</I>.</A>
<LI>The status is now set to Active and Saved. Next you need to
create a matchcode ID or your object will be incomplete (see Figure
21.7). To do this, click the Matchcode IDs button.<BR>
<A HREF="javascript:popUp('f21-7.gif')"><B>Figure 21.7 : </B><I>The matchcode attributes after activation</I>.</A>
<LI>The system will prompt you to create a new ID if one does
not exist (see Figure 21.8). To do this, click on the Yes button.
<BR>
<A HREF="javascript:popUp('f21-8.gif')"><B>Figure 21.8 : </B><I>A prompt to Create Object</I>.</A>
<LI>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.<BR>
<A HREF="javascript:popUp('f21-9.gif')"><B>Figure 21.9 : </B><I>The Create Matchcode ID dialog box</I>.</A>
<LI>Let's view some possible entries (see Figure 21.10). 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.<BR>
<A HREF="javascript:popUp('f21-10.gif')"><B>Figure 21.10: </B><I>A Matchcode hit list</I>.</A>
<LI>Follow these steps we learned to maintain selection fields
for this matchcode ID, be sure to enter an Update type, and click
on Save (see Figure 21.11). 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.<BR>
<A HREF="javascript:popUp('f21-11.gif')"><B>Figure 21.11: </B><I>Maintenance of matchcode attributes</I>.</A>
<LI>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
<I>not</I> greater than the value of <TT>8888</TT> (see Figure
21.12). When finished, click Save and the green arrow to go back.
<BR>
<A HREF="javascript:popUp('f21-12.gif')"><B>Figure 21.12: </B><I>The Maintenance Selection Conditions dialog
box</I>.</A>
<LI>Now all you have to do is activate your matchcode ID and your
new object is ready to use (see Figure 21.13).<BR>
<A HREF="javascript:popUp('f21-13.gif')"><B>Figure 21.13: </B><I>Generate and use the matchcode</I>.</A>
</OL>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
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.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
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 <I>pool</I> 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:
<UL>
<LI>I-Arranged by the attributed database.
<LI>S-Arranged by the database interface.
<LI>A-Auto-arranged by the system program SAPMACO.
<LI>P-Arranged by an application program.
<LI>K-Also arranged by an application program.
</UL>
<H3><A NAME="SyntaxforUsingaMatchcode">
Syntax for Using a Matchcode</A></H3>
<P>
The following is the syntax for using matchcodes for selection
screen parameter input validation:
<BLOCKQUOTE>
<PRE>
tables: saptab
parameter: example like saptab-field matchcode object exam.
select single field from saptab where field = example.
</PRE>
</BLOCKQUOTE>
<P>
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.
<H2><A NAME="FormattingSelectionScreens"><FONT SIZE=5 COLOR=#FF0000>
Formatting Selection Screens</FONT></A></H2>
<P>
Now that you have explored some tools to validate input data in
ABAP/4, let's take some time to learn more about designing effective
selection screen formats. When defining input screens for the
use of reporting on data, various selection elements can be combined
to maintain data integrity and still be easy to use. These elements
include standard input fields such as selection options and parameters,
as well as others such as check boxes, radio buttons, and pushbuttons.
The following section will take a look at each of these individually
and give some examples of where they are best utilized. You will
get a chance to combine them in Exercise 1 at the end of the chapter.
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Reports that have Logical Database attached to them are assigned pre-designed selection screens. These selection criteria can be modified to best suit your needs. Reports that do not have the screens pre-defined must be maintained by the programmer of the report. These custom user interfaces can take on any form and combine any elements that you, the programmer, want.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H2><A NAME="UsingselectionscreenStatements"><FONT SIZE=5 COLOR=#FF0000>
Using selection-screen Statements</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
Selection screen elements can be combined into cohesive units
called <I>blocks</I>. These logical blocks are, in essence, a
cosmetic screen feature that encapsulates a combination of screen
input elements and can be created with a descriptive frame title.
Logical blocks help to make the selection options easier to understand
and use.
<H3><A NAME="Syntaxforselectionscreenblockwithframe">
Syntax for selection-screen block with frame</A></H3>
<P>
The following is the syntax for a <TT>selection-screen block</TT>
with <TT>frame</TT>:
<BLOCKQUOTE>
<PRE>
selection-screen begin of block block0 with frame title text-000.
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<P>
In addition to the <TT>block</TT> statement, selection screens
can be customized by utilizing formatting elements such as the
following <TT>selection-screen</TT> statements:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -