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

📄 ch14.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
16 write: /     t1,  26 'type t: default output length = 6',
17        /(8)  t1,  26 'type t: increased output length to 8',
18        /(12) t1,  26 'type t: increased output length to 12',
19        /     t2,  26 'type t: default output length = 8 (from domain)',
20        /     d1,  26 'type d: default output length = 8',
21        /(10) d1,  26 'type d: increased output length to 10',
22        /     d2,  26 'type d: default output length = 10 (from domain)',
23        /     f1,  26 'type f: default output length = 22',
24        /     i1,  26 'type i: default output length = 11',
25        /     i2,  26 'type i: same output length, more digits',
26        /     i3,  26 'type i: same output length, even more digits',
27        /(10) i3,  26 'type i: smaller output length, negative number',
28        /(10) i4,  26 'type i: smaller output length, positive number',
29        /     n1,  26 'type n: default output length = field length',
30        /     p1,  26 'type p: default output length = 2 * length = 10',
31        /(12) p1,  26 'type p: output length increased to 12',
32        /(15) p1,  26 'type p: output length increased to 15',
33        /     c1,  26 'type c: output length = field length (left just)',
34        /     x1,  26 'type x: default output length = 2 * length = 4'.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 14.1 produces this output:
<BLOCKQUOTE>
<PRE>
123456                   type t: default output length = 6
12:34:56                 type t: increased output length to 8
12:34:56                 type t: increased output length to 12
12:34:56                 type t: default output length = 8 (from domain)
19980201                 type d: default output length = 8
1998/02/01               type d: increased output length to 10
1998/02/01               type d: default output length = 10 (from domain)
-1.234000000000000E+03   type f: default output length = 22
12,345,678-              type i: default output length = 11
123456,789-              type i: same output length, more digits
1123456789-              type i: same output length, even more digits
*23456789-               type i: smaller output length, negative number
1123456789               type i: smaller output length, positive number
00123                    type n: default output length = field length
123456789-               type p: default output length = 2 * length = 10
123,456,789-             type p: output length increased to 12
   123,456,789-          type p: output length increased to 15
ABC                      type c: output length = field length (left just)
A0B0                     type x: default output length = 2 * length = 4
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 16 writes a type <TT>t</TT> variable using its default
length of 6. There is no room for the separators, so they are
not written.
<LI>Line 17 writes the same variable using an output length of
8, which was specified on the <TT>write</TT> statement. This output
length overrides the default output length and provides enough
room in the output to include the separators.
<LI>Line 18 shows that if the output field is larger than 8 characters,
the time field is output left-justified within that field by default.
<LI>Line 19 writes out a field defined like <TT>sy-uzeit</TT>.
Within the domain for <TT>sy-uzeit</TT>, the Output Length field
is set to 8. Therefore, the output length for field <TT>t2</TT>
is also 8, which provides enough room to write the separators
as well.
<LI>Line 20 writes out a type <TT>d</TT> field that has a default
output length of 8. There is not enough room for separators, so
the field does not contain separators. However, the year/month/day
order is still determined from the user defaults.
<LI>Line 21 writes out the same date field, this time increasing
the output length to 10 to allow for separators.
<LI>Line 22 writes out field <TT>d2</TT>. The length of <TT>d2</TT>
is obtained from the domain for <TT>sy-datum</TT>.
<LI>Line 23 writes out a floating-point field showing scientific
notation and a leading sign.
<LI>Line 24 writes out an integer using the default length of
11.
<LI>Line 25 writes out a bigger integer using the same length.
The first thousands separator is dropped to enable the extra digit
to be written.
<LI>Line 26 increases the number again by one digit, causing the
second separator to be dropped.
<LI>Line 27 writes out the same number, this time decreasing the
output length by 1, and the overflow indicator is seen in the
first character of the output field.
<LI>Line 28 writes the same number using the same length, but
this time the number is positive. The system shifts the number
right and uses the sign field to prevent overflow.
<LI>Line 29 writes a numeric field showing that it is right-justified
and padded on the left with leading zeros.
<LI>Line 30 writes a packed decimal field showing the default
output length and the dropping of separators.
<LI>Lines 31 and 32 increase the output length to 12 and 15, showing
the separators and right justification.
<LI>Line 33 shows a character field left-justified in the output
field.
<LI>Line 34 shows the output from a hexadecimal field.
</UL>
<H2><A NAME="AdditionstothewriteStatement"><FONT SIZE=5 COLOR=#FF0000>
Additions to the write Statement</FONT></A></H2>
<P>
This section details some of the specific output specifications
that can be used with the <TT>write</TT> statement.
<H3><A NAME="SyntaxforthewriteStatement">
Syntax for the write Statement</A></H3>
<P>
The following is the syntax for the <TT>write</TT> statement.
<BLOCKQUOTE>
<PRE>
write [at] [/<I>p</I>(<I>l</I>)] <I>v1</I>[+<I>o</I>(<I>sl</I>)]
       (1)  under <I>v2</I> | no-gap
       (2)  using edit mask <I>m</I> | using no edit mask
       (3)  mm/dd/yy   | dd/mm/yy  
       (4)  mm/dd/yyyy | dd/mm/yyyy
       (5)  mmddyy     | ddmmyy     | yymmdd
       (6)  no-zero
       (7)  no-sign
       (8)  decimals <I>n
</I>       (9)  round <I>n
</I>       (10) currency <I>c</I> | unit <I>u
</I>       (11) left-justified | centered | right-justified
</PRE>
</BLOCKQUOTE>
<P>
where:
<UL>
<LI><TT><I>v1</I></TT> is a literal,
variable, or field string name.
<LI><TT><I>p</I></TT>, <TT><I>l</I></TT>,
and <TT><I>n</I></TT> are numeric
literals or variables.
<LI><TT><I>p</I></TT> is the position
specification. It identifies the output column in which the output
field should begin.
<LI><TT><I>l</I></TT> is the length
specification. It identifies the length of the output field in
which the value should be written.
<LI><TT><I>o</I></TT> is a subfield
offset specification that can contain numeric literals only.
<LI><TT><I>sl</I></TT> is a subfield
length specification that can contain numeric literals only.
<LI><TT><I>m</I></TT> is an edit
mask.
<LI><TT><I>c</I></TT> is a currency
key (from table <TT>tcurc</TT>).
<LI><TT><I>u</I></TT> is a unit
of measure (from table <TT>t006</TT>).
<LI><TT><I>n</I></TT> is a numeric
literal or variable.
</UL>
<P>
The following points apply:
<UL>
<LI>If either <TT><I>p</I></TT>
or <TT><I>l</I></TT> is a variable,
the word <TT>at</TT> is required.
<LI>A slash (<TT><I>/</I></TT>)
begins a new line before writing the variable value.
</UL>
<P>
If no additions are specified and two <TT>write</TT> statements
are executed (such as <TT>write: v1, v2.</TT>), the value of <TT>v2</TT>
appears on the same line as that of <TT>v1</TT> separated from
it by one space. If the value of <TT>v2</TT> will not fit on the
remainder of the current line, it appears on the next line. If
the output length of <TT>v2</TT> is greater than the line length,
the output is truncated on the right. If the value is output right-justified
(as with type <TT>p</TT> variables) before truncating it on the
right, it will be shifted left as long as there are leading blanks
to avoid truncating it. Separators are also removed, if necessary,
to avoid truncation.<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
A new line of output always begins at the start of a new event. Events are covered in <A HREF="../ch17/ch17.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch17/ch17.htm" >Chapter 17</A>, &quot;Modularization: Events and Subroutines.&quot;</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="UnderstandingthePositionSpecification">
Understanding the Position Specification</A></H3>
<P>
Referring to the syntax given above, <TT><I>p</I></TT>
specifies the output column. The output value can overwrite all
or part of a preceding <TT>write</TT>. The program in Listing
14.2 illustrates the effect of a series of <TT>write</TT> statements.
Table 14.4 shows the cumulative effect of each <TT>write</TT>,
in sequence, to show how the output is arrived at.
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<HR>
<P>
<B>Listing 14.2&nbsp;&nbsp;A Series of write Statements to Illustrate
the Effect of the Output Column Specification<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1402.
2  data f1(4) type p value 1234.
3  write: / '----+----1----+--',
4         / '12345678901234567'.
5  skip.
6  write /1 'X'.
7  write    'YZ'.
8  write  2 'YZ'.
9  write  3 'ABC'.
10 write  4 f1.
11 write  7 f1.
12 write  'Z'.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 14.2 produces this output:
<BLOCKQUOTE>
<PRE>
----+----1----+--
12345678901234567
               
XYA  1  1,234  Z
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Lines 3 and 4 write out a ruler so that you can see the output
columns.
<LI>Line 6 writes an <TT>'X'</TT> beginning in column 1.
<LI>Line 7 writes <TT>'YZ'</TT> beginning one space after the
<TT>'X'</TT>.
<LI>Line 8 writes <TT>'YZ'</TT> beginning in column 2. This overwrites
the space and the <TT>'Y'</TT> that was written previously.
<LI>Line 9 writes <TT>'ABC'</TT> beginning in column 3. This overwrites
the two <TT>'Z'</TT>s, plus one space.
<LI>Line 10 writes <TT>f1</TT> beginning in column 4. The default
output length of <TT>f1</TT> is 8; the default format is right-justified
with the last character reserved for the sign. The three leading
blanks overwrite the existing output beginning in column 4.
<LI>Line 11 writes <TT>f1</TT> again, this time beginning in column
7.
<LI>Line 12 writes <TT>'Z'</TT> one space after <TT>f1</TT>. In
the output, there appears to be two spaces. The first space after
the <TT>4</TT> is the sign field for <TT>f1</TT>. Then one space
is written, and then <TT>'Z'</TT> in column 16.
</UL>
<P>
<P>
<CENTER><B>Table 14.4&nbsp;&nbsp;write Statement Examples and
Corresponding Output</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><B>Statements</B></CENTER></TD><TD WIDTH=192><CENTER><B>Cumulative Output
<BR>
</B><TT><B>----+----1----+--<BR>
12345678901234567</B></TT></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write 1 'X'.</TT></TD><TD WIDTH=192><TT>X</TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write   'YZ'.</TT></TD><TD WIDTH=192><TT>X YZ</TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write 2 'YZ'.</TT></TD><TD WIDTH=192><TT>XYZZ</TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write 3 'ABC'.</TT></TD><TD WIDTH=192><TT>XYABC</TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write 4 f1.</TT></TD><TD WIDTH=192><TT>XYA  1,234</TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write 7 f1.</TT></TD><TD WIDTH=192><TT>XYA  1  1,234</TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>write   'Z'.</TT></TD><TD WIDTH=192><TT>XYA  1  1,234  Z</TT>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="UnderstandingtheLengthSpecification">
Understanding the Length Specification</A></H3>
<P>
In the syntax description for the <TT>write</TT> statement, <TT><I>o</I></TT>
specifies the output length. This is the number of characters
on the output line used to hold the output value.
<P>
Position and length specifications are always optional. They can
be specified using either a literal or a variable. If either one
is a variable, it must be preceded by the word <TT>at</TT>. <TT>at</TT>
is optional if the position and length are both literals, but
it is required if either is a variable.
<P>
If a slash (<TT>/</TT>) precedes a position or length specification,
there cannot be an intervening space between them. Listing 14.3
provides examples.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 14.3&nbsp;&nbsp;Illustrating the Use of the Position
and Length Specifications<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1403.
2  data: f1(4) type p value 1234,
3        p     type i value 5,
4        l     type i value 8.
5 
6  write: / '----+----1----+--',
7         / '12345678901234567'.
8  skip.
9  write /(2) 'XYZ'.
10 write /(4) 'XYZ'.
11 write      'ABC'.
12 write /5(4) f1.
13 write at /p(l) f1.
</PRE>
</BLOCKQUOTE>
<HR>
<P>

⌨️ 快捷键说明

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