📄 ch04.htm
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function popUp(pPage) {
popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
figDoc= popUpWin.document;
zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
zhtm += '</head>';
zhtm += '<BODY bgcolor="#FFFFFF">';
zhtm += '<IMG SRC="' + pPage + '">';
zhtm += '<P><B>' + pPage + '</B>';
zhtm += '</BODY></HTML>';
figDoc.write(zhtm);
figDoc.close();
popUpWin.focus();
}
//-->
</SCRIPT>
<META NAME="GENERATOR" Content="Symantec Visual Page 1.0.1">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<TITLE>Sams Teach Yourself ABAP/4® in 21 Days -- Day 4- The Data Dictionary, Part 2</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<CENTER>
<H1><IMG SRC="../button/sams.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/sams.gif" BORDER="0"></H1>
</CENTER>
<CENTER>
<P><A HREF="../ch03/ch03.htm" tppabs="http://ebooks.cs.biu.ac.il/0672312174/ch03/ch03.htm"><IMG SRC="../button/previous.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/previous.gif" BORDER="0"></A>
<A HREF="../index.htm" tppabs="http://ebooks.cs.biu.ac.il/0672312174/index.htm"><IMG SRC="../button/contents.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/contents.gif" BORDER="0"></A>
<A HREF="../ch05/ch05.htm" tppabs="http://ebooks.cs.biu.ac.il/0672312174/ch05/ch05.htm"><IMG SRC="../button/next.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/next.gif" BORDER="0"></A>
<H1>Sams Teach Yourself ABAP/4<sup>®</sup> in 21 Days</H1></CENTER>
<HR SIZE=4>
<H1>Day 4</H1>
<H1>The Data Dictionary, Part 2</H1>
<UL>
<LI><A HREF="#ChapterObjectives">
Chapter Objectives</A>
<LI><A HREF="#DiscoveringForeignKeys">
Discovering Foreign Keys</A>
<UL>
<LI><A HREF="#TriggeringtheForeignKeyCheck">
Triggering the Foreign Key Check</A>
<LI><A HREF="#TechnicalRequirementsforCreatingaForeignKey">
Technical Requirements for Creating a Foreign Key</A>
<LI><A HREF="#CreatingaForeignKey">
Creating a Foreign Key</A>
<LI><A HREF="#DiscoveringtheCheckTableColumn">
Discovering the CheckTable Column</A>
<LI><A HREF="#AutomaticDeterminationofForeignKeyFields">
Automatic Determination of Foreign Key Fields</A>
<LI><A HREF="#RelatingForeignKeystotheDownArrowandFHelp">
Relating Foreign Keys to the Down-Arrow and F4 Help</A>
<LI><A HREF="#ForeignKeysandBatchPrograms">
Foreign Keys and Batch Programs</A>
<LI><A HREF="#CompoundForeignKeys">
Compound Foreign Keys</A>
<LI><A HREF="#UnderstandingCardinality">
Understanding Cardinality</A>
<LI><A HREF="#ForeignKeyFieldType">
Foreign Key Field Type</A>
<LI><A HREF="#GenericandConstantForeignKeys">
Generic and Constant Foreign Keys</A>
<LI><A HREF="#AdaptedForeignKeys">
Adapted Foreign Keys</A>
<LI><A HREF="#DefiningaValueTable">
Defining a Value Table</A>
</UL>
<LI><A HREF="#SpecialTableFields">
Special Table Fields</A>
<UL>
<LI><A HREF="#CurrencyFields">
Currency Fields</A>
<LI><A HREF="#QuantityFields">
Quantity Fields</A>
</UL>
<LI><A HREF="#StructuresintheDataDictionary">
Structures in the Data Dictionary</A>
<UL>
<LI><A HREF="#UnderstandingIncludes">
Understanding Includes</A>
<LI><A HREF="#IncludingtheSameStructureMultipleTimes">
Including the Same Structure Multiple Times</A>
</UL>
<LI><A HREF="#Summary">
Summary</A>
<LI><A HREF="#QampA">
Q&A</A>
<LI><A HREF="#Workshop">
Workshop</A>
<UL>
<LI><A HREF="#Quiz">
Quiz</A>
<LI><A HREF="#Exercise1">
Exercise 1</A>
<LI><A HREF="#Exercise2">
Exercise 2</A>
<LI><A HREF="#Exercise3">
Exercise 3</A>
<LI><A HREF="#Exercise4">
Exercise 4</A>
<LI><A HREF="#Exercise5">
Exercise 5</A>
<LI><A HREF="#Exercise6">
Exercise 6</A>
<LI><A HREF="#Exercise7">
Exercise 7</A>
</UL></UL>
<HR>
<H2><A NAME="ChapterObjectives"><FONT SIZE=5 COLOR=#FF0000>
Chapter Objectives</FONT></A></H2>
<P>
After you complete this chapter, you will be able to:
<UL>
<LI>Create foreign keys.
<LI>Use the Value Table field in the domain.
<LI>Create and use text tables.
<LI>Describe the difference between a structure and a table, and
create <BR>
structures in the R/3 Data Dictionary.
<LI>Create tables and structures containing currency and quantity
fields.
<LI>Nest structures within other structures or tables.
</UL>
<H2><A NAME="DiscoveringForeignKeys"><FONT SIZE=5 COLOR=#FF0000>
Discovering Foreign Keys</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
A <I>foreign key</I> is a field in a table that is connected to
another table via a foreign key relationship. The purpose of the
foreign key relationship is to validate the data being entered
into one table by checking against a valid set of values in another
table. The table that contains the foreign key is called the <I>foreign
key table</I>. The table that contains the valid set of values
is called the <I>check table</I> (see Figure 4.1). The field that
is validated and on which the foreign key relationship is created
is called the foreign key.
<P>
<A HREF="javascript:popUp('f4-1.gif')"><B>Figure 4.1 : </B><I>The foreign key table and the check table</I>.</A>
<P>
For example, your -<TT>lfa1</TT>
table contains country codes in a field named <TT>land1</TT>.
You can create a second table, for example -<TT>t005</TT>,
and fill it with a list of valid country codes. Then, if you create
a foreign key like the one shown in Figure 4.1, a check will automatically
be done against the check table for a valid value. With such a
foreign key in place, the user cannot insert invalid country codes
into table -<TT>lfa1</TT>.
<P>
A foreign key gets its name from the fact that it must always
check against a field in the primary key of another table.
<H3><A NAME="TriggeringtheForeignKeyCheck">
Triggering the Foreign Key Check</A></H3>
<P>
Foreign key checking is performed by the R/3 user<I> </I>interface.
When you type a value into a field and press the Enter key, behind
the scenes the user interface formulates a <TT>select</TT> statement
to validate the foreign key field and sends it to the database.
If a matching row is not found in the check table, the user sees
a standard message indicating that the value he entered is invalid.
If a matching row exists in the check table, the values entered
on the screen are allowed to pass to the underlying ABAP/4 program.
Thus, the foreign keys are already checked before the program
receives the values. In addition to the Enter key, foreign keys
are also checked when a function key, a pushbutton, or a menu
item is selected.
<P>
Foreign keys are checked by the user interface only. They <I>do
not</I> exist in the database, and they are not checked if you
merely issue a database <TT>update</TT> statement. No referential
integrity constraints are kept in the database. Therefore, an
incorrectly written ABAP/4 program can violate referential integrity;
it can insert invalid values into database tables. For that reason,
ABAP/4 programs that need to update the database with data that
comes from a source other than the user interface usually pass
that data through a user interface in order to validate it. <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>
For more information on using the user interface to validate data, refer to the R/3 Library help for BDC (Batch Data Communication) programs. To view this documentation, from any screen choose the menu path Help->R/3 Library. You will see the main menu of the R/3 library. From there, click on the following tabs: Basis Components->ABAP/4 Development Workbench-> Basis Programming Interfaces->Transferring Data With Batch Input.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="TechnicalRequirementsforCreatingaForeignKey">
Technical Requirements for Creating a Foreign Key</A></H3>
<P>
To create a foreign key:
<UL>
<LI>The check must occur against a field within the primary key
of the check table.
<LI>The domain names for the foreign key field and the check table
field must be the same.
</UL>
<P>
The second requirement exists to make sure that the fields being
compared are compatible in data type and length (see Figure 4.2).
<P>
<A HREF="javascript:popUp('f4-2.gif')"><B>Figure 4.2 : </B><I>This is a diagram of the foreign key field,
check table field, and the common domain they share</I>.</A><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>
In Figure 4.2, both fields use the same data element as well as the same domain. Notice that it is not required that they both use the same data element-only the domains must be the same.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Because these fields share a common domain, the integrity of the
comparison between the two fields is guaranteed because their
data types and lengths will always match.<BR>
<H3><A NAME="CreatingaForeignKey">
Creating a Foreign Key</A></H3>
<P>
Now it is time for you to create a simple foreign key. This example
will enable you to become familiar with the screens involved in
this process; all of the fields in those screens will be explained
in detail later in this chapter. The following procedures demonstrate
how create check table <TT>ztxt005</TT>, and then a foreign key
on <TT>ztxlfa1-land1</TT> by using <TT>ztxt005</TT> as the check
table. After viewing this procedure, you will be asked to create
your own -<TT>t005</TT> table and
then create a foreign key relationship from -<TT>lfa1-land1</TT>
to check table -<TT>t005</TT>.
<P>
Before you create a foreign key, you must first have a check table.
Although there is already a country code table in R/3, for practice
you will create and use your own. The check table will be named
-<TT>t005</TT> and will contain the
fields and use the data elements shown in Table 4.1. (An x in
the PK column indicates fields that form the primary key.)<BR>
<P>
<CENTER><B>Table 4.1 The Fields and Their Characteristics
for Table -</B><TT><B>T005</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></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></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></TR>
</TABLE>
</CENTER>
<P>
<H4>Check Table Creation Procedure</H4>
<P>
Following is the creation procedure for check table -<TT>t005</TT>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -