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

📄 ch14.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 14.3 produces this output:
<BLOCKQUOTE>
<PRE>
----+----1----+--
12345678901234567
                 
XY               
XYZ  ABC         
    1234         
      1,234                 
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 6 writes the first two characters of <TT>'XYZ'</TT>.
<LI>Line 7 writes <TT>'XYZ'</TT> using four characters of output.
Default formatting is used, so the value is left-justified and
padded on the right with blanks.
<LI>Line 8 writes <TT>'ABC'</TT> one space after the previous
value. The previous value was padded on the right with one blank.
Another blank is added, and then <TT>'ABC'</TT> is written.
<LI>Line 9 writes <TT>f1</TT> in a field that is four characters
long beginning in column 5. The system removes the separators
to make the value fit into four characters.
<LI>Line 10 writes <TT>f1</TT> into a field that is eight characters
long beginning in column 5. Variables are used, so the word <TT>at</TT>
is required. Default formatting applies, so the value is right-justified
with leading zeros suppressed and, because there is enough room,
separators are also written.
</UL>
<H3><A NAME="WorkingwithSubfields">
Working with Subfields</A></H3>
<P>
You can specify a subfield in the <TT>write</TT> statement by
using offset and length specifications immediately after the value
without an intervening space. (If necessary, refer to the previous
section on additions to the <TT>write</TT> statement.) You cannot
use a subfield with a literal or a numeric field (types <TT>p</TT>,
<TT>i</TT>, and <TT>f</TT>). Listing 14.4 provides examples.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 14.4&nbsp;&nbsp;Using Subfields<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1404.
2  data f1(4) type c value 'ABCD'.
3 
4  write: / '----+----1----+--',
5         / '12345678901234567'.
6  skip.
7  write  / f1(2).
8  write  / f1+1(2).
9  write: /(2) f1+2(1), f1.
</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.4 produces this output:
<BLOCKQUOTE>
<PRE>
----+----1----+--
12345678901234567 
                  
AB                
BC                
C  ABCD           
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 7 writes the first and second characters of <TT>f1</TT>.
<LI>Line 8 writes the second and third characters of <TT>f1</TT>.
<LI>Line 9 writes the third character of <TT>f1</TT> beginning
on a new line in a field that is two characters long. It is left-justified
in that field and padded on the right with blanks. It then writes
out the entire contents of <TT>f1</TT> with an intervening blank
beforehand.
</UL>
<H3><A NAME="UsingtheunderAddition">
Using the under Addition</A></H3>
<P>
Using <TT>under</TT> causes the first character of the field to
be positioned in the same column as the first character of a previously
written field. You cannot use <TT>under</TT> with an explicit
position specification. Listing 14.5 shows examples.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 14.5&nbsp;&nbsp;Using the under Addition<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1405.
2  tables: ztxlfa1.
3 
4  select * up to 5 rows from ztxlfa1 order by lifnr.
5      write: /1  ztxlfa1-lifnr,
6              15 ztxlfa1-land1,
7              25 ztxlfa1-name1,
8             /   ztxlfa1-spras under ztxlfa1-land1,
9                 ztxlfa1-stras under ztxlfa1-name1.
10     skip.
11     endselect.
</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.5 produces this output:
<BLOCKQUOTE>
<PRE>
1000          CA        Parts Unlimited        
              E         111 Queen St.          
                                               
1010          CA        Industrial Pumps Inc.  
              E         1520 Avenue Rd.        
                                               
1020          CA        Chemical Nation Ltd.   
              E         123 River Ave.         
                                               
1030          CA        ChickenFeed Ltd.       
              E         8718 Wishbone Lane     
                                               
1040          US        Motherboards Inc.      
              E         64 BitBus Blvd.        
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 6 writes the <TT>land1</TT> field beginning in column
15.
<LI>Line 7 writes the <TT>name1</TT> field beginning in column
25.
<LI>Line 8 writes the <TT>spras</TT> field beginning in the same
column as <TT>land1</TT>. It consequently is written beginning
in column 15.
<LI>Line 9 writes the <TT>stras</TT> field beginning in the same
column as <TT>name1</TT>. It is therefore written beginning in
column 25.
</UL>
<H3><A NAME="UsingthenogapAddition">
Using the no-gap Addition</A></H3>
<P>
Using <TT>no-gap</TT> suppresses the intervening gap automatically
placed after a field if the following field has no column specification.
Listing 14.6 illustrates the use of <TT>no-gap</TT>.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 14.6&nbsp;&nbsp;Using no-gap<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1406.
2  data f1(4) value 'ABCD'.
3 
4  write: / f1, f1,
5         / f1 no-gap, f1,
6         / '''', f1, '''',
7         / '''', 2 f1, 6 '''',
8         / '''' no-gap, f1 no-gap, ''''.
</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.6 produces this output:
<BLOCKQUOTE>
<PRE>
ABCD ABCD
ABCDABCD 
' ABCD ' 
'ABCD'   
'ABCD'   
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 4 writes <TT>f1</TT> twice on the same line. Because
there is no position specification for the second <TT>f1</TT>,
a single intervening space is written before it.
<LI>Line 5 also writes <TT>f1</TT> twice. Using <TT>no-gap</TT>
after the first causes the two values to appear in the output
without an intervening space.
<LI>Line 6 writes <TT>f1</TT> with a single quote on either side.
Intervening spaces appear without the use of <TT>no-gap</TT>.
<LI>Line 7 writes <TT>f1</TT> enclosed by single quotes. Position
specifications cause the quotes to appear without intervening
spaces.
<LI>Line 8 uses <TT>no-gap</TT> to achieve the same output.
</UL>
<H3><A NAME="UsingEditMasks">
Using Edit Masks</A></H3>
<P>
Edit masks enable you to:
<UL>
<LI>Insert characters into the output
<LI>Move the sign to the beginning of a numeric field
<LI>Artificially insert or move a decimal point
<LI>Display a floating-point number without using scientific notation
</UL>
<P>
Anywhere within an edit mask, the underscore character (<TT>_</TT>)
has special meaning. At the beginning of an edit mask, <TT>V</TT>,
<TT>LL</TT>, <TT>RR</TT>, and <TT>==</TT> have special meaning.
All other characters are transferred without change to the output.
<P>
Underscores within an edit mask are replaced one-by-one with the
characters from the source field (the field you are writing out).
The number of characters taken from the source field will be equal
to the number of underscores in the edit mask. For example, if
there are three characters in the edit mask, at most three characters
from the source field will be output. All other characters in
the edit mask are inserted into the output. You also usually need
to increase the length of the output field to accommodate the
extra characters inserted by the mask.
<P>
For example, the statement <TT>write (6) 'ABCD' using edit mask
'_:__:_'</TT> writes <TT>A:BC:D</TT>. Characters are taken from
the source field one at a time, and characters from the edit mask
are inserted at the points indicated by the mask. The statement
<TT>write 'ABCD' using edit mask '_:__:_'</TT> only writes <TT>A:BC</TT>
because the default output length is equal to the length of the
source field (4).
<P>
If there are fewer underscores in the mask than there are in the
source field, the default is to take the left-most <I>n</I> characters
from the source field, where <I>n</I> equals the number of underscores
in the edit mask. This can also be explicitly specified by preceding
the edit mask with <TT>LL</TT>. For example, <TT>write 'ABCD'
using edit mask 'LL__:_'</TT> takes the left-most three characters
and writes out <TT>AB:C</TT>. Using <TT>RR</TT> instead takes
the right-most three characters, so <TT>write 'ABCD' using edit
mask 'RR__:_'</TT> will write out <TT>BC:D</TT>.
<P>
If there are more underscores than there are source field characters,
the effect of <TT>LL</TT> is to left-justify the value in the
output; <TT>RR</TT> right-justifies the value (see Listing 14.7
for an example).
<P>
An edit mask beginning with a <TT>V</TT>, when applied to a numeric
field (types <TT>i</TT>, <TT>p</TT>, and <TT>f</TT>), causes the
sign field to be displayed at the beginning. If applied to a character
field, a <TT>V</TT> is actually output.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 14.7&nbsp;&nbsp;The Effect of Various Edit Masks<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1407.
2  data: f1(4) value 'ABCD',
3        f2    type i value '1234-'.
4 
5  write: / ' 5. ', f1,
6         / ' 6. ', (6) f1 using edit mask '_:__:_',
7         / ' 7. ', f1 using edit mask 'LL_:__',
8         / ' 8. ', f1 using edit mask 'RR_:__',
9         / ' 9. ', f2 using edit mask 'LLV______',
10        / '10. ', f2 using edit mask 'RRV______',
11        / '11. ', f2 using edit mask 'RRV___,___',
12        / '12. ', f2 using edit mask 'LLV___,___',
13        / '13. ', f1 using edit mask 'V___'.
</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.7 produces this output:
<BLOCKQUOTE>
<PRE>
 5.  ABCD      
 6.  A:BC:D    
 7.  A:BC      
 8.  B:CD      
 9.  -1234     
10.  -  1234   
11.  -  1,234  
12.  -123,4    
13.  VABC      
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 5 outputs <TT>f1</TT> without any edit masks.
<LI>Line 6 outputs all four characters of <TT>f1</TT> using colons
to separate them.
<LI>There are three underscores in the edit mask on line 7, but
four characters in <TT>f1</TT>. Therefore, the first three characters
of <TT>f1</TT> are used in the edit mask.
<LI>Line 8 takes the last three characters of <TT>f1</TT> and
applies them to the edit mask.
<LI>There are six underscores in the edit mask on line 9, more
than the four characters from <TT>f1</TT>. The value of <TT>f1</TT>
is output left-justified with a leading sign.
<LI>On line 10, the value of <TT>f1</TT> is output right-justified
with a leading sign.
<LI>Lines 11 and 12 show the effect of combining inserted characters
with justification. The inserted characters do not move relative
to the output field.
<LI>Line 13 shows the effect of using a <TT>V</TT> with a character

⌨️ 快捷键说明

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