📄 ch16.htm
字号:
3 30
4 40
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>The first execution of line 4 triggers line 12 (the <TT>top-of-page</TT>
event).
<LI>Line 13 writes a title, and line 14 underlines it.
<LI>Line 15 sets the current output position to the first line
in the output list.
<LI>Line 16 overwrites <TT>'was'</TT> with <TT>'is '</TT>.
<LI>Line 17 moves the current output position down one line. The
second line of the output list is now the current output line.
<LI>Control returns to line 4. It issues a new line character
and the first value from this loop is output to the third line
of output. The remaining values are output on succeeding lines.
<LI>Line 6 returns the current output position to what it was
for the first write after the <TT>top-of-page</TT> processing
(output list line 2).
<LI>The loop on lines 7 through 10 overwrites the output list
beginning on line 3. This data is written to the right of the
existing data, beginning in column 10.
</UL>
<H3><A NAME="UsingthepositionStatement">
Using the position Statement</A></H3>
<P>
Use the <TT>position</TT> statement to specify the next output
column on the current line. For example, <TT>skip to line 2. position
3. write 'Hi'.</TT> would write <TT>Hi</TT> on line 2 beginning
in column 3.
<H4>Syntax for the position Statement</H4>
<BLOCKQUOTE>
<PRE>
position v1.
</PRE>
</BLOCKQUOTE>
<P>
where:
<UL>
<LI><TT><I>v1</I></TT> is a numeric
variable or literal.
</UL>
<P>
Listing 16.5 illustrates the use of the <TT>position</TT> statement.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 16.5 The POSITION Statement<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 report ztx1605.
2 data n type i.
3 do 4 times.
4 do 4 times.
5 position sy-index.
6 write 'A'.
7 enddo.
8 new-line.
9 enddo.
10
11 skip.
12 do 4 times.
13 do 4 times.
14 position sy-index.
15 write 'A'.
16 enddo.
17 skip.
18 enddo.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 16.5 produces the following output:
<BLOCKQUOTE>
<PRE>
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 3 begins a <TT>do</TT> loop.
<LI>Line 4 begins a nested <TT>do</TT> loop. Each time through,
line 5 sets the current output position equal to the current loop
iteration. So, the first time through, the current output position
is set to 1. The second time through it's set to 2, and so on.
This causes line 6 to write the letter A 4 times, in columns 1
through 4.
<LI>Line 8 moves the output position down one line. This results
in the output being written on successive lines, beginning at
the line following the standard headers.
<LI>Line 11 outputs a blank line.
<LI>Lines 12 through 18 are the same as lines 3 through 9, except
instead of <TT>new-line</TT>, <TT>skip</TT> is used on line 17.
This has the effect of inserting blank lines between successive
output lines.
</UL>
<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Using the <TT>position</TT> statement followed immediately by a write is equivalent to issuing a single <TT>write</TT> at statement (covered in the previous chapter).
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="UsingthesetblanklinesStatement">
Using the set blank lines Statement</A></H3>
<P>
Normally, if your program issues a <TT>write</TT> statement that
results in a blank line being output, this blank line will be
suppressed. For example, when writing out a variable that contains
blanks, you will not see a blank line in the list. Use the <TT>set
blank lines</TT> statement to change this behavior.
<H4>Syntax for the set blank lines Statement</H4>
<BLOCKQUOTE>
<PRE>
set blank lines on | off.
</PRE>
</BLOCKQUOTE>
<P>
The following points apply:
<UL>
<LI>The default setting is off.
<LI>Blank lines generated by the <TT>skip</TT> statement are not
suppressed.
<LI>Blank lines generated by <TT>write /</TT> without a variable
are not suppressed. For example, <TT>write /.</TT> will always
generate a blank line. <TT>Write / ' '.</TT> will only generate
a blank line if <TT>set blank lines on</TT> has been executed
beforehand.
</UL>
<P>
Listing 16.6 illustrates the <TT>set blank lines</TT> statement.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 16.6 The SET BLANK<I> </I>LINES Statement
<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 report ztx1606.
2 data: f1, f2, f3.
3 write: / 'Text 1'.
4 write: / f1, / f2, / f3.
5 write: / 'Text 2'.
6 skip.
7
8 set blank lines on.
9 write: / 'Text 3'.
10 write: / f1, / f2, / f3.
11 write: / 'Text 4'.
12
13 set blank lines off.
14 skip.
15 write: / 'Text 5'.
16 write: / f1, / f2, / f3.
17 write: / 'Text 6'.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 16.6 produces the following output:
<BLOCKQUOTE>
<PRE>
Text 1
Text 2
Text 3
Text 4
Text 5
Text 6
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 2 defines three variables. All are character length <TT>1</TT>,
and have a default initial value of blanks.
<LI>By default, blank lines that would result from attempting
to write blanks are suppressed. Therefore, the line 4 does not
cause any blank lines to be written.
<LI>The <TT>skip</TT> statement always writes blank lines, so
line 6 generates a blank line.
<LI>Line 8 allows the <TT>write</TT> statement to write entirely
blank lines to the list.
<LI>Line 10 writes three blank lines.
<LI>Line 13 sets blank lines off again.
<LI>Line 14 generates a blank line.
<LI>Line 16 does not generate blank lines.
</UL>
<H2><A NAME="Summary"><FONT SIZE=5 COLOR=#FF0000>
Summary</FONT></A></H2>
<UL>
<LI>Use <TT>new-line</TT> to begin a new line or to lock a specific
line in place. It can prevent horizontal scrolling of any individual
line.
<LI>Use <TT>new-page</TT> to generate a page break, to turn titles
and headers on or off, change the line count or line size between
pages, or to send output to the spool.
<LI>Use <TT>skip</TT> to generate blank lines in the output. <TT>skip
to line</TT> sets the output position to a specific line.
<LI>Use <TT>back</TT> to return to the top of a page, or to the
beginning of a group of lines.
<LI>Use <TT>position</TT> to specify the next output column.
<LI>Use <TT>set blank lines</TT> to allow blank lines to be created
by writing variables that contain blanks.
</UL>
<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> use symbols and icons in your report to increase readability.
</TD><TD WIDTH=288><B>DON'T</B> hard-code a page size. Allow the users to specify it when they print the report.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=288> </TD><TD WIDTH=288><B>DON'T </B>create reports wider than 132 characters if the user may print it. Most printers cannot print pages wider than 132 characters.
</TD></TR>
</TABLE>
</CENTER>
<P>
<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>I don't really understand the difference between <TT><B>skip</B></TT> and <TT><B>new-line</B></TT>. Don't they both cause the next <TT><B>write</B></TT> to go to a new line?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><CENTER><B>A</B></CENTER></TD><TD>The purpose of <TT>skip</TT> is to generate a blank line in the output. <TT>new-line</TT> causes the next line of output to be written to a new line, and does not generate blank lines.
</TD></TR>
</TABLE>
<P>
<H2><A NAME="Workshop"><FONT SIZE=5 COLOR=#FF0000>
Workshop</FONT></A></H2>
<P>
The Workshop provides two ways for you 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>What statement can you use to overwrite the same line?
<LI>When would you want to use <TT>skip sy-linct</TT> instead
of <TT>new-page</TT> if you want a footer?
</OL>
<H3><A NAME="Exercise">
Exercise 1</A></H3>
<P>
Explain the flow of control in the following program, and how
it works.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 16.7 top-of-page, position, and skip<BR>
</B>
<BLOCKQUOTE>
<PRE>
report zty1607.
data n type i.
do 4 times.
do 4 times.
position sy-index.
write 'A'.
enddo.
add 1 to n.
skip to line n.
enddo.
top-of-page.
n = sy-linno.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 16.7 produces the following output:
<BLOCKQUOTE>
<PRE>
AAAA
AAAA
AAAA
AAAA
</PRE>
</BLOCKQUOTE>
<P>
<CENTER>
<HR SIZE=4>
<A HREF="../ch15/ch15.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch15/ch15.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="../ch17/ch17.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch17/ch17.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 + -