📄 ch21.htm
字号:
if ( p_ex1 = 'X' ) and
( ( p_jdate1 = 'IEQ?' ) or ( p_jdate1 is initial ) ).
message E017 with 'Selection Option with Default field has no value'.
elseif ( p_ex1 = 'X' ) and
not ( ( p_jdate1 = 'IEQ?' ) or ( p_jdate1 is initial ) ).
message I017 with 'We are now using Example 1'.
endif.
if ( p_ex2 = 'X' ) and
( ( s_jdate2 = 'IEQ?' ) or ( s_jdate2 is initial ) ).
message E017 with 'Selection Option using for field has no value'.
elseif ( p_ex2 = 'X' ) and
not ( ( s_jdate2 = 'IEQ?' ) or ( s_jdate2 is initial ) ).
message I017 with 'And now Example 2 is selected'.
endif.
if ( p_ex3 = 'X' ) and
( ( p_jdate3 = 'IEQ?' ) or ( p_jdate3 is initial ) ).
message E017 with 'Parameter w/ like statement field has no value'.
elseif ( p_ex3 = 'X' ) and
not ( ( p_jdate3 = 'IEQ?' ) or ( p_jdate3 is initial ) ).
message I017 with 'We are now using Example 3'.
endif.
if ( p_ex4 = 'X' ) and
( ( s_jdate4 = 'IEQ?' ) or ( s_jdate4 is initial ) ).
message E017 with 'Selection Option with no interval has no value'.
elseif ( p_ex4 = 'X' ) and
not ( ( s_jdate4 = 'IEQ?' ) or ( s_jdate4 is initial ) ).
message I017 with 'We are now using Example 4'.
endif.
if p_ex5 = 'X'.
perform get_price_data.
else.
message I017 with 'No Pricing Data selected'.
endif.
if p_ex6 = 'X'.
perform get_cost_data.
else.
message I017 with 'No Costing Data selected'.
endif.
if p_ex7 = 'X'.
perform get_revenue_data.
else.
message I017 with 'No Revenue Data selected'.
endif.
form get_cost_data.
...
endform.
form get_revenue_data.
...
endform.
form get_price_data.
...
endform.
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<P>
Because radio buttons are mutually exclusive, it is a good idea
to keep them all in the same processing block on the selection
screen. Notice, in Figure 21.18, how each group of field elements
has been isolated to contain only those fields that are relevant
to that decision block.
<P>
<A HREF="javascript:popUp('f21-18.gif')"><B>Figure 21.18: </B><I>Selection screen with relevant decision
block</I>.</A>
<P>
As you can see in Figure 21.19, it is harder to follow the requested
data fields when they are not grouped into selection screen blocks.
<P>
<A HREF="javascript:popUp('f21-19.gif')"><B>Figure 21.19: </B><I>Selection screen without blocks</I>.</A>
<P>
Parameters that are defined with the <TT>like</TT> clause will
appear with a down arrow, which can be clicked to view a list
window of valid values (see Figure 21.20).
<P>
<A HREF="javascript:popUp('f21-20.gif')"><B>Figure 21.20: </B><I>Parameters and the down-arrow request</I>.</A>
<P>
We can now click on our selection push the green check button.
(see Figure 21.21). This will populate this parameter field with
the value that you selected. This can be very helpful for helping
a user become more familiar with your selection requirements.
<P>
<A HREF="javascript:popUp('f21-21.gif')"><B>Figure 21.21: </B><I>Choose a valid value</I>.</A>
<P>
When you create a <TT>select-option</TT> without using the <TT>no-extension</TT>
clause, you have the ability to enter multiple selections or a
range of selections. To enter multiple selections or range of
selections, simply click on the white arrow button (see Figure
21.22).
<P>
<A HREF="javascript:popUp('f21-22.gif')"><B>Figure 21.22: </B><I>Selection options with Extension</I>.</A>
<P>
At this point, you can enter all of your selection criteria and
click on the Copy button (see Figure 21.23).
<P>
<A HREF="javascript:popUp('f21-23.gif')"><B>Figure 21.23: </B><I>Enter your selection requirements</I>.</A>
<P>
As you can see, the arrow changes color, and is now green (see
Figure 21.24). This reflects the fact that you have selected multiple
selections for this field and these inputs will populate a selection
table at runtime.
<P>
<A HREF="javascript:popUp('f21-24.gif')"><B>Figure 21.24: </B><I>Selection screen with green arrow enabled</I>.</A>
<P>
If you use the <TT>no-extensions</TT> and the <TT>no-intervals</TT>
clauses in the <TT>select-options</TT> statement, you will get
an input field that acts similar to a parameter field, complete
with a down arrow key for viewing valid entries (see Figure 21.25).
<P>
<A HREF="javascript:popUp('f21-25.gif')"><B>Figure 21.25: </B><I>Selection screen without extension or
intervals</I>.</A>
<P>
Be careful using default values for <TT>select-option</TT> fields.
As you can see in Figure 21.26, if you populate a <TT>select-option</TT>
field with a default value, the field will not allow you to view
valid entries.
<P>
<A HREF="javascript:popUp('f21-26.gif')"><B>Figure 21.26: </B><I>select-option with default value</I>.</A>
<P>
The following screen shows an example of a data validation routine
that utilizes an information message in the form of a pop-up window
that is merely informative and just pauses the program. This is
best used to communicate status of events in the processing of
data (see Figure 21.27).
<P>
<A HREF="javascript:popUp('f21-27.gif')"><B>Figure 21.27: </B><I>Pop-up message used for data validation</I>.</A>
<P>
You can also utilize the error type of a message text. This type
of message will append the program and issue a text message to
the status bar. This is used primarily to validate data upon initial
entry (see Figure 21.28).
<P>
<A HREF="javascript:popUp('f21-28.gif')"><B>Figure 21.28: </B><I>Error messages on status bar</I>.</A>
<P>
This example shows many elements of selection screens combined
in an efficient and simple format. Please have a look at the code
that created this selection screen in the paragraphs preceding
this visual walkthrough.<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=288><CENTER><B>DO</B></CENTER></TD><TD WIDTH=288><CENTER><B>DON'T</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=288><B>DO</B> remember to utilize the selection screen elements for the tasks that best suit them.
<P>
<B>DO </B>design your selection screens to fit your data input requirements in a way that is easy to follow for the user.
</TD><TD WIDTH=288><B>DON'T </B>forget to include well-thought-out data-validation routines that utilize ABAP/4's event capabilities.
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
As mentioned in this last example, it is good practice to use
message statements as input validation warnings at runtime.
<H2><A NAME="UsingtheMessageStatement"><FONT SIZE=5 COLOR=#FF0000>
Using the Message Statement</FONT></A></H2>
<P>
Messages are maintained and stored in the <TT>T100</TT> table
and can be accessed from the ABAP Workbench. An effective programmer
issues messages that are descriptive and help the user understand
the nature of the program flow.
<P>
Each individual message statement can be assigned message types
that have various effects on the outcome of the program.
<UL>
<LI>S-Success, this message displays on the following screen in
the status line.
<LI>A-Abend, the current transaction is halted and a message is
displayed until the user confirms it.
<LI>E-Error, user must input data to continue.
<LI>W-Warning, user can either modify input data or press Enter
to proceed.
<LI>I-Information, user must press Enter to continue at the same
point in the program.
</UL>
<P>
You must specify a <TT>message-id</TT> report statement at the
beginning of your program.
<H3><A NAME="SyntaxforthemessageidStatement">
Syntax for the message-id Statement</A></H3>
<P>
The following is the syntax for a <TT>message-id</TT> statement
in a report:
<BLOCKQUOTE>
<PRE>
report example line-count 65 line-size 132 message-id fs.
</PRE>
</BLOCKQUOTE>
<P>
This two-character ID and a three-digit message number, together
with the language, determine message classes. SAP has made including
message statements in your program easy by using the <TT>insert</TT>
statement command in the ABAP/4 editor.
<P>
Figure 21.29 is a quick by double-clicking on the message ID number
in the ABAP/4 Editor.
<P>
<A HREF="javascript:popUp('f21-29.gif')"><B>Figure 21.29: </B><I>Object Browser Initial Screen</I>.</A>
<P>
Let's start at the Object Browser and choose Other Objects at
the bottom of the list (see Figure 21.30). You can skip to the
Maintain Individual Messages screen by double-clicking on the
message ID number in the ABAP/4 Editor.
<P>
<A HREF="javascript:popUp('f21-30.gif')"><B>Figure 21.30: </B><I>Other Development Objects screen</I>.</A>
<P>
Next enter a message class and click on the icon for the action
you want to perform. In this example, click on Create mode (see
Figure 21.31).
<P>
<A HREF="javascript:popUp('f21-31.gif')"><B>Figure 21.31: </B><I>Maintain Message Class screen</I>.</A>
<P>
Now you see the Maintain Message Class screen; it is here that
you can enter the attributes of the message class that you are
editing (see Figure 21.32)<I>. </I>Click the Messages button to
maintain individual messages.
<P>
<A HREF="javascript:popUp('f21-32.gif')"><B>Figure 21.32: </B><I>Maintain Individual Messages screen</I>.</A>
<P>
You are now in editor mode, which corresponds to one item in a
list of message text elements. After making necessary changes,
click on the Save button and your message is ready to use.<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=288><CENTER><B><FONT SIZE=4>D</FONT>O</B></CENTER>
</TD><TD WIDTH=288><CENTER><B><FONT SIZE=4>D</FONT>ON'T</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=288><B>DO </B>remember to use messages in a way that helps the user input data more efficiently.
<P>
<B>DO </B>make good use of the existing sys-tem message classes before creating your own.
</TD><TD WIDTH=288><B>DON'T </B>forget to specify the correct <TT>message-id </TT>at the beginning of your report.
</TD></TR>
</TABLE>
</CENTER>
<P>
<H2><A NAME="Summary"><FONT SIZE=5 COLOR=#FF0000>
Summary</FONT></A></H2>
<UL>
<LI>ABAP/4 is an event-driven programming language, and you can
take advantage of this fact by using the <TT>at selection-screen</TT>
and <TT>initialization</TT> events, as well as the <TT>at user-command</TT>
event, to validate user input using a number of techniques.
<LI>Foreign keys can be used to check the integrity of input data
using the primary key fields of a check table.
<LI>Matchcodes use logically pooled data to validate user input
based on specified selection criteria when used in conjunction
with selection screen parameters and selection options.
<LI>Messages can be used to communicate the status of the program
and the validity of the data entered, as well as interact with
the user in a way that can process data more efficiently.
<LI>Text elements should be maintained for selection screen elements
so that the user has a good understanding of the uses of the various
selection criteria field objects.
<LI>With ABAP/4 you can customize and modify existing logical
database selection screens to suite your specific needs.
</UL>
<H2><A NAME="QampABR"><FONT SIZE=5 COLOR=#FF0000>
Q&A<BR>
</FONT></A></H2>
<TABLE>
<TR VALIGN=TOP><TD WIDTH=48><CENTER><B>Q</B></CENTER></TD><TD><B>What happens if a primary key field is added to a check table after a foreign key has been defined?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><CENTER><B>A</B></CENTER></TD><TD>Additional fields that are added to the primary key of a foreign key check table are flagged as <I>generic</I> and therefore ignored by the system when validating data entered into the foreign key field.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><CENTER><B>Q</B></CENTER></TD><TD><B>Is it possible to insert variables such as system error messages or return codes in a message text?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><CENTER><B>A</B></CENTER></TD><TD>Yes. If you place an ampersand in the place that you want the variable to appear in the message text and call the message passing the variable, similar to a perform statement.
</TD></TR>
</TABLE>
<P>
<H2><A NAME="Workshop"><FONT SIZE=5 COLOR=#FF0000>
Workshop</FONT></A></H2>
<P>
The Workshop provides you two ways to affirm what you've learned
in this chapter. The Quiz section poses questions to help you
solidify your understanding of the material covered and the Exercise
section provides you with experience in using what you have learned.
You can find answers to the quiz questions and exercises in Appendix
B, "Answers to Quiz Questions and Exercises."
<H3><A NAME="Quiz">
Quiz</A></H3>
<OL>
<LI>How do the two flavors of matchcode assembly work in regard
to the storage of matchcode data?
<LI>If you change the characteristics of a domain, do the characteristics
of linked data elements change as well?
<LI>What is the primary rule for establishing a foreign key relationship?
</OL>
<H3><A NAME="Exercise">
Exercise 1</A></H3>
<P>
Create a selection screen report that lists all components of
a bill of materials in multiple languages. Construct fields for
selections from a range of material and plant combinations. Remember
to utilize the elements that we have learned in this chapter for
the tasks that best suit them.
<P>
<CENTER>
<HR SIZE=4>
<A HREF="../ch20/ch20.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch20/ch20.htm"><IMG SRC="../button/previous.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/previous.gif" BORDER="0"></A>
<A HREF="../index.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/index.htm"><IMG SRC="../button/contents.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/contents.gif" BORDER="0"></A>
<A HREF="rev03.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch21/rev03.htm"><IMG SRC="../button/next.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/next.gif" BORDER="0"></A>
</P>© <A HREF="../copy.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/copy.htm">Copyright</A>, Macmillan Computer Publishing. All rights reserved.
</CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -