📄 ch04.htm
字号:
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>CA</TT></CENTER>
</TD><TD WIDTH=144><TT>Kanada</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>E</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>DE</TT></CENTER>
</TD><TD WIDTH=144><TT>Germany</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>DE</TT></CENTER>
</TD><TD WIDTH=144><TT>Deutschland</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>E</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>US</TT></CENTER>
</TD><TD WIDTH=144><TT>United States</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>US</TT></CENTER>
</TD><TD WIDTH=144><TT>USA</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>E</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>IT</TT></CENTER>
</TD><TD WIDTH=144><TT>Italy</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>IT</TT></CENTER>
</TD><TD WIDTH=144><TT>Italien</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>E</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>JP</TT></CENTER>
</TD><TD WIDTH=144><TT>Japan</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>JP</TT></CENTER>
</TD><TD WIDTH=144><TT>Japan</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>E</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>AQ</TT></CENTER>
</TD><TD WIDTH=144><TT>Antarctica</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER><TT>AQ</TT></CENTER>
</TD><TD WIDTH=144><TT>Antarctica</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>E</TT></CENTER></TD><TD WIDTH=144><CENTER>CC</CENTER>
</TD><TD WIDTH=144><TT>Coconut Islands</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>D</TT></CENTER></TD><TD WIDTH=144><CENTER>CC</CENTER>
</TD><TD WIDTH=144><TT>Kobinseln</TT></TD></TR>
</TABLE>
</CENTER>
<P>
<P>
<img src="../button/screencam.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/screencam.gif">
<P>
Start the ScreenCam "Text Table Demonstration: The Effect
of the Logon Language" now.
<OL>
<LI>Start transaction SE16 (type <TT><B>/nse16</B></TT>
in the Command field and press the Enter key).
<LI>Enter the table name <TT><B>ztxlfa1</B></TT>
in the Table Name field.
<LI>Press the Create Entries button on the Application toolbar.
<LI>Position your cursor on the Country Code field (<TT>land1</TT>).
<LI>Press the F4 key, or click the down-arrow at the end of the
field. A pop-up appears displaying columns from both tables <TT>ztxt005</TT>
and <TT>ztxt005t</TT>. Notice that the <TT>land1</TT> column from
table <TT>ztxt005</TT> is displayed and the English-language descriptions
from table <TT>ztxt005t</TT> are displayed.
<LI>Now log on again (you do not need to log off first). This
time, enter <TT><B>D</B></TT>
for Deutsche in the Language Field of the R/3 logon screen.
<LI>Repeat steps 1 through 5 in your new logon session.
<LI>Notice that this time the German descriptions from table <TT>ztxt005t</TT>
are displayed.
</OL>
<H5>Creating a Text Table and a Foreign Key for It</H5>
<BLOCKQUOTE>
Now is a good time to try creating your own text table. Use <TT>ztxt005t</TT>
as a model. Your text table will be named -<TT>t005t</TT>
and will contain the fields and use the data elements and domains
shown in Table 4.4. You will also have to create the data element
-<TT>landx</TT>. Use the existing
SAP domain <TT>text15</TT> for your new data element. An x in
the PK column indicates fields that form the primary key.<BR>
</BLOCKQUOTE>
<P>
<CENTER><B>Table 4.4 Fields and Their Characteristics
for Table -</B><TT><B>T005T</B></TT></CENTER><CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><B>Field Name</B></CENTER></TD><TD WIDTH=144><CENTER><B>PK</B></CENTER>
</TD><TD WIDTH=144><CENTER><B>DE Name</B></CENTER></TD><TD WIDTH=144><CENTER><B>DM Name</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>mandt</TT></CENTER></TD><TD WIDTH=144><CENTER>x</CENTER>
</TD><TD WIDTH=144><CENTER><TT>mandt</TT></CENTER></TD><TD WIDTH=144><CENTER> </CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>spras</TT></CENTER></TD><TD WIDTH=144><CENTER>x</CENTER>
</TD><TD WIDTH=144><CENTER><TT>spras</TT></CENTER></TD><TD WIDTH=144><CENTER> </CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>land1</TT></CENTER></TD><TD WIDTH=144><CENTER>x</CENTER>
</TD><TD WIDTH=144><CENTER>-<TT>land1</TT></CENTER>
</TD><TD WIDTH=144><CENTER> </CENTER></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><TT>landx</TT></CENTER></TD><TD WIDTH=144><CENTER> </CENTER>
</TD><TD WIDTH=144><CENTER>-<TT>landx</TT></CENTER>
</TD><TD WIDTH=144><CENTER><TT>text15</TT></CENTER></TD></TR>
</TABLE>
</CENTER>
<P>
<P>
<blockquote>
After activating -<TT>t005t</TT>,
enter data into it using SE16. Use the sample data shown in Table
4.3.
<P>
Now create a foreign key on -<TT>t005t-land1</TT>.
Follow the foreign key creation procedure previously given. Use
-<TT>t005</TT> as the check table.
On the Create Foreign Key screen, specify a foreign key field
type of Key fields of a text table. You might want to review the
screencam "How to Create a Foreign Key" before beginning.
<P>
After creating your foreign key, follow the procedure for testing
the foreign key relationship on -<TT>lfa1-land1</TT>.
In step 11, notice that the description from <TT>ztxt005t</TT>
is also displayed. Also, log on again, this time specifying a
logon language of <TT>D</TT> (German), and repeat the test. This
time you should see the German descriptions in step 11.
</blockquote>
<H3><A NAME="GenericandConstantForeignKeys">
Generic and Constant Foreign Keys</A></H3>
<P>
Recall that when you create a foreign key, all of the primary
key fields of the check table must be included in the foreign
key relationship. However at times, you may not want to perform
a check against all of these fields. In other situations, you
may wish to check against a constant value. In either of these
cases, you can define either a generic or constant foreign key.
<H4>Generic Foreign Keys</H4>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
A <I>generic foreign key</I> is a foreign key in which one of
the primary key fields of the check table fields is marked as
generic. When a primary key field is marked as generic, it doesn't
have a counterpart in the foreign key table, and it does not participate
in the check.
<P>
For example, within the Materials Management application, the
<TT>mara</TT> table is the Material Master table. It contains
the master list of materials used for manufacture and the attributes
of each material.
<P>
The setup program for this book created a <TT>ztxmara</TT> table
similar to <TT>mara</TT>. The fields of <TT>ztxmara</TT> are shown
in Figure 4.8.
<P>
<A HREF="javascript:popUp('f4-8.gif')"><B>Figure 4.8 :</B> <I>Table ztxmara is similar to the R/3 Material
Master table mara</I>.</A>
<P>
The <TT>ztxmara-stoff</TT> field contains a hazardous material
number. If the field is non-blank, the material requires special
handling; the <TT>stoff</TT> number indicates the type of handling
required. The handling numbers are defined in table <TT>ztxmgef</TT>,
which is illustrated in Figure 4.9. In our example, assume <TT>ztxmgef</TT>
contains a row with <TT>stoff</TT> equal 1. That row indicates
a handling procedure that requires gloves. Updating a material
and placing a 1 in the <TT>ztxmara-stoff</TT> field for the material
indicates that the material requires special handling with gloves.
<P>
<A HREF="javascript:popUp('f4-9.gif')"><B>Figure 4.9 :</B><I>The ztxmara and
ztxmgef tables relate via the stoff field</I>.</A>
<P>
The check table for <TT>ztxmara-stoff</TT> is <TT>ztxmgef</TT>.
The foreign key definition is shown in Figure 4.10.
<P>
<A HREF="javascript:popUp('f4-10.gif')"><B>Figure 4.10:</B> <I>A tickmark in the Generic check box causes
a field to be ignored during the foreign key check</I>.</A>
<P>
This foreign key validates the values entered into <TT>ztxmara-stoff</TT>
and ensures that only valid handling numbers exist in the <TT>ztxmara</TT>
table. Unfortunately, handling regulations can vary with geographical
regions. Therefore, the primary key of <TT>ztxmgef</TT> is composed
of <TT>stoff</TT>, <TT>regio</TT>, and <TT>land1</TT>. However,
<TT>ztxmara</TT> doesn't contain any geographical information
- that information is contained in plant tables.
<P>
Remember, a foreign key must include all primary key fields from
the check table. Therefore, <TT>regio</TT> and <TT>land1</TT>
from <TT>ztxmgef</TT> appear in the foreign key definition. However,
for the purposes of <TT>ztxmara</TT>, validating <TT>ztxmara-stoff</TT>
against <TT>ztxmgef-stoff</TT> is good enough; location information
doesn't exist in <TT>ztxmara</TT> and doesn't matter for this
validation. It is enough to know that the specified special handling
number exists.
<P>
In this foreign key relationship, the <TT>regio</TT> and <TT>land1</TT>
fields in the primary key of <TT>ztxmgef</TT> are be ignored.
To cause these fields to be ignored during validation, they are
defined in the foreign key relationship as <I>generic</I>. The
tickmark in the Generic check box on the Create Foreign Key screen
accomplishes this.
<P>
When this foreign key is checked, only the combination of <TT>mandt</TT>
and <TT>stoff</TT> must exist in the check table. The <TT>regio</TT>
and <TT>land1</TT> fields are ignored.
<H4>Constant Foreign Keys</H4>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
<I>Constant foreign keys</I> are compound foreign keys where one
of the check table field names is replaced by a constant value.
This constant value is entered on the Create Foreign Key screen
(see Figure 4.11).
<P>
<A HREF="javascript:popUp('f4-11.gif')"><B>Figure 4.11:</B> <I>The country field as a constant foreign
key</I>.</A>
<P>
For example, assume you need to create a new vendor table <TT>ztxlfa1us</TT>
like <TT>ztxlfa1</TT> containing U.S. vendors only, but for compatibility
reasons, you want it to have exactly the same structure as <TT>ztxlfa1</TT>.
The country code in this table would always be <TT>US</TT>. You
could create a constant foreign key to restrict the values in
table <TT>ztxlfa1us</TT>. An example of the definition is shown
in Figure 4.11.
<H3><A NAME="AdaptedForeignKeys">
Adapted Foreign Keys</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
Foreign key fields of a compound foreign key do not all have to
reside in the same table. If they do not, this is known as an
<I>adapted foreign key</I>. For example, assume that the country
code for the vendor is not stored at all in <TT>ztxlfa1</TT>,
but instead in <TT>ztxlfa1cc</TT>. When you create the foreign
key on the region field, you would change the check table field
for <TT>land1</TT> to <TT>ztxlfa1cc-land1</TT> (see Figure 4.12).
The validation on the <TT>regio</TT> field would check to see
whether the combination of <TT>mandt</TT> and <TT>regio</TT> existed
in <TT>ztxt005s</TT> and whether <TT>land1</TT> existed in any
row of <TT>ztxt005cc</TT>.
<P>
<A HREF="javascript:popUp('f4-12.gif')"><B>Figure 4.12:</B> <I>An example of an adapted foreign key</I>.</A>
<H3><A NAME="DefiningaValueTable">
Defining a Value Table</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
Within the domain is the <I>Value Table</I> field. The table named
within this field provides the following functions to the domain:
<UL>
<LI>It is automatically proposed as the check table when creating
a foreign key
<LI>It provides a list of values for F4 (possible entries) help,
but it does not provide validation
</UL>
<P>
Whenever you create a foreign key relationship, the system looks
in the value table field. If there is a table name there, it proposes
that name as the check table.
<P>
Some readers will have difficulty with this concept, so I will
explain it in depth in the following section.
<H4>Understanding the Value Table Field</H4>
<P>
In order to understand the purpose of the Value Table field, you
should be familiar with the "bigger picture" of database
design and development. I will begin by describing this bigger
picture.
<P>
Before you create any tables in the DDIC, you usually do some
database design. This design describes the tables that will be
created, their relationships, and the type of data that each will
contain. It will usually designate certain tables to be check
tables for validating the data within other tables. For example,
a country code check table may be needed to validate country codes
for all of the tables where country codes will be stored. When
you create a set of tables within R/3, you will usually create
the check tables first.
<P>
When you create a check table, it exists for one primary purpose:
to validate data. You can create multiple foreign key relationships
linking many other tables to a single check table. The Value Table
field in the domain exists to simplify the task of creating these
relationships.
<P>
Before I continue, I want you to imagine that the Value Table
field within the domain has a completely different name. Wipe
the term "Value Table" from your mind, and imagine that
field is called the "Default Check Table" field.
<P>
To simplify the example, our check table will have a single primary
key field, illustrated in Figure 4.13. To illustrate this concept,
I will describe the process you would go through to create this
check table and use it in a foreign key relationship.
<P>
<A HREF="javascript:popUp('f4-13.gif')"><B>Figure 4.13:</B> <I>The Value Table field within the domain
contains the name of a check table</I>.</A>
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -