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

📄 ch07.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!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 7- Defining Data in ABAP/4, Part 1</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="../ch06/ch06.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch06/ch06.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="rev01.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch07/rev01.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;7</H1>
<H1>Defining Data in ABAP/4, Part 1</H1>


<UL>
<LI><A HREF="#ChapterObjectives">
Chapter Objectives</A>
<LI><A HREF="#ProgramBufferandtheRollArea">
Program Buffer and the Roll Area</A>
<LI><A HREF="#ElementsofABAPSyntax">
Elements of ABAP/4 Syntax</A>
<LI><A HREF="#DefiningDataObjects">
Defining Data Objects</A>
<UL>
<LI><A HREF="#DefiningLiterals">
Defining Literals</A>
<LI><A HREF="#DefiningVariables">
Defining Variables</A>
</UL>
<LI><A HREF="#Summary">
Summary</A>
<LI><A HREF="#QampA">
Q&amp;A</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 should be able to
<UL>
<LI>Explain the program's roll area and its contents.
<LI>Understand the elements of ABAP/4 syntax.
<LI>Describe the concept of data objects and their visibility.
<LI>Use literals and understand how to code each type.
<LI>Define and use constants.
<LI>Use the <TT>data</TT> statement to define variables and field
strings.
<LI>Understand ABAP/4 data types, and be able to identify the
character and numeric data types.
<LI>Understand the ABAP/4 definition of common DDIC data types.
</UL>
<P>
Before proceeding, please turn to Day 2 and take a few minutes
to re-read the analysis in the section &quot;Understanding Code
Syntax&quot; now.
<H2><A NAME="ProgramBufferandtheRollArea"><FONT SIZE=5 COLOR=#FF0000>
Program Buffer and the Roll Area</FONT></A></H2>
<P>
Programs are buffered on the application server in a <I>program
buffer</I>. When a user makes a request to run a program, a search
is done in the program buffer for it. If it is found, and if it
has not been modified in the database, the buffered copy is used.
If not, or if the copy in the database is newer, the program is
reloaded.
<P>
A separate copy of the program is not made in memory for each
user who executes it. Instead, all users execute the same copy
of the program. The differentiating factor is a separate memory
allocation called a <I>roll area.</I> One roll area is allocated
per execution per user per program. The system uses the roll area
to hold all information about the current execution of the program
and all memory allocations. Information such as the variables
and their values, the current program pointer, and the list output
are all kept in the roll area. For example, suppose a user executes
a program and a roll area is allocated. If, without waiting for
it to finish, the user switches to another session and starts
up the same program again, another roll area is allocated for
the second execution of that program. The user has two roll areas,
one for each execution of the program. If the user had instead
run a different program, he would still have two roll areas, one
for each program.
<H2><A NAME="ElementsofABAPSyntax"><FONT SIZE=5 COLOR=#FF0000>
Elements of ABAP/4 Syntax</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
Each ABAP/4 program is composed of one or more statements. Each
statement contains one or more words separated by at least one
space. The first word of a statement is the keyword. A statement
can include one or more <I>additions</I>, and always ends with
a period.
<P>
In Listing 7.1, the keywords are <TT>select</TT>, <TT>write</TT>,
and <TT>endselect</TT>. Two additions appear on the <TT>select</TT>
statement: <TT>where</TT> and <TT>order by</TT>. What is normally
called a <I>clause</I> in other languages is called an <I>addition</I>
in ABAP/4: It is any word or group of words after the keyword
that modifies the behavior of the statement.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 7.1&nbsp;&nbsp;Illustration of Basic ABAP/4 Syntax
<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 select * from ztxlfa1 where lifnr &gt; '0000001050' order by lifnr.
2     write: \ ztxlfa1-lifnr, ztxlfa1-name1, ztxlfa1-land1.
3     endselect.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
A statement can begin in any column and can span any number of
lines. To continue a statement on another line, break the statement
between any two words. A continuation character is not needed.
For example, the code in Listing 7.1 can be reformatted as shown
in Listing 7.2.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 7.2&nbsp;&nbsp;This Code Is the Same as Listing 7.1,
Only It Has Been Formatted Differently<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 select * from ztxlfa1
2     where lifnr &gt; '0000001050'
3     order by lifnr.
4     write: \ ztxlfa1-lifnr,
5              ztxlfa1-name1,
6              ztxlfa1-land1. endselect.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
ABAP/4 code is not case sensitive.
<H2><A NAME="DefiningDataObjects"><FONT SIZE=5 COLOR=#FF0000>
Defining Data Objects</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
<I>Data objects </I>are memory locations that you use to hold
data while the program is running. There are two types of data
objects: modifiable and non-modifiable. The types of non-modifiable
data objects are literals and constants. The modifiable data objects
are variables, field strings, and internal tables. A field string
is the ABAP/4 equivalent of a structure. An internal table is
the ABAP/4 equivalent of an array.
<P>
When the program starts, the memory allocation for each data object
occurs in the roll area of the program. While the program is running,
you can read the contents of a non-modifiable data object or put
data into a modifiable data object and then retrieve it. When
the program ends, the system frees the memory for all data objects
and their contents are lost.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
Data objects have three levels of <I>visibility: </I>local, global,
and external. The visibility of a data object indicates from where
in the program the data object is accessible.
<P>
Locally visible data objects are accessible only from inside the
subroutine in which they are defined. Globally visible objects
can be accessed from anywhere within the program. Externally visible
objects are accessible from outside of the program by another
program. Figure 7.1 displays these three levels of visibility
pictorially.
<P>
<A HREF="javascript:popUp('f7-1.gif')"><B>Figure 7.1 :</B> <I>The visibility of a data object indicates
its accessibility. If it is locally visible, it is only accessible
from within a subroutine. If it is globally visible, it is accessible
from any-where within a program. If it is externally visible,
it is accessible from outside of the program by another program</I>.</A>
<P>
In Figure 7.1, the local data objects in subroutine 1A are visible
only from within that subroutine. Any statement outside of it
cannot access them. Similarly, the local data objects in subroutines
1B and 2A are not accessible from anywhere but within those subroutines.
<P>
Any statement in program 1, regardless of where the statement
appears, can access the global data objects in program 1. Similarly,
any statement in program 2 can access the global data objects
in program 2.
<P>
The external data objects could be accessed from any statement
in program 1 or program 2. In actuality, whether they can be or
not depends on the type of external memory area used and the relationship
between the two programs. The details of this are described in
the sections on SPA/GPA memory and on ABAP/4 memory.
<H3><A NAME="DefiningLiterals">
Defining Literals</A></H3>
<P>
A <I>literal</I> is a non-modifiable data object. Literals can
appear anywhere in a program, and they are defined merely by typing
them where needed. There are four types: character string, numeric,
floating-point, and hexadecimal.
<H4>Character String Literals</H4>
<P>
<I>Character string literals</I> are case-sensitive character
strings of any length enclosed within single quotes. For example,
<TT>'JACK'</TT> is a character string literal containing only
uppercase characters. <TT>'Caesar the cat'</TT> is a character
string literal containing a mixture of upper- and lowercase characters.
Your first program used the character string literal <TT>'Hello
SAP world'</TT>.
<P>
Because a character string literal is enclosed by quotes, you
cannot use a single quote by itself in the value of the literal.
To represent a single quote, you must use two consecutive single
quotes. For example, the statement <TT>write 'Caesar''s tail'.</TT>
will write <TT>Caesar's tail</TT>, but the statement <TT>write
'Caesar's tail'</TT> will cause a syntax error because it contains
a single quote by itself. The statement <TT>write ''''.</TT> will
cause a single quote to be written to the output page because
the two consecutive quotes within quotes are translated to a single
quote. Lastly, <TT>write: '''', 'Hello Caesar', ''''.</TT> will
write <TT><B>' Hello Caesar '</B>.</TT>
<P>
Here are some examples of invalid character string literals and
the correct way to code them. <TT>&quot;Samantha&quot;</TT> is
incorrect; it should be enclosed in single quotes, not double
quotes, and thus should be coded <TT>'Samantha'</TT>. In <TT>'Never
ending</TT>, the trailing quote is missing and thus should be
coded <TT>'Never ending'</TT>. <TT>'Don't bite'</TT> should contain
two consecutive single quotes; it should be coded <TT>'Don''t
bite'</TT>.<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>CAUTION</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
When a literal is involved in a comparison, as a rule of thumb you should always use uppercase between quotes. Comparisons with character string lit-erals are always case sensitive, so it is necessary to ensure you use the correct case to get the intended result. If the case doesn't match, usually the pro-gram will still run, but you will get either incorrect output or no output at all. 99.99 percent of the time, the values your character string literal will be compared with will be in uppercase. Therefore, always type the value for a character string literal in uppercase unless you <I>know </I>that it should be other-wise. For example, <TT>select single * from ztxlfa1 where lifnr = 'v1' </TT>will not find a record, but <TT>select single * from ztxlfa1 where lifnr = 'V1' </TT>will find a record. Did you notice the lowercase <TT>v</TT>?
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H4>Numeric Literals</H4>
<P>
<I>Numeric literals</I> are hard-coded numeric values with an
optional leading sign. They are not usually enclosed in quotes.
However, if a numeric literal contains a decimal, it must be coded
as a character string enclosed within single quotes. If it is
not, the syntax error <TT>Statement <I>x</I>
is not defined. Please check your spelling.</TT> will occur. Table
7.1 shows the right and wrong ways to code literals.
<P>
For example, <TT>256</TT> is a numeric literal, as is <TT>-99</TT>.
<TT>'10.5'</TT> is a numeric literal that contains a decimal point,
so it is enclosed by single quotes. A literal can be used as the
default value for a variable, or it can be used to supply a value
in a statement. Examples of invalid literals are: <TT>99-</TT>
(trailing minus sign), <TT>&quot;Confirm&quot;</TT> (enclosed
in double quotes), and <TT>2.2</TT> (contains a decimal but is
not enclosed in quotes).
<H4>Floating-Point Literals</H4>
<P>
<I>Floating-point literals</I> are specified within single quotes
as <TT>'&lt;mantissa&gt;E&lt;exponent&gt;'</TT>. The <TT>mantissa</TT>
can be specified with a leading sign and with or without decimal
places, and the <TT>exponent</TT> can be signed or unsigned, with
or without leading zeros. For example, <TT>'9.99E9'</TT>, <TT>'-10E-32'</TT>,
and <TT>'+1E09'</TT> are valid floating-point literals.
<H4>Hexadecimal Literals</H4>
<P>
A <I>hexadecimal literal</I> is specified within single quotes
as if it were a character string. The permissible values are <TT>0</TT>-<TT>9</TT>
and <TT>A</TT>-<TT>F</TT>. There must be an even number of characters
in the string, and all characters <I>must be in uppercase</I>.
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>CAUTION</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
If you specify a hexadecimal literal using lowercase characters, you will not receive any warnings or errors. However, when your program runs, the value of the literal will be wrong.</BLOCKQUOTE>

</TD></TR>
</TABLE>

⌨️ 快捷键说明

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