📄 ch19.htm
字号:
<!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® in 21 Days -- Day 19- Modularization: Function Modules, 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="../ch18/ch18.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch18/ch18.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="../ch20/ch20.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch20/ch20.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>®</sup> in 21 Days</H1></CENTER>
<HR SIZE=4>
<H1>Day 19</H1>
<H1>Modularization: Function Modules, Part 1</H1>
<UL>
<LI><A HREF="#UsingtheincludeStatement">
Using the include Statement</A>
<UL>
<LI><A HREF="#SyntaxfortheincludeStatement">
Syntax for the include Statement</A>
</UL>
<LI><A HREF="#IntroducingFunctionModules">
Introducing Function Modules</A>
<LI><A HREF="#UnderstandingFunctionGroups">
Understanding Function Groups</A>
<UL>
<LI><A HREF="#AccessingtheFunctionLibrary">
Accessing the Function Library</A>
<LI><A HREF="#ActivatingaFunctionModule">
Activating a Function Module</A>
<LI><A HREF="#DefiningDatawithinaFunctionModule">
Defining Data within a Function Module</A>
<LI><A HREF="#DefiningtheFunctionModuleInterface">
Defining the Function Module Interface</A>
<LI><A HREF="#PassingParameters">
Passing Parameters</A>
<LI><A HREF="#UsingTypedandUntypedParameters">
Using Typed and Untyped Parameters</A>
</UL>
<LI><A HREF="#CallingFunctionModules">
Calling Function Modules</A>
<UL>
<LI><A HREF="#SyntaxforthecallfunctionStatement">
Syntax for the call function Statement</A>
<LI><A HREF="#RunningaSampleFunctionModule">
Running a Sample Function Module</A>
</UL>
<LI><A HREF="#CreatingaFunctionModule">
Creating a Function Module</A>
<LI><A HREF="#Summary">
Summary</A>
<LI><A HREF="#QampABR">
Q&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>
<P>
After you complete this chapter, you will be able to:
<UL>
<LI>Understand and use the <TT>include</TT> statement
<LI>Create function groups and function modules
<LI>Define import, export, and changing parameters
</UL>
<H2><A NAME="UsingtheincludeStatement"><FONT SIZE=5 COLOR=#FF0000>
Using the include Statement</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
An <I>include program</I> is a program in which the contents are
designed to be used by another program. It is not usually complete
all by itself. Instead, other programs use the code the include
program contains by copying the lines of code from the include
program into themselves. The copy is performed at runtime via
the <TT>include</TT> statement. An include program is also known
as an <I>included program</I>.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
A program that includes another is known as an <I>including program</I>.
<H3><A NAME="SyntaxfortheincludeStatement">
Syntax for the include Statement</A></H3>
<P>
The following is the syntax for the <TT>include</TT> statement.
<BLOCKQUOTE>
<PRE>
include ipgm.
</PRE>
</BLOCKQUOTE>
<P>
where:
<UL>
<LI><TT><I>ipgm</I></TT> is a
type <TT>i</TT> program.
</UL>
<P>
The following points apply:
<UL>
<LI>An include program must be type <TT>i</TT>. You specify the
program type in the Type field on the Program Attributes screen
when you create the program.
<LI>An include program can be included into one or more including
programs.
<LI>A type <TT>i</TT> program cannot contain partial or incomplete
statements.
</UL>
<P>
The <TT>include</TT> statement copies the contents of the include
program into the including program. The code from the include
program is copied as-is and replaces the <TT>include</TT> statement
at the time of program generation. Figure 19.1 illustrates the
<TT>include</TT> statement.
<P>
<A HREF="javascript:popUp('f19-1.gif')"><B>Figure 19.1 :</B> <I>An illustration of the include statement</I>.</A>
<P>
In Figure 19.1, <TT>za</TT> is the including program. The include
programs are <TT>zb</TT> and <TT>zc</TT>. At the time <TT>za</TT>
is generated, the source code for <TT>zb</TT> and <TT>zc</TT>
is inserted into <TT>za</TT>, making the program shown at the
bottom of the figure.
<P>
Listings 19.1 through 19.3 illustrate include programs.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 19.1 An Including Program<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 report ztx1901 no standard page heading.
2 tables: ztxlfa1, ztxlfb1.
3 parameters p_lifnr like ztxlfa1-lifnr obligatory default '1000'.
4
5 include: ztx1902,
6 ztx1903.
7
8 top-of-page.
9 write: / 'Company Codes for Vendor', p_lifnr.
10 uline.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 19.2 This Program Is Included into ztx1901
<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 ***INCLUDE ZTX1902.
2 select single * from ztxlfa1 where lifnr = p_lifnr.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 19.3 This Program Is also Included into
ztx1901<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 ***INCLUDE ZTX1903.
2 select * from ztxlfb1 where lifnr = ztxlfa1-lifnr.
3 write: / ztxlfb1-bukrs.
4 endselect.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listings 19.1 through 19.3 produces this output:
<BLOCKQUOTE>
<PRE>
Company Codes for Vendor 1000
---------------------------------
1000
3000
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>At generation time for <TT>ztx1901</TT>, line 5 copies the
code from program <TT>ztx1902</TT> into <TT>ztx1901</TT>. The
inserted code replaces line 5.
<LI>Still during program generation of <TT>ztx1901</TT>, line
6 copies the code from program <TT>ztx1903</TT> into <TT>ztx1901</TT>.
The inserted code replaces line 6.
<LI>When the program runs, ztx1901 behaves like a single program,
as if those lines of code from the included programs had been
typed directly into ztx1901.
</UL>
<P>
SAP uses <TT>include</TT>s to reduce code redundancy and to divide
very large programs into smaller units.<P>
<CENTER>
<TABLE BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>TIP</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
While viewing an including program, you can view the contents of an included program simply by double-clicking on its name. For example, while editing <TT>ztx1901 </TT>from the ABAP/4 Editor: Edit Program screen, double-click on the name <TT>ztx1902 </TT>or <TT>ztx1903</TT>. The included program will be displayed immediately.
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<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 want to see the resulting code with all <TT>includes </TT>expanded in-line, run program <TT>RSINCL00</TT>. On the selection screen for <TT>RSINCL00</TT>, in the Program field, enter the name of a program that includes other programs. Place an X in the Program Source Code and Expand Include Lines fields and press Execute. A list of the resulting source code will be displayed on the next screen.
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H2><A NAME="IntroducingFunctionModules"><FONT SIZE=5 COLOR=#FF0000>
Introducing Function Modules</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -