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

📄 ch07.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 4 页
字号:
millisecond precision. To obtain these, use the <TT>get run time</TT>
statement and store them using data type <TT>i</TT>. See the chapter
on runtime analysis for more details.
</BLOCKQUOTE>
<H5>Numeric Data Types</H5>
<BLOCKQUOTE>
The numeric data types are shown in Table 7.3. A dash in the Max
Length column indicates the length cannot be changed. An asterisk
indicates the attribute is machine-dependent.<BR>
</BLOCKQUOTE>
<P>
<CENTER><B>Table 7.3&nbsp;&nbsp;Numeric Data Types </B></CENTER><CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=86>
<BR>
<B>Data<BR>
<B>Type</B></B></TD><TD WIDTH=86><BR>
<BR>
<B>Description</B>
</TD><TD WIDTH=86><B>Default <BR>
Internal<BR>
Length</B></TD>
<TD WIDTH=86><BR>
<B>Max<BR>
Length</B></TD><TD WIDTH=86><BR>
<B>Max<BR>
Decimals</B>
</TD><TD WIDTH=86><BR>
<B>Valid <BR>
Values</B></TD><TD WIDTH=86><B>Default <BR>
Initial <BR>
Value</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=86><CENTER><TT>i</TT></CENTER></TD><TD WIDTH=86>integer
</TD><TD WIDTH=86><CENTER>4(fixed)</CENTER></TD><TD WIDTH=86><CENTER>-</CENTER>
</TD><TD WIDTH=86><CENTER>0</CENTER></TD><TD WIDTH=86>-231 to +231
</TD><TD WIDTH=86><CENTER>0</CENTER></TD></TR>
<TR VALIGN=TOP><TD WIDTH=86><CENTER><TT>p</TT></CENTER></TD><TD WIDTH=86>packed decimal
</TD><TD WIDTH=86><CENTER>8</CENTER></TD><TD WIDTH=86><CENTER>16</CENTER>
</TD><TD WIDTH=86><CENTER>14</CENTER></TD><TD WIDTH=86>0-9 .</TD>
<TD WIDTH=86><CENTER>0</CENTER></TD></TR>
<TR VALIGN=TOP><TD WIDTH=86><CENTER><TT>f</TT></CENTER></TD><TD WIDTH=86>floating-point
</TD><TD WIDTH=86><CENTER>8</CENTER></TD><TD WIDTH=86><CENTER>8</CENTER>
</TD><TD WIDTH=86><CENTER>15*</CENTER></TD><TD WIDTH=86>-1E-307 to 1E308
</TD><TD WIDTH=86><CENTER>0.0</CENTER></TD></TR>
</TABLE>
</CENTER>
<P>
<BLOCKQUOTE>
All of the variables in Table 7.3 are signed. In floating-point
variables, the exponent is also signed.
</BLOCKQUOTE>
<BLOCKQUOTE>
Use integers for variables that will be involved in simple computations
or when no decimal points are required. Variables such as counters,
indexes, positions, or offsets are good examples.
</BLOCKQUOTE>
<BLOCKQUOTE>
A decimal variable stores <TT>(L*2)-1</TT> digits, where <TT>L</TT>
is the length of the variable in bytes. Decimal values are stored
two digits per byte, except the end byte, which contains a single
digit and a sign. The decimal point itself is not stored; it is
an attribute of the definition. For example, <TT>data f1(4) type
p</TT> defines a variable <TT>f1</TT> that is four bytes long
and can hold seven digits (plus a sign), as shown in Figure 7.2.
<TT>data f2(3) type p decimals 2</TT> defines a variable <TT>f2</TT>
that is three bytes long and can hold five digits (plus a sign).
The definition <TT>data f3 type p</TT> defines a variable <TT>f3</TT>
capable of holding 15 digits because the default length for type
<TT>p</TT> is 8.
</BLOCKQUOTE>
<P>
<A HREF="javascript:popUp('f7-2.gif')"><B>Figure 7.2 :</B> <I>Packed decimal values are stored two digits
per byte. The end byte is an exception; it stores a single digit
and the sign. The decimal point is not stored and so does not
take up any space in the field; it is part of the definition</I>.</A>
<BLOCKQUOTE>
Floating-point variables are always approximate. They can be used
for calculations requiring very large values or many decimal places.
Precision up to 15 decimal places is possible, but this is hardware-dependent.
<BR>
</BLOCKQUOTE>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>CAUTION</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Be careful when you specify initial values on the <TT>data </TT>statement using the <TT>value </TT>addition. These values are not validated to see whether they are com-patible with the data type. Using the <TT>value </TT>addition, you can assign invalid values to integers, date and time variables, numeric text, packed decimal variables, or floating-point variables, either accidentally or intentionally. The results of this assignment are machine-dependent and are undefined.
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<BLOCKQUOTE>
</BLOCKQUOTE>
<H5>Mapping DDIC Data Types to ABAP/4 Data Types</H5>
<BLOCKQUOTE>
Data types in the Data Dictionary are built from the ABAP/4 data
types. Table 7.4 shows common Data Dictionary data types and their
corresponding ABAP/4 data definitions. <TT>L</TT> is the length
specified in the domain. For a complete list, view the F1 help
for the <TT>tables</TT> statement.<BR>
</BLOCKQUOTE>
<P>
<CENTER><B>Table 7.4&nbsp;&nbsp;Data Dictionary Data Types and
Their Corresponding ABAP/4 Data Types</B></CENTER><CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><B>DDIC
<BR>
<B>Data Type</B></B></CENTER>
</TD><TD WIDTH=192><CENTER><B>Description</B></CENTER></TD><TD WIDTH=192><CENTER><B>ABAP/4<BR>
Data Definition</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>char</TT></CENTER></TD><TD WIDTH=192>Character
</TD><TD WIDTH=192><TT>c(L)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>clnt</TT></CENTER></TD><TD WIDTH=192>Client
</TD><TD WIDTH=192><TT>c(3)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>dats</TT></CENTER></TD><TD WIDTH=192>Date
</TD><TD WIDTH=192><TT>d</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>tims</TT></CENTER></TD><TD WIDTH=192>Time
</TD><TD WIDTH=192><TT>t</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>cuky</TT></CENTER></TD><TD WIDTH=192>Currency key
</TD><TD WIDTH=192><TT>c(5)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>curr</TT></CENTER></TD><TD WIDTH=192>Currency
</TD><TD WIDTH=192><TT>p((L+2)/2)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>dec</TT></CENTER></TD><TD WIDTH=192>Decimal
</TD><TD WIDTH=192><TT>p((L+2)/2)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>fltp</TT></CENTER></TD><TD WIDTH=192>Floating-point
</TD><TD WIDTH=192><TT>f</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>int1</TT></CENTER></TD><TD WIDTH=192>1-byte integer
</TD><TD WIDTH=192>(none)</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>int2</TT></CENTER></TD><TD WIDTH=192>2-byte integer
</TD><TD WIDTH=192>(none)</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>int4</TT></CENTER></TD><TD WIDTH=192>4-byte integer
</TD><TD WIDTH=192><TT>I</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>lang</TT></CENTER></TD><TD WIDTH=192>Language
</TD><TD WIDTH=192><TT>c(1)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>numc</TT></CENTER></TD><TD WIDTH=192>Numeric text
</TD><TD WIDTH=192><TT>n(L)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>prec</TT></CENTER></TD><TD WIDTH=192>Precision
</TD><TD WIDTH=192><TT>x(2)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>quan</TT></CENTER></TD><TD WIDTH=192>Quantity
</TD><TD WIDTH=192><TT>p((L+2)/2)</TT></TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><TT>unit</TT></CENTER></TD><TD WIDTH=192>Units
</TD><TD WIDTH=192><TT>c(L)</TT></TD></TR>
</TABLE>
</CENTER>
<P>
<H4>Using the <TT>parameters</TT> Statement to Define Variables
</H4>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
A parameter is a special type of variable that is defined using
the <TT>parameters</TT> statement. <TT>parameters</TT> is a lot
like the <TT>data</TT> statement, but when you run the program,
the system will display the parameters as input fields on a <I>selection
screen</I> before the program actually begins to execute. The
user can enter or modify their values and then press the Execute
button to begin program execution. You can use both <TT>parameters</TT>
and <TT>data</TT> in the same program. The rules for parameter
names are the same as for variable names, except for the following:
<UL>
<LI>The maximum length is 8 characters instead of 30.
<LI>In addition to literals and constants, you can also use a
variable to supply default a default value.
</UL>
<H5>Syntax for the parameters Statement</H5>
<BLOCKQUOTE>
The following code is the syntax for defining a variable using
the <TT>parameters</TT> statement.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>
parameters <I>p1</I>[(<I>l</I>)] [type <I>t</I>] [decimals <I>d</I>] ...
</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE>
or
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>
parameters <I>p1</I> like <I>v1</I> ...
... [default '<I>xxx</I>'] [obligatory] [lower case] [as checkbox] [radiobutton
    group <I>g</I>].
</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE>
where:

<UL>
<LI><TT><I>p1</I></TT> is the
parameter name.
<LI><TT><I>v1</I></TT> is the
name of a previously defined variable or parameter, or is the
name of a field that belongs to a table or structure in the Data
Dictionary.
<LI><TT>(<I>l</I>)</TT> is the
internal length specification.
<LI><TT><I>t</I></TT> is the data
type.
<LI><TT><I>d</I></TT> is the number
of decimal places (used only with type <TT>p</TT>).
<LI><TT>'<I>xxx</I>'</TT> is a
literal or previously defined variable that supplies a default
value.
</UL>

Listing 7.5 shows examples of parameters defined with the <TT>parameters</TT>
statement.<BR>
</BLOCKQUOTE>
<BLOCKQUOTE>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
</BLOCKQUOTE>
<HR>
<P>
<B>Listing 7.5&nbsp;&nbsp;Examples of Parameters Defined Using
the </B><TT><B>PARAMETERS</B></TT><B>
Statement<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 parameters p1(2) type c.
2 parameters p2 like p1.
3 parameters max_value type i default 100.
4 parameters cur_date type d default '19980211' obligatory.
5 parameters cur_date like sy-datum default sy-datum obligatory.
</PRE>
</BLOCKQUOTE>
<HR>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
There are two variations of the <TT>parameters </TT>statement: <TT>parameter </TT>and <TT>para-meters</TT>. Operationally, there is no difference between the two; they are completely interchangeable. However, if you attempt to obtain F1 help on the <TT>parameter </TT>statement, none will be found. For this reason, I recommend that you use only the <TT>parameters </TT>statement.
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<BLOCKQUOTE>
A sample program using <TT>parameters</TT> is given in Listing
7.6, and the input screen it generates appears in Figure 7.3.
Please run this report now.<BR>
</BLOCKQUOTE>
<P>
<A HREF="javascript:popUp('f7-3.gif')"><B>Figure 7.3 :</B> <I>When you run report ztx0706, the parameters
first appear on a selection screen. Obligatory parameters are
indicated with question marks. To begin processing, the user must
press the Execute button on the Application toolbar</I>.</A><BR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 7.6&nbsp;&nbsp;Example of a Program That Accepts Input
Parameters Using the </B><TT><B>PARAMETERS</B></TT><B>
Statement<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx0706.
2  parameters: p1(15) type c,
3              p2  like p1 obligatory lower case,
4              p3  like sy-datum default sy-datum,
5              cb1 as checkbox,
6              cb2 as checkbox,
7              rb1 radiobutton group g1 default 'X',
8              rb2 radiobutton group g1,
9              rb3 radiobutton group g1.
10  write: / 'You entered:',
11         / '  p1 =', p1,
12         / '  p2 =', p2,
13         / '  p3 =', p3,
14         / '  cb1=', cb1,
15         / '  cb2=', cb2,
16         / '  rb1=', rb1,
17         / '  rb2=', rb2,
18         / '  rb3=', rb3.
</PRE>
</BLOCKQUOTE>
<HR>
<BLOCKQUOTE>
The additions to the <TT>parameters</TT> statement are described
in Table 7.5.<BR>
</BLOCKQUOTE>
<P>
<CENTER><B>Table 7.5&nbsp;&nbsp;Additions to the </B><TT><B>PARAMETERS</B></TT><B>
Statement and Their Uses</B></CENTER><CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=144><CENTER><B>Addition</B></CENTER></TD><TD WIDTH=336><CENTER><B>Use</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>type</TT></TD><TD WIDTH=336>Same as the <TT>data</TT> statement.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>Decimals</TT></TD><TD WIDTH=336>Same as the <TT>data</TT> statement.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>Like</TT></TD><TD WIDTH=336>Same as the <TT>data</TT> statement.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>Default</TT></TD><TD WIDTH=336>Same as the <TT>value</TT> addition on the data statement.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>Obligatory</TT></TD><TD WIDTH=336>The user must enter a value into the field before the program will execute.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>lower case</TT></TD><TD WIDTH=336>Prevents values from being translated into uppercase.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>as checkbox</TT></TD><TD WIDTH=336>Displays the input field as a check box.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT>Radiobutton group </TT><U><I>g</I></U></TD>
<TD WIDTH=336>Displays the input field as a radio button belonging to group <I>g.</I>
</TD></TR>
</TABLE>
</CENTER>
<P>
<BLOCKQUOTE>
The following points also apply to the <TT>parameters</TT> statement:
</BLOCKQUOTE>
<BLOCKQUOTE>
When the selection screen is shown, obligatory fields contain
a question mark. These indicate to the user which fields must
be filled in before continuing.

<UL>
<LI>The default data type is <TT>c</TT> (character).
<LI>The default value is <TT>0</TT>, except for data type <TT>c</TT>,
which is blank.
<LI>The <TT>value</TT> addition accepts a literal, a <TT>sy</TT>
variable, or a variable previously defined in the program.
<LI>When using the <TT>like</TT> addition, the parameter being
defined obtains its length and data type from the referenced variable.
You cannot specify them on the same statement with <TT>like</TT>.

⌨️ 快捷键说明

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