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

📄 ch10.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 10- Common Control Statements</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="../ch09/ch09.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch09/ch09.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="../ch11/ch11.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch11/ch11.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;10</H1>
<H1>Common Control Statements</H1>


<UL>
<LI><A HREF="#ChapterObjectives">
Chapter Objectives</A>
<LI><A HREF="#UsingtheTTFONTSIZEifFONTTTFONTSIZEStatementFONT">
Using the <TT>if</TT> Statement
</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEifFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>if</TT>
Statement</A>
<LI><A HREF="#DataConversionofLiteralsDuringComparisons">
Data Conversion of Literals During Comparisons</A>
<LI><A HREF="#DisplayingConversions">
Displaying Conversions</A>
<LI><A HREF="#UsingTTFONTSIZEelseifFONTTT">
Using <TT>elseif</TT></A>
<LI><A HREF="#UsingCharacterStringOperators">
Using Character String Operators</A>
</UL>
<LI><A HREF="#UsingtheTTFONTSIZEcaseFONTTTFONTSIZEStatementFONT">
Using the <TT>case</TT> Statement
</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEcaseFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>case</TT>
Statement</A>
</UL>
<LI><A HREF="#UsingtheTTFONTSIZEexitFONTTTFONTSIZEStatementFONT">
Using the <TT>exit</TT> Statement
</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEexitFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>exit</TT>
Statement</A>
</UL>
<LI><A HREF="#UsingtheTTFONTSIZEdoFONTTTFONTSIZEStatementFONT">
Using the <TT>do</TT> Statement
</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEdoFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>do</TT>
Statement</A>
<LI><A HREF="#TerminatinganEndlessLoop">
Terminating an Endless Loop</A>
<LI><A HREF="#UsingtheTTFONTSIZEvaryingFONTTTFONTSIZEAdditionFONT">
Using the <TT>varying</TT>
Addition</A>
<LI><A HREF="#ModifyingValueswithinTTFONTSIZEdovaryingenddoFONTTT">
Modifying Values within <TT>do ... varying/enddo</TT>
</A>
</UL>
<LI><A HREF="#UsingtheTTFONTSIZEwhileFONTTTFONTSIZEStatementFONT">
Using the <TT>while</TT>
Statement</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEwhileFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>while</TT>
Statement</A>
</UL>
<LI><A HREF="#UsingtheTTFONTSIZEcontinueFONTTTFONTSIZEstatementFONT">
Using the <TT>continue</TT>
statement</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEcontinueFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>continue</TT>
Statement</A>
</UL>
<LI><A HREF="#UsingtheTTFONTSIZEcheckFONTTTFONTSIZEstatementFONT">
Using the <TT>check</TT>
statement</A>
<UL>
<LI><A HREF="#SyntaxfortheTTFONTSIZEcheckFONTTTFONTSIZEStatementFONT">
Syntax for the <TT>check</TT>
Statement</A>
</UL>
<LI><A HREF="#ComparingtheTTFONTSIZEexitFONTTTFONTSIZEFONTTTFONTSIZEcontinueFONTTTFONTSIZEandFONTTTFONTSIZEcheckFONTTTFONTSIZEStatementsFONT">
Comparing the <TT>exit</TT>,
<TT>continue</TT>, and
<TT>check</TT> Statements
</A>
<LI><A HREF="#SimplePositionandLengthSpecificationsfortheTTFONTSIZEwriteFONTTTFONTSIZEStatementFONT">
Simple Position and Length Specifications for the <TT>write</TT>
Statement</A>
<UL>
<LI><A HREF="#SyntaxforSimplePositionandLengthSpecificationsontheTTFONTSIZEwriteFONTTTFONTSIZEStatementFONT">
Syntax for Simple Position and Length Specifications on the
<TT>write</TT> Statement
</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 should be able to:
<UL>
<LI>Code the common control statements <TT>if</TT>, <TT>case</TT>,
<TT>do</TT>, and <TT>while</TT>
<LI>Control program sequence using <TT>exit</TT>, <TT>continue</TT>,
and <TT>check</TT>
<LI>Code simple position and length specifications on the <TT>write</TT>
statement
</UL>
<H2><A NAME="UsingtheTTFONTSIZEifFONTTTFONTSIZEStatementFONT"><FONT SIZE=5 COLOR=#FF0000>
Using the <TT><FONT SIZE=5>if</FONT></TT><FONT SIZE=5> Statement</FONT>
</FONT></A></H2>
<P>
The <TT>if</TT> statement in ABAP/4 has relational operators for
equality and inequality and special relational operators for string
comparisons and for bit masks.<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Bit comparisons are not often used in ABAP/4 and so they are not presented here. They are, however, detailed in the ABAP/4 keyword documentation under the heading &quot;Relational Operators for Bit Masks.&quot;</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="SyntaxfortheTTFONTSIZEifFONTTTFONTSIZEStatementFONT">
Syntax for the <TT><FONT SIZE=4>if</FONT></TT><FONT SIZE=4>
Statement</FONT></A></H3>
<P>
The following is the syntax for the <TT>if</TT> statement.
<BLOCKQUOTE>
<PRE>
if [not] <I>exp</I> [ and [not] <I>exp</I> ] [ or [not] <I>exp</I> ].
    ---
[elseif <I>exp</I>.
    ---]
[else.
    ---]
    endif.
</PRE>
</BLOCKQUOTE>
<P>
where:
<UL>
<LI><TT><I>exp</I></TT> is a logical
expression that evaluates to a true or false condition.
<LI><TT>---</TT> represents any number of lines of code. Even
zero lines are allowed.
</UL>
<P>
The following points apply:
<UL>
<LI>Every <TT>if</TT> must have a matching <TT>endif</TT>.
<LI><TT>else</TT> and <TT>elseif</TT> are optional.
<LI>Parentheses can be used. Each parentheses must be separated
by a space. For example, <TT>if ( f1 = f2 ) or ( f1 = f3 )</TT>
is correct, and <TT>if (f1 = f2) or (f1 = f3)</TT> is incorrect.
<LI>Variables can be compared with blanks or zeros using the addition
<TT>is initial</TT>. For example, <TT>if f1 is initial</TT> will
be true if <TT>f1</TT> is type <TT>c</TT> and is blank. If <TT>f1</TT>
is any other data type, the statement is true if <TT>f1</TT> contains
zeros.
<LI>To accomplish negation, <TT>not</TT> must <I>precede</I> the
logical expression. For example, <TT>if not f1 is initial</TT>
is correct. <TT>if f1 is not initial</TT> is incorrect.
<LI>Variables can be compared with nulls using the addition <TT>is
null</TT>. For example, <TT>if f1 is null</TT>.
</UL>
<P>
The logical operators for operands of any type are listed in Table
10.1.<BR>
<P>
<CENTER><B>Table 10.1&nbsp;&nbsp;Common Comparisons and Their
Alternate Forms</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=144><BR>
<CENTER><B>Comparison</B></CENTER></TD>
<TD WIDTH=144><CENTER><B>Alternate<BR>
Forms</B></CENTER></TD>
<TD WIDTH=192><CENTER><B>True When</B></CENTER></TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> = <I>v2</I></TT>
</TD><TD WIDTH=144><TT>EQ</TT></TD><TD WIDTH=192><TT><I>v1</I></TT> equals <TT><I>v2</I></TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> &lt;&gt; <I>v2</I></TT>
</TD><TD WIDTH=144><TT>NE</TT>, <TT>&gt;&lt;</TT></TD><TD WIDTH=192><TT><I>v1</I></TT> does not equal <TT><I>v2</I></TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> &gt; <I>v2</I></TT>
</TD><TD WIDTH=144><TT>GT</TT></TD><TD WIDTH=192><TT><I>v1</I></TT> is greater than <TT><I>v2</I></TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> &lt; <I>v2</I></TT>
</TD><TD WIDTH=144><TT>LT</TT></TD><TD WIDTH=192><TT><I>v1</I></TT> is less than <TT><I>v2</I></TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> &gt;= <I>v2</I></TT>
</TD><TD WIDTH=144><TT>GE</TT>, <TT>=&gt;</TT></TD><TD WIDTH=192><TT><I>v1</I></TT> is greater than or equal to <TT><I>v2</I></TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> &lt;= <I>v2</I></TT>
</TD><TD WIDTH=144><TT>LE</TT>, <TT>=&lt;</TT></TD><TD WIDTH=192><TT><I>v1</I></TT> is less than or equal to <TT><I>v2</I></TT>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>v1</I> between <I>v2</I> and <I>v3</I></TT>
</TD><TD WIDTH=144>&nbsp;</TD><TD WIDTH=192><TT><I>v1</I></TT> lies between <TT><I>v2</I></TT> and <TT><I>v3</I></TT> (inclusive)
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=144><TT><I>not v1</I> between <I>v2</I> and <I>v3</I></TT>
</TD><TD WIDTH=144>&nbsp;</TD><TD WIDTH=192><TT><I>v1</I></TT> lies outside of the range <TT><I>v2</I></TT> to <TT><I>v3</I></TT> (inclusive)
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
In Table 10.1, <TT><I>v1</I></TT>
and <TT><I>v2</I></TT> can be
variables, literals, or field strings. In the case of variables
or literals, automatic conversion is performed if the data type
or length does not match. Field strings are treated as type <TT>c</TT>
variables.
<P>
Comparing two values that do not have the same data type will
result in an internal automatic type adjustment of one or both
of the values. One type will take precedence and will dictate
what type of conversion is performed. The order of precedence
is:
<UL>
<LI>If one field is type <TT>f</TT>, the other is converted to
type <TT>f</TT>.
<LI>If one field is type <TT>p</TT>, the other is converted to
type <TT>p</TT>.
<LI>If one field is type <TT>i</TT>, the other is converted to
type <TT>i</TT>.
<LI>If one field is type <TT>d</TT>, the other is converted to
type <TT>d</TT>. Types <TT>c</TT> and <TT>n</TT>, however, are
not converted. They are compared directly.
<LI>If one field is type <TT>t</TT>, the other is converted to
type <TT>t</TT>. Types <TT>c</TT> and <TT>n</TT>, however, are
not converted. They are compared directly.
<LI>If one field is type <TT>n</TT>, <I>both</I> are converted
to type <TT>p</TT> (at this point, the other field can only be
type <TT>c</TT> or <TT>x</TT>).
<LI>At this point, one field will be type <TT>c</TT> and the other
will be type <TT>x</TT>. <TT>x</TT> is converted to type <TT>c</TT>.
</UL>
<P>
Conversions follow the same rules as those performed by the <TT>move</TT>
statement. Type conversions are fully detailed in the ABAP/4 keyword
documentation under the heading &quot;Relational Operators for
All Data Types.&quot;
<H3><A NAME="DataConversionofLiteralsDuringComparisons">
Data Conversion of Literals During Comparisons</A></H3>
<P>
Literals are stored internally with data types, as shown in Table
10.2.<BR>
<P>
<CENTER><B>Table 10.2&nbsp;&nbsp;Data Types of Literals</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=240><CENTER><B>Description</B></CENTER></TD><TD WIDTH=96><CENTER><B>Data Type</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240>Numbers one to nine digits long</TD><TD WIDTH=96><CENTER><TT>i</TT></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240>Numbers 10 or more digits long</TD><TD WIDTH=96><CENTER><TT>p</TT></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240>All others</TD><TD WIDTH=96><CENTER><TT>c</TT></CENTER>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Type conversions for literals follow the same order of precedence
and the same conversion rules apply.
<P>
Listing 10.1 shows a sample program using the common comparison
operators. A surprising conversion is also demonstrated.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 10.1&nbsp;&nbsp;An Example of Using </B><TT><B>IF</B></TT><B>
in the Program<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  report ztx1001.
2  data: begin of s1,
3            x value 'X',
4            y value 'Y',
5            z value 'Z',

⌨️ 快捷键说明

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