⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch04.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
If you have trouble, refer to the troubleshooter for the transparent
table creation procedure for pre-existing domains and data elements
on Day 3.
<P>
<img src="../button/screencam.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/screencam.gif">
<P>
Start the ScreenCam &quot;How to Create Check Table -<TT>t005</TT>&quot;
now.
<P>
To create your check table:
<OL>
<LI>Begin at the Dictionary: Initial Screen.
<LI>Type the table name in the Object Name field.
<LI>Choose the Tables radio button.
<LI>Press the Create button. The Dictionary: Table/Structure:
Change Fields screen is displayed.
<LI>Type a short text, choose delivery class A, and tickmark Tab.
Maint. Allowed.
<LI>Type the field and data element names at the bottom of the
screen.
<LI>Tickmark both fields to indicate that they both form the primary
key.
<LI>Press the Save button on the Standard toolbar. The Create
Object Catalog Entry screen appears.
<LI>Press the Local Object button. You are returned to the Dictionary:
Table/Structure: Change Fields screen.
<LI>Press the Technical Settings button on the Application toolbar.
The ABAP/4 Dictionary: Maintain Technical Settings screen is displayed.
<LI>In the Data Class field, enter <TT>APPL0</TT> (APPL0 with
a <I>zero</I>, not APPLO with an alphabetic <I>O</I>).
<LI>Enter <TT><B>0</B></TT> (zero)
in the Size Category field.
<LI>Press the Save button.
<LI>Press the Back button. You are returned to the Dictionary:
Table/Structure: Change Fields screen.
<LI>Press the Activate button on the Application toolbar. The
message &quot;was activated&quot; appears in the status bar and
the Status field contains the value <TT>Act.</TT>.
</OL>
<P>
Choose the menu path Utilities-&gt;Create Entries to enter data
into your newly created check table. Enter six rows with <TT>land1</TT>
values of <TT>US</TT>, <TT>CA</TT>, <TT>DE</TT>, <TT>IT</TT>,
<TT>JP</TT>, and <TT>AU</TT>.
<H4>Foreign Key Creation Procedure</H4>
<P>
<img src="../button/screencam.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/screencam.gif">
<P>
Start the ScreenCam &quot;How to Create a Foreign Key&quot; now.
<P>
To create a foreign key:
<OL>
<LI>Begin at the Dictionary: Initial Screen.
<LI>In the Object Name field, type the name of the table that
is to contain the foreign key (-<TT><B>lfa1</B></TT>).
<LI>Choose the Tables radio button.
<LI>Press the Change button. The Dictionary: Table/Structure:
Change Fields screen is displayed.
<LI>Position your cursor on the field that is to become the foreign
key (<TT>land1</TT>).
<LI>Press the Foreign Keys button on the Application toolbar.
The Create Foreign Key screen will be displayed (see Figure 4.3).
<LI>Type a description of the foreign key in the Short Text field,
for example, <TT><B>Country Code validation</B></TT>.
<LI>Type the name of the check table (-<TT><B>t005</B></TT>)
in the Check Table field, or click on the down-arrow and choose
it from the list.
<LI>The Change Foreign Key pop-up appears. It states <TT>Check
table name was created or changed. Generate a proposal for field
assignment?</TT> Press the Yes button.
<LI>You are returned to the Create Foreign Key screen. The check
table field names and the foreign key field names are displayed.
(The check table field names are -<TT>t005-mandt</TT>
and -<TT>t005-land1</TT>. The foreign
key field names are -<TT>lfa1-mandt</TT>
and -<TT>lfa1-land1</TT>).
<LI>Press the Copy button. You are returned to the Dictionary:
Table/Structure: Change Fields screen and the message &quot;Foreign
key was transferred&quot; appears in the status bar. The Status
fields contain the values <TT>Revised</TT> and <TT>Not saved</TT>.
<LI>Press the Activate button on the Application toolbar. The
message &quot;was activated&quot; appears in the status bar. The
values in the Status fields are now <TT>Act.</TT> and <TT>Saved</TT>.
</OL>
<P>
<A HREF="javascript:popUp('f4-3.gif')"><B>Figure 4.3: </B><I>The Create Foreign
Key screen displays check table fields and their associated foreign
key fields</I>.</A>
<P>
You have just created a foreign key relationship between the -<TT>lfa1</TT>
and -<TT>t005</TT> tables. -<TT>lfa1-land1</TT>
is the foreign key field, and -<TT>t005</TT>
is the check table. The user interface will validate the value
within the -<TT>lfa1-land1</TT> field
against the values in the -<TT>t005-land1</TT>
column.
<H4>Testing the Foreign Key Relationship</H4>
<P>
If you encounter problems, the following procedure is described
in more detail in the next section. To test your foreign key:
<OL>
<LI>Begin on the Dictionary: Table/Structure screen (either change
or display mode).
<LI>Choose the menu path Utilities-&gt;Create entries.
<LI>Type a value into the foreign key field (Country Code).
<LI>Press the Enter key. If the value is not found in the check
table, the message &quot;Entry does not exist (please check your
entry)&quot; is displayed.
</OL>
<H3><A NAME="DiscoveringtheCheckTableColumn">
Discovering the CheckTable Column</A></H3>
<P>
After you have created a foreign key, the name of the check table
appears in the CheckTable column on the Dictionary: Table/Structure
screen. If a field is a foreign key, the CheckTable column will
contain the name of the check table for that field.
<P>
Look at your table now. You should see the name of your check
table in the CheckTable column. 
<H3><A NAME="AutomaticDeterminationofForeignKeyFields">
Automatic Determination of Foreign Key Fields</A></H3>
<P>
When you created the foreign key, you did not have to specify
the fields that should participate in the foreign key relationship-the
system determined it automatically. This section explains how
the system determines these field names.
<P>
During the creation of a foreign key, you put your cursor on the
foreign key field and pressed the foreign key button, and the
system generated a foreign key proposal consisting of pairs of
fields. In each pair, one field comes from the check table and
the other from the foreign key table. The number of pairs is equal
to the number of primary key fields of the check table. All of
the primary key fields of the check table must be included in
the foreign key relationship.
<P>
The system searches these primary key fields for the one that
has the <I>same domain</I> as the foreign key field, and pairs
it with your foreign key field.
<P>
If there are multiple fields in the primary key of the check table,
it will try to find a match for each of the remaining fields.
One by one, the system will try to find a field in the foreign
key table that has the same domain as the check table field. Failing
that, it will try to find a field that has the same data type
and length. If it finds more than one match, the system picks
one and warns you that the assignment is ambiguous. The process
is repeated until all primary key fields from the check table
have been paired with a field from the foreign key table.
<H3><A NAME="RelatingForeignKeystotheDownArrowandFHelp">
Relating Foreign Keys to the Down-Arrow and F4 Help</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
In addition to F1 help, you can also provide something called
<I>F4 help</I> to the user. F4 help is a list of valid values
that the user can enter into a field. In order to obtain F4 help,
the user positions their cursor in a field and presses the F4
key. F4 help is also known as <I>possible entries help</I> because
it is the list of possible entries allowed in the field. Both
terms are used interchangeably by SAP.
<P>
When you create a foreign key, F4 help is automatically provided
for that field.
<P>
<img src="../button/screencam.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/screencam.gif">
<P>
Start the ScreenCam &quot;Using a Foreign Key to Provide F4 Help&quot;
now.
<P>
On a screen, if you place your cursor within a foreign key field,
a down-arrow will appear at the end of the input field. This is
the F4 help. If you click the down-arrow or press the F4 key,
a list of possible, valid entries is displayed. This list is the
contents of the check table. In this list, the primary key columns
of the check table are displayed, excluding <TT>mandt</TT>.<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 column heading and width in the possible entries list come from the Header field in the data element for the check table field displayed.</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Follow this procedure to test the foreign key relationship you
created on -<TT>lfa1-land1</TT>.
If your foreign key doesn't work, try this procedure using <TT>ztxlfa1</TT>,
then compare <TT>ztxlfa1</TT> with your table to determine the
problem.
<OL>
<LI>Begin on any screen.
<LI>In the Command field, type <TT><B>/nse16</B></TT>.
<LI>Press the Enter key. The Data Browser: Initial Screen is displayed.
<LI>Type -<TT><B>lfa1</B></TT>
in the Table Name field.
<LI>Press the Create Entries button on the Application toolbar.
The Table Insert screen is displayed.
<LI>Type any value in the vendor number field, for example, <TT><B>MY-V1</B></TT>.
<LI>Position your cursor on the Country Code field (<TT>land1</TT>).
Although a down-arrow appears at the end of it, do not press it
just yet.
<LI>Type the value <TT><B>XX</B></TT>
in the Country Code field.
<LI>Press the Save button on the Standard toolbar. The message
&quot;Entry XX does not exist (please check your entry)&quot;
appears.<BR>
Your cursor is positioned at the beginning of the field that contains
the incorrect value. A down-arrow appears at the end of the field.
<LI>Click the down-arrow or press the F4 key. A pop-up containing
the primary key columns of check table -<TT>t005</TT>
appears.
<LI>Double-click <TT>US</TT>. The pop-up disappears and the value
in the country code field changes to <TT>US</TT>.
<LI>Press the Save button on the Standard toolbar. The message
&quot;Database record successfully created&quot; appears in the
status bar.
</OL>
<P>
The foreign key relationship provides a mechanism for validating
data entered by the user on the screen. If the field is a foreign
key field, the value is compared against the check table. If the
value doesn't exist in the check table, a standard error message
is issued.
<H3><A NAME="ForeignKeysandBatchPrograms">
Foreign Keys and Batch Programs</A></H3>
<P>
Batch programs that read sequential files or other sources of
data other than the screen and update the database directly must
validate the data. Such a program should be coded in one of three
ways:
<UL>
<LI>It should pass the data through a user interface by calling
a transaction containing screens. This is done entirely in the
background. The data is automatically &quot;keyed&quot; into the
screen fields to cause the foreign key check to be done. This
technique is called <I>BDC</I> (<I>Batch Data Communications</I>),
and was mentioned earlier in the &quot;Forays into Foreign Keys&quot;
section. BDC is the standard technique used to import data into
the R/3 system.
<LI>It can contain <TT>select</TT> statements that perform the
foreign key checking. This technique is less reliable because
the programs must be updated if new foreign keys are added or
if existing ones change.
<LI>It can pass the data to special function modules that perform
both foreign key checking and database updates. SAP creates these
function modules (called BAPIs, or Business APIs) and supplies
them with the R/3 system.
</UL>
<H3><A NAME="CompoundForeignKeys">
Compound Foreign Keys</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
A <I>compound foreign key</I> is a foreign key composed of two
or more fields. In other words, a check is done to compare two
fields in the foreign key table against two fields in the check
table. The combination of values must exist in the check table
before they can be inserted into the foreign key table. However
only one field on the screen will trigger the compound foreign
key check.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
When you create a compound foreign key, the field on which you
actually define the foreign key is called the <I>check field</I>.
Only a non-blank value in the check field triggers the check against
the check table. A value in any of the other fields within the
compound foreign key will not trigger the validation.
<P>
For example, the <TT>regio</TT> field in <TT>ztxlfa1</TT> should
only contain valid state or province codes. The combination of

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -