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

📄 ch20.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 20- Modularization: Function Modules, Part 2</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="../ch19/ch19.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch19/ch19.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="../ch21/ch21.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch21/ch21.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;20</H1>
<H1>Modularization: Function Modules, Part 2</H1>


<UL>
<LI><A HREF="#DefiningGlobalDataforFunctionModules">
Defining Global Data for Function Modules</A>
<LI><A HREF="#PassinganInternalTabletoaFunctionModule">
Passing an Internal Table to a Function Module</A>
<UL>
<LI><A HREF="#PassinganInternalTableViatables">
Passing an Internal Table Via tables</A>
<LI><A HREF="#PassinganInternalTableViaexportingimportingandchanging">
Passing an Internal Table Via exporting/importing and changing
</A>
</UL>
<LI><A HREF="#DefiningSubroutinesinaFunctionGroup">
Defining Subroutines in a Function Group</A>
<LI><A HREF="#ReleasingaFunctionModule">
Releasing a Function Module</A>
<LI><A HREF="#TestingaFunctionModule">
Testing a Function Module</A>
<LI><A HREF="#FindingExistingFunctionModules">
Finding Existing Function Modules</A>
<LI><A HREF="#ExploringtheComponentsofyourFunctionGroup">
Exploring the Components of your Function Group</A>
<LI><A HREF="#FindingandFixingErrorsinFunctionModules">
Finding and Fixing Errors in Function Modules</A>
<LI><A HREF="#SettingtheValueofsysubrconReturn">
Setting the Value of sy-subrc on Return</A>
<UL>
<LI><A HREF="#UsingtheraiseStatement">
Using the raise Statement</A>
<LI><A HREF="#UsingthemessageraisingStatement">
Using the message ... raising Statement</A>
<LI><A HREF="#DefiningExceptionsintheInterface">
Defining Exceptions in the Interface</A>
</UL>
<LI><A HREF="#AutomaticallyInsertingthecallfunctionStatement">
Automatically Inserting the call function Statement</A>
<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>
<P>
After you complete this chapter, you will be able to:
<UL>
<LI>Understand the components and structure of a function group
<LI>Define global data and subroutines within a function group
</UL>
<H2><A NAME="DefiningGlobalDataforFunctionModules"><FONT SIZE=5 COLOR=#FF0000>
Defining Global Data for Function Modules</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
Two types of <I>global data</I> can be defined for a function
module:
<UL>
<LI>Data definitions placed in the top <TT>include</TT> are accessible
from all function modules and subroutines within the group. This
type of global data is persistent across function module calls.
<LI>Data definitions within the interface are known only within
the function module. If the interface is defined as a <I>global
interface</I>, the parameter definitions are also known within
all subroutines that the function module calls. This type of global
data is not persistent across function module calls.
</UL>
<P>
The global data defined within the top <TT>include</TT> is accessible
from all function modules within the group. It is analogous to
the global data definitions at the top of an ABAP/4 program.
<P>
The parameters defined within a <I>global</I> <I>interface</I>
are accessible from all subroutines called from the function module.
It is analogous to variables defined within a subroutine using
the <TT>locals</TT> statement.
<P>
The parameters defined within a <I>local</I> <I>interface</I>
are inaccessible from subroutines called from the function module.
It is analogous to variables defined within a subroutine using
the <TT>data</TT> statement. By default, interfaces are local.
<P>
To make an interface global, from the Function Module Change:
Import/Export Parameters screen, choose the menu path Edit-&gt;Globalize
Parameters. To make it local again, choose the menu path Edit-&gt;Localize
Parameters.<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 a parameter with the same name exists in two function modules within a group and both interfaces are global, the data definitions of both of these parameters must be identical.</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Global data defined within the top <TT>include</TT> is allocated
when a program makes its first call to any function module of
a group. It remains allocated as long as the calling program remains
active. Each subsequent call to a function module within the same
group sees the previous values within the global data area. The
values in the global data area persist until the calling program
ends.
<P>
Global data defined by making the interface global is reinitialized
each time the function module is called.
<P>
Listings 20.1 through 20.4 illustrate the persistence of global
data defined within the top include.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 20.1&nbsp;&nbsp;This Program Illustrates the Persistence
of Global Data<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx2001.
 2 parameters parm_in(10) default 'XYZ' obligatory.
 3 data f1(10) value 'INIT'.
 4
 5 perform: call_fm12,
 6          call_fm13.
 7 write: / 'f1 =', f1.
 8
 9 *_____________________________________________________________________
10 form call_fm12.
11   call function 'Z_TX_2002'
12        exporting
13             p_in    = parm_in
14        exceptions
15             others  = 1.
16   endform.
17
18 *_____________________________________________________________________
19 form call_fm13.
20   call function 'Z_TX_2003'
21        importing
22             p_out   = f1
23        exceptions
24             others  = 1.
25   endform.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 20.2&nbsp;&nbsp;This Is the Source Code of the First
Function Module Called from Listing 20.1<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  function z_tx_2002.
2  *&quot;------------------------------------------------------------
3  *&quot;*&quot;Local interface:
4  *&quot;       IMPORTING
5  *&quot;             VALUE(P_IN)
6  *&quot;------------------------------------------------------------
7  g1 = p_in.
8  endfunction.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 20.3&nbsp;&nbsp;This Is the Source Code of the Second
Function Module Called from Listing 20.1<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  function z_tx_2003.
2  *&quot;------------------------------------------------------------
3  *&quot;*&quot;Local interface:
4  *&quot;       EXPORTING
5  *&quot;             VALUE(P_OUT)
6  *&quot;------------------------------------------------------------
7  p_out = g1.
8  endfunction.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 20.4&nbsp;&nbsp;This Is the Top INCLUDE for the Function
Group ZTXB-ZTXB Contains the Function Modules Shown in Listings
20.2 and 20.3<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  function-pool ztxb.
2  data g1(10).
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listings 20.1 through 20.4 produce this output:
<BLOCKQUOTE>
<PRE>
f1 = XYZ
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>In Listing 20.1, line 5 transfers control to line 10, and
line 11 calls function module <TT>z_tx_2002</TT>, which exists
in function group <TT>ztxb</TT>. The value of <TT>parm_in</TT>
is passed to <TT>p_in</TT>. Control transfers to line 1 of Listing
20.2.
<LI>In Listing 20.2, line 7 moves the value from <TT>p_in</TT>
to the global variable <TT>g1</TT>. <TT>g1</TT> is defined in
the top <TT>include</TT> on line 2 of in Listing 20.14. That makes
it visible to all function modules, and the value is persistent
between calls to function modules of that group. Control returns
to line 11 of Listing 20.1.
<LI>In Listing 20.1, line 16 transfers control to line 5, then
line 6, and then line 19. Line 20 calls function module <TT>z_tx_2003</TT>,
which also exists in function group <TT>ztxb</TT>. Control transfers
to line 1 of Listing 20.3.
<LI>In Listing 20.3, line 7 moves the value from the global variable
<TT>g1</TT> to <TT>p_out</TT>. <TT>g1</TT> still contains the
value placed in it by the previous function module. Control returns
to the calling program and the value is written out.
</UL>
<H2><A NAME="PassinganInternalTabletoaFunctionModule"><FONT SIZE=5 COLOR=#FF0000>
Passing an Internal Table to a Function Module</FONT></A></H2>
<P>
Passing an internal table to a function module follows the same
rules as that of passing an internal table to a subroutine. There
are two methods:
<UL>
<LI>Via the <TT>tables</TT> portion of the interface. This is
equivalent to passing it via the <TT>tables</TT> addition to the
<TT>perform</TT> statement.

⌨️ 快捷键说明

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