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

📄 ch12.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 12- Advanced Internal Tables, 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="../ch11/ch11.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch11/ch11.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="../ch13/ch13.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch13/ch13.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;12</H1>
<H1>Advanced Internal Tables, Part 1</H1>


<UL>
<LI><A HREF="#ChapterObjectives">
Chapter Objectives</A>
<LI><A HREF="#TestingandModifyingInternalTableContents">
Testing and Modifying Internal Table Contents</A>
<LI><A HREF="#ObtainingInformationaboutanInternalTable">
Obtaining Information about an Internal Table</A>
<UL>
<LI><A HREF="#DeterminingWhetheranInternalTableIsEmpty">
Determining Whether an Internal Table Is Empty</A>
<LI><A HREF="#DeterminingtheNumberofRowsinanInternalTable">
Determining the Number of Rows in an Internal Table</A>
<LI><A HREF="#SampleProgramthatObtainsInformationAboutanInternalTable">
Sample Program that Obtains Information About an Internal
Table</A>
</UL>
<LI><A HREF="#CopyingDatafromoneInternalTabletoAnother">
Copying Data from one Internal Table to Another</A>
<UL>
<LI><A HREF="#CopyingaPortionofanInternalTable">
Copying a Portion of an Internal Table</A>
<LI><A HREF="#SampleProgramthatCopiesDataBetweenInternalTables">
Sample Program that Copies Data Between Internal Tables</A>
<LI><A HREF="#ComparingtheContentsofTwoInternalTables">
Comparing the Contents of Two Internal Tables</A>
</UL>
<LI><A HREF="#UsingtheeditorcallStatement">
Using the editor-call Statement</A>
<UL>
<LI><A HREF="#SyntaxfortheeditorcallStatement">
Syntax for the editor-call Statement</A>
</UL>
<LI><A HREF="#InsertingRowsintoanInternalTable">
Inserting Rows into an Internal Table</A>
<UL>
<LI><A HREF="#SyntaxfortheinsertStatement">
Syntax for the insert Statement</A>
<LI><A HREF="#insertwaintoitindexn">
insert [wa into] it [index n]</A>
</UL>
<LI><A HREF="#ModifyingRowsinanInternalTable">
Modifying Rows in an Internal Table</A>
<UL>
<LI><A HREF="#SyntaxforthemodifyStatement">
Syntax for the modify Statement</A>
</UL>
<LI><A HREF="#DeletingInternalTableContents">
Deleting Internal Table Contents</A>
<UL>
<LI><A HREF="#UsingfreetoDeleteInternalTableContents">
Using free to Delete Internal Table Contents</A>
<LI><A HREF="#UsingrefreshtoDeleteInternalTableContents">
Using refresh to Delete Internal Table Contents</A>
<LI><A HREF="#UsingclearwithanInternalTable">
Using clear with an Internal Table</A>
<LI><A HREF="#UsingthedeleteStatementtoDeleteRowsfromanInternalTable">
Using the delete Statement to Delete Rows from an Internal
Table</A>
</UL>
<LI><A HREF="#CreatingTopListsUsingappendsortedby">
Creating Top 10 Lists Using append sorted by</A>
<UL>
<LI><A HREF="#SyntaxfortheappendsortedbyStatement">
Syntax for the append sorted by Statement</A>
</UL>
<LI><A HREF="#FillinganInternalTableUsingcollect">
Filling an Internal Table Using collect</A>
<UL>
<LI><A HREF="#SyntaxforthecollectStatement">
Syntax for the collect Statement</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>Recognize the table body operator and use it to test for the
existence of data in an internal table, and to compare the contents
of two internal tables for equality
<LI>Determine the number of rows in an internal table using <TT>describe</TT>
and <TT>sy-tfill</TT>
<LI>Copy the contents from one internal table to another using
the table body operator and the <TT>append lines</TT> and <TT>insert
lines</TT> statements
<LI>View and modify internal tables using <TT>editor-call</TT>
<LI>Use the <TT>insert</TT> and <TT>modify</TT> statements to
change the internal table contents
<LI>Delete rows from an internal table using <TT>delete</TT>,
<TT>delete ... where</TT>, <TT>clear</TT>, <TT>clear it[]</TT>,
<TT>refresh</TT>, and <TT>free</TT>
<LI>Fill an internal table using <TT>append sorted by</TT> and
<TT>collect</TT>
</UL>
<H2><A NAME="TestingandModifyingInternalTableContents"><FONT SIZE=5 COLOR=#FF0000>
Testing and Modifying Internal Table Contents</FONT></A></H2>
<P>
Use the following constructs to test and modify the contents of
internal tables:
<UL>
<LI>The table body operator
<LI><TT>describe table</TT>
<LI><TT>append lines</TT>
<LI><TT>insert lines</TT>
<LI><TT>editor-call</TT>
<LI><TT>insert</TT>
<LI><TT>modify</TT>
<LI><TT>free</TT>
<LI><TT>delete</TT>
<LI><TT>clear</TT>
<LI><TT>refresh</TT>
<LI>append sorted by
<LI>collect
</UL>
<P>
The body of an internal table is represented by the syntax <TT><I>it</I>[]</TT>,
where <TT><I>it</I></TT> is the
name of any internal table. <TT>it[]</TT> means &quot;the body
of the internal table <TT>it</TT>.&quot; There cannot be anything
between the square brackets; they must be written precisely as
shown. You can use this syntax to perform efficient table operations
that do not require the use of a header line. These operations
are described throughout this chapter.
<P>
If an internal table does not have a header line, the internal
table name itself represents the body. For example, if internal
table <TT>it</TT> does not have a header line, you can use either
<TT>it[]</TT> or <TT>it</TT> to represent the body; they are equivalent.
<H2><A NAME="ObtainingInformationaboutanInternalTable"><FONT SIZE=5 COLOR=#FF0000>
Obtaining Information about an Internal Table</FONT></A></H2>
<P>
You can obtain the following commonly needed information about
an internal table:
<UL>
<LI>Whether the internal table contains data
<LI>How many rows it contains
</UL>
<H3><A NAME="DeterminingWhetheranInternalTableIsEmpty">
Determining Whether an Internal Table Is Empty</A></H3>
<P>
If the body of an internal table contains only initial values
(blanks and spaces), it is empty. Therefore, to determine whether
an internal table contains any rows, test the body with the following
statement:
<BLOCKQUOTE>
<PRE>
if it[] is initial.
</PRE>
</BLOCKQUOTE>
<P>
If the test is true, the internal table is empty. When false,
it contains at least one row.
<H3><A NAME="DeterminingtheNumberofRowsinanInternalTable">
Determining the Number of Rows in an Internal Table</A></H3>
<P>
To determine the number of rows in an internal table, use the
<TT>sy-tfill</TT> variable. It is set by the <TT>describe table</TT>
statement.
<H4>Syntax for the describe table Statement</H4>
<P>
The following is the syntax for the <TT>describe table</TT> statement.
<BLOCKQUOTE>
<PRE>
describe table <I>it</I> [lines <I>i</I>] [occurs <I>j</I>].
</PRE>
</BLOCKQUOTE>
<P>
where:
<UL>
<LI><TT><I>it</I></TT> is the
name of an internal table.
<LI><TT><I>i</I></TT> and <TT><I>j</I></TT>
are numeric variables.
</UL>
<P>
This statement fills the three system variables shown in Table
12.1.<BR>
<P>
<CENTER><B>Table 12.1&nbsp;&nbsp;DESCRIBE TABLE Statement Fills
These System Variables</B></CENTER><CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=192><CENTER><B>Variable</B></CENTER></TD><TD WIDTH=288><CENTER><B>Value</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>sy-tfill</TT></TD><TD WIDTH=288>Number of rows
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>sy-tleng</TT></TD><TD WIDTH=288>Length of a row in bytes
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=192><TT>sy-toccu</TT></TD><TD WIDTH=288>Current value of the <TT>occurs</TT> clause
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
The following points apply:
<UL>
<LI>If the <TT>lines <I>i</I></TT>
addition is specified, the number of rows is placed in both <TT>sy-tfill</TT>
and <TT><I>i</I></TT>.
<LI>If the <TT>occurs <I>j</I></TT>
addition is specified, the size of the <TT>occurs</TT> clause
is placed in both <TT>sy-toccu</TT> and <TT><I>j</I></TT>.
</UL>
<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
There is only one instance where <TT>sy-toccu </TT>will differ from the <TT>occurs </TT>clause on the table definition. When <TT>sy-tleng * sy-toccu &gt; 8192</TT>, and after one row has been added to the internal table, <TT>sy-toccu </TT>will be zero. This indicates that memory is being allocated in 8KB chunks for this internal table.
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="SampleProgramthatObtainsInformationAboutanInternalTable">
Sample Program that Obtains Information About an Internal
Table</A></H3>
<P>
Listing 12.1 shows a sample program that obtains information about
an internal table.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 12.1&nbsp;&nbsp;The describe table Statement Uses System
Variables to Quantify Table Contents<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1  report ztx1201.
 2  data: begin of it occurs 3,
 3            f1 value 'X',
 4            end of it,
 5        n type i.
 6 
 7  if it[] is initial.
 8      write: / 'it is empty'.
 9      endif.
10
11 append: it, it, it.     &quot;same as writing 'append it' 3 times.
12
13 if not it[] is initial.
14     write: / 'it is not empty'.
15     endif.
16
17 write: / 'number of  rows from sy-tabix:', sy-tabix.
18 describe table it lines n.
19 write: / 'number of  rows from sy-tfill:', sy-tfill,
20        / 'length of a row from sy-tleng:', sy-tleng,
21        / 'occurs value    from sy-toccu:', sy-toccu.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 12.1 produces this output:
<BLOCKQUOTE>
<PRE>
it is empty                              
it is not empty                          
number of  rows from sy-tabix:          3
number of  rows from sy-tfill:          3
length of a row from sy-tleng:     1     
occurs value    from sy-toccu:          3
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 7 compares the body of the internal table using the table
body operator with initial values. The internal table does not
yet contain any rows, so the test is true.
<LI>Line 11 uses the chain operator (<TT>:</TT>) to append three
identical rows to <TT>it</TT>.
<LI>Line 13 tests the body again. This time, the test is preceded
by a logical <TT>not.</TT> The internal table contains data, so
this test is true.
<LI>After each <TT>append</TT> statement, the value of <TT>sy-tabix</TT>
is set to the number of rows in the internal table. Line 17 writes
out its value.
<LI>Line 18 uses the <TT>describe</TT> statement to obtain the
number of rows and places it in <TT>sy-tfill</TT>. It also obtains
the row length and size of the <TT>occurs</TT> clause and places
them into <TT>sy-tleng</TT> and <TT>sy-toccu</TT>.
</UL>
<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>TIP</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
If you only need to know whether the table contains data and not how many rows it has, use the table body operator. It is more efficient than the <TT>describe table </TT>statement.
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H2><A NAME="CopyingDatafromoneInternalTabletoAnother"><FONT SIZE=5 COLOR=#FF0000>
Copying Data from one Internal Table to Another</FONT></A></H2>
<P>
If two internal tables have the same structure, use the following
statement to duplicate the contents of one internal table in another:
<BLOCKQUOTE>
<PRE>
it2[] = it1[].
</PRE>
</BLOCKQUOTE>
<P>
The preceding statement copies the contents of the body of <TT>it1</TT>

⌨️ 快捷键说明

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