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

📄 ch17.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<UL>
<LI>If a program has a selection screen and you issue a <TT>write</TT>
statement in an event triggered before <TT>start-of-selection</TT>,
you will not see the output from it. For example, if you have
a <TT>parameters</TT> statement in your program, a selection screen
is created for your program to allow the user to enter the parameter
value. If in this program you issue a <TT>write</TT> in <TT>initialization</TT>,
you will not see the output from the <TT>write</TT> statement.
<LI>A new event always begins a new line in the output. For example,
if you issue a <TT>write</TT> statement in <TT>start-of-selection</TT>,
a <TT>write</TT> in <TT>end-of-selection</TT> will begin on a
new line. You can use <TT>skip to line</TT> if it is necessary
to continue writing on the same line.
</UL>
<H4>Triggering top-of-page</H4>
<P>
This section describes when <TT>top-of-page</TT> is triggered
in relation to driver program events. If your program doesn't
have a selection screen, the first <TT>write</TT> statement executed
triggers <TT>top-of-page</TT>. If your program does have a selection
screen, is it possible for <TT>top-of-page</TT> to be triggered
twice:
<UL>
<LI>By the first <TT>write</TT> statement executed before the
selection screen is shown
<LI>By the first <TT>write</TT> statement after the selection
screen is shown
</UL>
<P>
Only if you are doing something unusual in <TT>top-of-page</TT>,
like opening files or initializing data, do you have to be wary
of the double-trigger effect.
<P>
If <TT>top-of-page</TT> is triggered twice, you will only see
the output from <TT>write</TT> statements within it the second
time it is triggered. The output created by <TT>write</TT> statements
during the first time it is triggered is discarded. This double-triggering
doesn't usually cause any problems with your program or with your
output because
<UL>
<LI>You can't see the output from <TT>write</TT>s issued before
a selection is shown, so you usually don't code them there.
<LI>The <TT>top-of-page</TT> event usually only contains <TT>write</TT>
statements, and the output from the first triggering is discarded
so no harm is done when it is triggered twice.
</UL>
<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
The write to variation of the <TT>write</TT> statement doesn't trigger <TT>top-of-page</TT>.
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="Defaultingtostartofselection">
Defaulting to start-of-selection</A></H3>
<P>
If the first executable statement in your program is not preceded
by an event name, at runtime the system automatically inserts
<TT>start-of-selection</TT> before the first line of executable
code. Therefore, if you haven't coded any events, or you have
put code at the top of the program without naming an event, <TT>start-of-selection</TT>
is assumed. Listing 17.3 provides an example of this, in a program
containing both a selection screen and events. It also contains
a program-driven event-<TT>top-of-page</TT>.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 17.3&nbsp;&nbsp;start-of-selection Automatically Inserted
Before the First Line of Code<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1703 no standard page heading.
2  parameters p1(8).
3
4  write: / 'p1 =', p1.
5
6  initialization.
7    p1 = 'Init'.
8
9  end-of-selection.
10   write: /(14) sy-uline,
11          / 'End of program'.
12
13 top-of-page.
14   write: / 'This is My Title'.
15   skip.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 17.3 produces the following output:
<BLOCKQUOTE>
<PRE>
This is My Title
p1 = INIT      
--------------
End of program
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>When you execute program <TT>ztx1703</TT>, a driver program
starts up first. Since there is code at the beginning of the program
that doesn't belong to any events, a <TT>start-of-selection</TT>
is automatically inserted at line 3.
<LI>The driver program triggers the <TT>initialization</TT> event.
Line 7 executes and assigns the value <TT>'Init'</TT> to <TT>p1</TT>.
Control returns to the driver program.
<LI>Since there is a selection screen for this program, the selection
screen is now shown. It appears in Figure 17.2. The value assigned
to <TT>p1</TT> on line 7 appears in the input field.<BR>
<A HREF="javascript:popUp('f17-2.gif')"><B>Figure 17.2 :</B> <I>The selection screen for the ztx1703 program</I>.</A>
<LI>The user presses Execute on the selection screen. Control
returns to the driver program, which then triggers the <TT>start-of-selection</TT>
event.
<LI>Since <TT>start-of-selection</TT> was inserted at line 3,
control passes to <TT>ztx1703</TT> starting at line 4.
<LI>Line 4 is executed. Since this is the first <TT>write</TT>
statement executed after <TT>start-of-selection</TT> it triggers
the <TT>top-of-page</TT> event. Control transfers to line 14.
<LI>Line 14 writes a title. Line 15 writes a blank line. Control
returns to line 4.
<LI>Line 4 writes the value of <TT>p1</TT>.
<LI>The driver then triggers the <TT>end-of-selection</TT> event.
Control passes to line 10.
<LI>Line 10 writes a horizontal line for 14 bytes.
<LI>Line 11 writes <TT>End of program</TT>. Control returns to
the driver program.
<LI>The driver displays the list to the user.
</UL>
<P>
You cannot put a condition around an event or enclose an event
in a loop. To do so will cause a syntax error. For example, the
code in Listing 17.4 causes a syntax error.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 17.4&nbsp;&nbsp;Don't Enclose an Event Within a Condition
or a Loop<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1704.
2  data f1.
3 
4  start-of-selection.
5    f1 = 'A'.
6 
7  if f1 = 'A'.
8    end-of-selection.
9    write: / f1.
10   endif.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 17.4 produces this syntax error: <TT>Incorrect
nesting: before the statement &quot;END-OF-SELECTION&quot;, the
structure introduced by &quot;IF&quot; must be concluded by &quot;ENDIF&quot;</TT>.

<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<p>
Event names have higher priority than other ABAP/4 statements.
The <TT>if</TT> statement on line 7 belongs to the <TT>start-of-selection</TT>
event. The <TT>endif</TT> statement on line 10 belongs to the
<TT>end-of-selection</TT> event. You close all open conditions
and loops within the event to which they belong. Therefore, this
program must have an <TT>endif</TT> before the <TT>end-of-selection</TT>
event. Because there is also an <TT>endif</TT> within <TT>end-of-selection</TT>
on line 10, that <TT>endif</TT> would have to be removed before
the program would run.
<P>
You should not put data definitions within events. Although this
doesn't cause a syntax error, it is poor programming style. All
data definitions should be done at the top of the program.
<P>
Each event has a specific purpose and is needed to accomplish
a specific programming task. As the need arises, I will refer
to them in the material that follows. If you don't see any events
in a program, always remember that one still exists-<TT>start-of-selection</TT>.
<H3><A NAME="LeavinganEvent">
Leaving an Event</A></H3>
<P>
You can exit out of an event at any time using the following statements:
<UL>
<LI><TT>exit</TT>
<LI><TT>check</TT>
<LI><TT>stop</TT>
</UL>
<P>
At this time, please review the function of the <TT>check</TT>
statement (presented in <A HREF="../ch10/ch10.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch10/ch10.htm" >Chapter 10</A>, &quot;Common Control Statements&quot;).
<P>
The following paragraphs describe the effect of <TT>check</TT>
and <TT>exit</TT> when they are coded outside a loop. The effect
of <TT>stop</TT> is the same regardless of whether is it coded
within a loop or not.<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Although at this point only three events have been presented in detail, this section is written in a general sense so that it will apply equally well after you have learned to use all events.</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
In all events
<UL>
<LI><TT>check</TT> immediately leaves the current event and processing
continues with the next event (or action, such as displaying the
selection screen or output list).
<LI><TT>stop</TT> immediately leaves the current event and goes
directly to the <TT>end-of-selection</TT> event. Executing <TT>stop</TT>
within <TT>end-of-selection</TT> leaves the event. It doesn't
cause an infinite loop.
</UL>
<P>
In events that occur before <TT>start-of-selection</TT>
<UL>
<LI><TT>exit</TT> and <TT>check</TT> have the same behavior. They
both leave the event immediately and processing continues with
the next event (or action, such as display of the selection screen).
</UL>
<P>
In <TT>start-of-selection</TT> and events that occur after it
<UL>
<LI><TT>exit</TT> terminates the report and shows the output list.
A single exception exists; within <TT>top-of-page</TT>, <TT>exit</TT>
behaves like <TT>check</TT>.
<LI><TT>check</TT> leaves the event and processing continues with
the next event (or action, such as display of the output list).
</UL>
<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>CAUTION</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Don't use stop in the following events: initialization, at selection-screen output, top-of-page, and end-of-page. Technically, stop can work with top-of-page and end-of-page if you refrain from issuing write statements within end-of-selection afterward. In the case of top-of-page a write, can cause a short dump; in the case of end-of-page, you can lose output. It is safer to avoid it altogether within these events.</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
<TT>check</TT>, <TT>exit</TT>, and <TT>stop</TT> do <I>not</I>
set the value of <TT>sy-subrc</TT>. If you want to set it, you
can assign a numeric value to it before leaving.
<P>
The report shown in Listing 17.5 allows you to try the effects
of these statements within various events. Copy it and remove
comments one at a time to experiment with the possible variations.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 17.5&nbsp;&nbsp;Effects of exit, check, and stop Within
Events<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1705 no standard page heading line-count 6(2).
2  *in events before start-of-selection:
3  *   - exit and check have the same behavior. They both leave the event
4  *     and processing continues with the next event or action.
5  *   - stop goes directly to the end-of-selection event
6  *     (don't use stop in initialization or at selection-screen output)
7
8  *in start-of-selection and subsequent events:
9  *   - exit terminates the report and shows the output list
10 *     exception: top-of-page: exit leaves the event
11 *   - check leaves the event and processing continues with the next one.
12 *   - stop goes directly to the end-of-selection event
13
14                                            &quot;execute an:
15 parameters: exit_sos radiobutton group g1, &quot;exit in start-of-selection
16             exit_eos radiobutton group g1, &quot;exit in end-of-selection
17             chck_sos radiobutton group g1, &quot;check in start-of-selection
18             chck_eos radiobutton group g1, &quot;check in end of selection
19             stop_sos radiobutton group g1, &quot;stop in start-of-selection
20             stop_eos radiobutton group g1, &quot;stop in end-of-selection
21             none     radiobutton group g1. &quot;no stop, exit or check
22
23 initialization.
24 *   exit.                          &quot;exits event
25 *   check 1 = 2.                   &quot;exits event
26 *   stop.                          &quot;don't do this
27     chck_sos = 'X'.
28
29 at selection-screen output.
30 *   exit.                          &quot;exits event
31 *   check 1 = 2.                   &quot;exits event
32 *   stop.                          &quot;don't do this
33     message s789(zk) with 'at selection-screen output'.
34
35 at selection-screen on radiobutton group g1.
36 *   exit.                          &quot;exits event
37 *   check 1 = 2.                   &quot;exits event
38 *   stop.                          &quot;goes to end-of-selection
39     message i789(zk) with 'at selection-screen on rbg'.
40
41 at selection-screen.
42 *   exit.                          &quot;exits event
43 *   check 1 = 2.                   &quot;exits event
44 *   stop.                          &quot;goes to end-of-selection
45     message i789(zk) with 'at selection-screen'.
46
47 start-of-selection.
48     write: / 'Top of SOS'.
49     if      exit_sos = 'X'.
50         exit.                      &quot;exits report
51     elseif  chck_sos = 'X'.
52         check 1 = 2.               &quot;exits event
53     elseif  stop_sos = 'X'.
54         stop.                      &quot;goes to end-of-selection
55         endif.
56     write: / 'Bottom of SOS'.
57
58 end-of-selection.
59     write: / 'Top of EOS'.
60     if      exit_eos = 'X'.
61         exit.                      &quot;exits report
62     elseif  chck_eos = 'X'.
63         check 1 = 2.               &quot;exits report
64     elseif  stop_eos = 'X'.
65         stop.                      &quot;exits report
66         endif.
67     write: / 'Bottom of EOS'.
68     write: / '1',
69            / '2',
70            / '3'.
71
72 top-of-page.
73     write: / 'Title'.
74 *   exit.                  &quot;exits event and returns to write statement
75 *   check 'X' = 'Y'.       &quot;exits event and returns to write statement
76 *   stop.                  &quot;goto end-of-selection - don't write after it
77     uline.
78
79 end-of-page.
80     uline.
81 *   exit.                  &quot;exits report
82 *   check 'X' = 'Y'.       &quot;exits event and returns to write statement
83 *   stop.                  &quot;goto end-of-selection - don't write after it
84     write: / 'Footer'.
</PRE>
</BLOCKQUOTE>

⌨️ 快捷键说明

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