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

📄 ch14.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">


<!--

function popUp(pPage) {
 popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
 figDoc= popUpWin.document;
 zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
 zhtm += '</head>';
 zhtm += '<BODY bgcolor="#FFFFFF">';
 zhtm += '<IMG SRC="' + pPage + '">';
 zhtm += '<P><B>' + pPage + '</B>';
 zhtm += '</BODY></HTML>';
 figDoc.write(zhtm);
 figDoc.close();
 popUpWin.focus();
 }

//-->


</SCRIPT>

        <META NAME="GENERATOR" Content="Symantec Visual Page 1.0.1">
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
        <TITLE>Sams Teach Yourself ABAP/4&reg; in 21 Days -- Day 14- The write Statement</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<CENTER>
<H1><IMG SRC="../button/sams.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/sams.gif" BORDER="0"></H1>
</CENTER>
<CENTER>
<P><A HREF="../ch13/ch13.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch13/ch13.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="rev02.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch14/rev02.htm"><IMG SRC="../button/next.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/next.gif" BORDER="0"></A> 

<H1>Sams Teach Yourself ABAP/4<sup>&reg;</sup> in 21 Days</H1></CENTER>
<HR SIZE=4>





<H1>Day&nbsp;14</H1>
<H1>The <FONT SIZE=6>write</FONT><FONT SIZE=6> Statement</FONT>
</H1>


<UL>
<LI><A HREF="#ChapterObjectives">
Chapter Objectives</A>
<LI><A HREF="#DefaultLengthsandFormatting">
Default Lengths and Formatting</A>
<UL>
<LI><A HREF="#DefaultLengths">
Default Lengths</A>
<LI><A HREF="#PackedFields">
Packed Fields</A>
<LI><A HREF="#DefaultFormatting">
Default Formatting</A>
<LI><A HREF="#SampleProgramDemonstratingDefaultFormatting">
Sample Program Demonstrating Default Formatting</A>
</UL>
<LI><A HREF="#AdditionstothewriteStatement">
Additions to the write Statement</A>
<UL>
<LI><A HREF="#SyntaxforthewriteStatement">
Syntax for the write Statement</A>
<LI><A HREF="#UnderstandingthePositionSpecification">
Understanding the Position Specification</A>
<LI><A HREF="#UnderstandingtheLengthSpecification">
Understanding the Length Specification</A>
<LI><A HREF="#WorkingwithSubfields">
Working with Subfields</A>
<LI><A HREF="#UsingtheunderAddition">
Using the under Addition</A>
<LI><A HREF="#UsingthenogapAddition">
Using the no-gap Addition</A>
<LI><A HREF="#UsingEditMasks">
Using Edit Masks</A>
<LI><A HREF="#UsingConversionExits">
Using Conversion Exits</A>
<LI><A HREF="#WorkingwithDateFormatting">
Working with Date Formatting</A>
<LI><A HREF="#UsingthenozeroandnosignAdditions">
Using the no-zero and no-sign Additions</A>
<LI><A HREF="#SpecifyingDecimalsandRounding">
Specifying Decimals and Rounding</A>
<LI><A HREF="#ShiftingJustification">
Shifting Justification</A>
</UL>
<LI><A HREF="#Summary">
 Summary</A>
<LI><A HREF="#QampABR">
Q&amp;A<BR>
</A>
<LI><A HREF="#Workshop">
Workshop</A>
<UL>
<LI><A HREF="#Quiz">
Quiz</A>
<LI><A HREF="#Exercise">
Exercise 1</A>
</UL></UL>

<HR>
<H2><A NAME="ChapterObjectives"><FONT SIZE=5 COLOR=#FF0000>
Chapter Objectives</FONT></A></H2>
<P>
After you complete this chapter, you will be able to:
<UL>
<LI>Understand the effect of data types on output
<LI>Use the formatting options of the <TT>write</TT> statement
<LI>Use conversion exits and detect their presence within domains
</UL>
<H2><A NAME="DefaultLengthsandFormatting"><FONT SIZE=5 COLOR=#FF0000>
Default Lengths and Formatting</FONT></A></H2>
<P>
If you do not specify any length or formatting options when you
use the <TT>write</TT> statement, the system uses a default format
and length based on the data type of each variable written. The
following sections describe these defaults.
<H3><A NAME="DefaultLengths">
Default Lengths</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
The <I>output length</I> of a field is the number of characters
used to display the value of that field. Output length is used
by the <TT>write</TT> statement to allocate space on the output
list for a field. Fields defined within a program via the <TT>data</TT>
statement have a default output length as shown in Table 14.1.
<BR>
<P>
<CENTER><B>Table 14.1&nbsp;&nbsp;ABAP/4 Data Type Determines the
Default Output Format and Length</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=48><CENTER><B>Data</B></CENTER></TD><TD WIDTH=96><CENTER><B>Justification</B></CENTER>
</TD><TD WIDTH=192><CENTER><B>Format</B></CENTER></TD><TD WIDTH=96><CENTER><B>Sign</B></CENTER>
</TD><TD WIDTH=144><CENTER><B>Dflt Output 
<BR>
Type Length</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>i</TT></TD><TD WIDTH=96>Right</TD><TD WIDTH=192>Zeros suppressed
</TD><TD WIDTH=96>Trailing</TD><TD WIDTH=144>11</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>p</TT></TD><TD WIDTH=96>Right</TD><TD WIDTH=192>Zeros suppressed
</TD><TD WIDTH=96>Trailing</TD><TD WIDTH=144>2*fldlen or (2*fldlen)+1
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>f</TT></TD><TD WIDTH=96>None</TD><TD WIDTH=192>Scientific notation
</TD><TD WIDTH=96>Leading</TD><TD WIDTH=144>22</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>n</TT></TD><TD WIDTH=96>Right</TD><TD WIDTH=192>Leading zeros shown
</TD><TD WIDTH=96>None</TD><TD WIDTH=144>fldlen</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>c</TT></TD><TD WIDTH=96>Left</TD><TD WIDTH=192>Leading blanks suppressed
</TD><TD WIDTH=96>&nbsp;</TD><TD WIDTH=144>fldlen</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>d</TT></TD><TD WIDTH=96>Left</TD><TD WIDTH=192>Determined by user defaults
</TD><TD WIDTH=96>&nbsp;</TD><TD WIDTH=144>8</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>t</TT></TD><TD WIDTH=96>Left</TD><TD WIDTH=192>HH:MM:SS
</TD><TD WIDTH=96>&nbsp;</TD><TD WIDTH=144>6</TD></TR>
<TR VALIGN=TOP><TD WIDTH=48><TT><CENTER>x</TT></TD><TD WIDTH=96>Left</TD><TD WIDTH=192>&nbsp;
</TD><TD WIDTH=96>&nbsp;</TD><TD WIDTH=144>2*fldlen</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Fields from the Data Dictionary have DDIC data types such as <TT>DEC</TT>,
<TT>CHAR</TT>, <TT>CURR</TT>, and so on. These are all based on
ABAP/4 data types and they inherit default length and format from
the ABAP/4 data type. To determine the ABAP/4 data type, and thus
the default output format, look up the ABAP/4 keyword documentation
for the <TT>tables</TT> statement. To do this, place your cursor
on a <TT>tables</TT> statement within your code and press the
F1 key.
<P>
In addition, DDIC fields have their output length and number of
decimals defined in the domain. These fields override the default,
and are shown in Figure 14.1.
<P>
<A HREF="javascript:popUp('f14-1.gif')"><B>Figure 14.1 :</B> <I>The Output Length and Decimal Places fields
override the defaults inherited from the ABAP/4 data types</I>.</A>
<P>
The output length and decimal places are inherited by all fields
that are created from a domain. For example, in Figure 14.1, the
field length is 15, indicating that 15 digits can be stored in
any field that uses this domain. The output length is 20, so the
output enables enough room for a decimal point, a sign, and three
thousands separators.
<H3><A NAME="PackedFields">
Packed Fields</A></H3>
<P>
The default output length of a type <TT>p</TT> field is twice
the defined field length. If decimal places are defined, the default
output length is increased by 1 so that it is 2 * field length
+ 1. Table 14.2 shows sample default output lengths for type <TT>p</TT>
fields.<BR>
<P>
<CENTER><B>Table 14.2&nbsp;&nbsp;Default Output Length for Packed
Decimal Fields</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=288><CENTER><B>Data Definition</B></CENTER></TD>
<TD WIDTH=192><CENTER><B>Default Output Length</B></CENTER></TD>
</TR>
<TR VALIGN=TOP><TD WIDTH=288><TT>data f1(4) type p.</TT> </TD><TD WIDTH=192><CENTER>8</CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=288><TT>data f2(4) type p decimals 2.</TT></TD>
<TD WIDTH=192><CENTER>9</CENTER></TD></TR>
<TR VALIGN=TOP><TD WIDTH=288><TT>data f3(5) type p.</TT></TD><TD WIDTH=192><CENTER>10</CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=288><TT>data f4(5) type p decimals 3</TT>.</TD>
<TD WIDTH=192><CENTER>11</CENTER></TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="DefaultFormatting">
Default Formatting</A></H3>
<P>
The default format is derived from the data type of the variable.
Table 14.1 described how the output will be formatted for each
ABAP/4 data type. The output of numeric fields (types <TT>p</TT>,
<TT>i</TT>, and <TT>f</TT>) is right-justified with leading zeros
suppressed and the rest are left-justified. Additional type-specific
formatting also applies.
<H4>Default Date Formatting</H4>
<P>
Date values are output according to the Date Format setting in
the User Defaults as long as the output length is 10 or greater.
The default output length is 8, so you must increase it to at
least 10 before the separators can be seen. Defining a variable
using <TT>like</TT> (for example, <TT>like sy-datum</TT>) causes
the output length to be taken from the domain.
<H4>Default Time Formatting</H4>
<P>
Time values are output in HH:MM:SS format as long as the output
length is 8 or greater. The default output length is 6, so you
must increase it to at least 8 before the separators can be seen.
Defining a variable using <TT>like</TT> (for example, <TT>like
sy-uzeit</TT>) causes the output length to be taken from the domain.
<H4>Default Numeric Formatting</H4>
<P>
The population of North America writes a number as 1,234.56. In
other countries, such as those in Europe, the same number is written
as 1.234,56-the use of the comma and decimal are interchanged.
R/3 enables each individual user to specify one of these formats
via the user profile setting Decimal Notation (from any screen,
choose the menu path System-&gt;User Profile-&gt;User Defaults).
<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>Caution</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
You must sign off and sign back on again to the R/3 system before changes to user defaults take effect.</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Table 14.3 shows the effect of the Decimal Notation setting on
numeric output.<BR>
<P>
<CENTER><B>Table 14.3&nbsp;&nbsp;Decimal Notation Setting in the
User Defaults Affects Numeric Output Formats</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><B>Setting</B></CENTER></TD><TD WIDTH=144><CENTER><B>Sample Output</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144>Comma</TD><TD WIDTH=144>1,234.56</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144>Period</TD><TD WIDTH=144>1.234,56</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
The default output format for floating-point (type <TT>f</TT>)
variables is via scientific notation. This can be modified by
using an edit mask or conversion exit.
<H4>Overflow Formatting</H4>
<P>
When dealing with numbers that are too big for the output field,
the system puts an asterisk in the first column of output to indicate
overflow. However, before that occurs, the system tries to output
all the digits, if possible. Thousands separators are only output
if there is enough room in the output field. If there isn't, they
are dropped one at a time beginning from the left of the field
and working to the right. If the number is positive and will fit
in the output by using the sign field, the system will use it.
<H3><A NAME="SampleProgramDemonstratingDefaultFormatting">
Sample Program Demonstrating Default Formatting</A></H3>
<P>
Listing 14.1 illustrates default length and formatting. It also
illustrates handling of numbers that are close to overflowing
the output field.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 14.1&nbsp;&nbsp;Default Formatting and Lengths<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1401.
2  data: t1    type t            value '123456',
3        t2    like sy-uzeit     value '123456',
4        d1    type d            value '19980201',
5        d2    like sy-datum     value '19980201',
6        f1    type f            value '-1234',
7        i1    type i            value '12345678-',
8        i2    type i            value '123456789-',
9        i3    type i            value '1123456789-',
10       i4    type i            value '1123456789',
11       n1(5) type n            value 123,
12       p1(5) type p            value '123456789-',
13       c1(5) type c            value 'ABC',
14       x1(2) type x value 'A0B0'.
15

⌨️ 快捷键说明

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