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

📄 ch20.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<LI>Via the <TT>importing</TT> or <TT>changing</TT> portion of
the interface. The first is equivalent to <TT>using</TT> on the
<TT>perform</TT> statement and the last is equivalent to <TT>changing</TT>
on <TT>perform</TT>.
</UL>
<P>
To return an internal table that originates from within a function
module, use one of the following:
<UL>
<LI>The <TT>tables</TT> portion of the interface
<LI>The <TT>exporting</TT> portion of the interface
</UL>
<H3><A NAME="PassinganInternalTableViatables">
Passing an Internal Table Via tables</A></H3>
<P>
If you use the <TT>tables</TT> portion of the interface, you can
pass the internal table together with the header line. If it doesn't
have a header line, it will automatically acquire one within the
function module. <TT>tables</TT> parameters are always passed
by reference.
<P>
To use this method, from the Function Library Initial Screen,
choose the Table Parameters/Exceptions Interface radio button
and then press the Change pushbutton. You will see the Table Parameters/Exceptions
screen. In the upper-half of the screen under the Table Parameters
column, type the names of internal table parameters.
<P>
If the internal table is a structured type, in the Ref. Structure
column, you can optionally type the name of a DDIC structure.
Only DDIC structure names can be entered here. If you don't specify
a DDIC structure here, you will not be able to access any of the
components of the internal table within the function module. To
do so will cause a syntax error.
<P>
If the internal table is not a structured type, you can enter
an ABAP/4 data type in the Reference Type column instead.
<H3><A NAME="PassinganInternalTableViaexportingimportingandchanging">
Passing an Internal Table Via exporting/importing and changing
</A></H3>
<P>
If you use the <TT>exporting</TT>/<TT>importing</TT> or <TT>changing</TT>
part of the interface, you can pass the body of an internal table
only. However, these parts of the interface enable you to choose
whether to pass the internal table body by value (the default)
or by reference. When using this method, you must specify <TT>table</TT>
in the Reference Type column.
<P>
Figures 20.1 and 20.2 and Listings 20.5 and 20.6 illustrate the
ways of passing internal tables to a function module.
<P>
<A HREF="javascript:popUp('f20-1.gif')"><B>Figure 20.1 : </B><I>The Import/Export Parameters screen showing
how to pass the body of the internal table</I>.</A>
<P>
<A HREF="javascript:popUp('f20-2.gif')"><B>Figure 20.2 : </B><I>The Table Parameters/ Exceptions screen
showing how to pass an internal table together with its header
line</I>.</A>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 20.5&nbsp;&nbsp;This Program Passes Internal Tables
to a Function Module<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx2005.
 2 tables ztxlfa1.
 3 data: it_a like ztxlfa1 occurs 3,   &quot;doesn't have a header line
 4       it_b like ztxlfa1 occurs 3.   &quot;doesn't have a header line
 5 select * up to 3 rows from ztxlfa1 into table it_a.
 6
 7 call function 'Z_TX_2006'
 8      exporting
 9           it1     = it_a[]
10      importing
11           it2     = it_b[]
12      tables
13           it4     = it_a
14      changing
15           it3     = it_a[]
16      exceptions
17           others  = 1.
18
19 write: / 'AFTER CALL',
20        / 'IT_A:'.
21 loop at it_a into ztxlfa1.
22     write / ztxlfa1-lifnr.
23     endloop.
24 uline.
25 write / 'IT_B:'.
26 loop at it_b into ztxlfa1.
27     write / ztxlfa1-lifnr.
28     endloop.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 20.6&nbsp;&nbsp;This Is the Source Code for the Function
Module Called from Listing 20.5<BR>
</B>
<BLOCKQUOTE>
<PRE>
1  function z_tx_2006.
2  *&quot;------------------------------------------------------------
3  *&quot;*&quot;Local interface:
4  *&quot;       IMPORTING
5  *&quot;             VALUE(IT1) TYPE  TABLE
6  *&quot;       EXPORTING
7  *&quot;             VALUE(IT2) TYPE  TABLE
8  *&quot;       TABLES
9  *&quot;             IT4 STRUCTURE  LFA1
10 *&quot;       CHANGING
11 *&quot;             VALUE(IT3) TYPE  TABLE
12 *&quot;------------------------------------------------------------
13 data wa like lfa1.
14 write / 'IT1:'.
15 loop at it1 into wa.
16     write / wa-lifnr.
17     endloop.
18 loop at it3 into wa.
19     wa-lifnr = sy-tabix.
20     modify it3 from wa.
21     endloop.
22 uline.
23 write: / 'IT4:'.
24 loop at it4.
25     write / it4-lifnr.
26     endloop.
27 uline.
28 it2[] = it1[].
29 endfunction.
</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.5 and 20.5 produce this output:
<BLOCKQUOTE>
<PRE>
------------
IT1:             
1000             
1010             
1020             
------------
IT4:             
1000             
1010             
1020             
------------
AFTER CALL       
IT_A:            
1                
2                
3                
------------
IT_B:            
1000             
1010             
1020         
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>In Listing 20.5, <TT>it_a</TT> and <TT>it_b</TT> are internal
tables without header lines.
<LI>Line 5 puts three rows into <TT>it_a</TT>.
<LI>Line 8 passes the body of <TT>it_a</TT> to <TT>it1</TT> by
value, to <TT>it3</TT> by value and result, and to <TT>it4</TT>
by reference with header line (<TT>it4</TT> will acquire a header
line within the function module).
<LI>In Listing 20.6 and within the function module, <TT>it1</TT>
and <TT>it3</TT> are independent copies of <TT>it_a</TT>. Line
13 defines a work area <TT>wa</TT> for use with <TT>it1</TT> and
<TT>it3</TT> because they don't have header lines.
<LI>Lines 15 through 17 write out the contents of <TT>it1</TT>
using the work area <TT>wa</TT>.
<LI>Lines 18 through 21 modify the contents of <TT>it3</TT>. This
table was passed by value and result, so the contents of the original
will be changed when the <TT>endfunction</TT> statement executes.
<LI>Lines 24 through 26 write out the contents of <TT>it4</TT>.
Notice that line 25 accesses a component of <TT>it</TT>. This
is only possible because the Ref. Structure column on the Table
Parameters/Exceptions screen contains the name of the DDIC structure
<TT>lfa1</TT>. This defines the structure of <TT>it</TT> within
the function module. If the Ref. Structure column was blank, a
syntax error would have occurred on line 25.
<LI>Line 28 copies the contents of <TT>it1</TT> to <TT>it2</TT>.
<LI>Line 29 copies the contents of <TT>it3</TT> back into <TT>it_a</TT>
in the calling program and control returns to the caller.
<LI>In Listing 20.5, lines 21 through 23 show that the contents
of <TT>it_a</TT> have been changed by the function module.
<LI>Lines 26 through 28 show that the contents of <TT>it_a</TT>
have been copied to <TT>it_b</TT> by the function module.
</UL>
<H2><A NAME="DefiningSubroutinesinaFunctionGroup"><FONT SIZE=5 COLOR=#FF0000>
Defining Subroutines in a Function Group</FONT></A></H2>
<P>
You can call internal and external subroutines from within function
modules. Calls to external subroutines are the same for function
modules as they are for reports. Internal subroutines should be
defined within a special include: the F01.
<P>
The F01 is included into the function group by editing the main
program and inserting the statement <TT>include L<I>fgid</I>F01</TT>.
Then, double-clicking on the name of the <TT>include</TT> will
create it automatically. Within it, you can put subroutines accessible
by all function modules within the group. There is, however, an
easier way.
<P>
The easiest way to define the F01 is to code your call to the
subroutine and then double-click on the subroutine name on the
<TT>perform</TT> statement. The following procedure illustrates
this process.
<P>
<img src="../button/screencam.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/screencam.gif">
<P>
Start the ScreenCam &quot;How to Create Subroutines within a Function
Group&quot; now.
<OL>
<LI>Start from the Function Library: Initial Screen.
<LI>Select the Source Code radio button.
<LI>Press the Change pushbutton. The Function Module: Edit screen
is shown.
<LI>Type a <TT>perform</TT> statement in the source code of the
function module. For example, <B>perform sub1</B>.
<LI>Double-click on the subroutine name. In this example, you
would double-click on <TT>sub1</TT>. The Create Object dialog
box appears, asking you if you want to create the subroutine.
<LI>Press the Yes button. The Create Subroutine dialog box appears.
The subroutine name appears in the Subroutine field. The include
name <TT>l<I>fgid</I>f01</TT>
appears in the Include Choice box, and the radio button to its
left is automatically selected.
<LI>Press the Continue button (the green checkmark). A Warning
dialog box appears, indicating the main program will be modified
and an <TT>include l<I>fgid</I>f01</TT>
statement will be inserted into it.
<LI>Press the Continue button (the green checkmark). You see the
Exit Editor dialog box indicating that your source code has changed
and asking you if you want to save the changes.
<LI>Press the Yes button. The Function Module Editor screen is
shown. You are now editing the F01. Code the subroutine here.
<LI>When you have finished coding your subroutine, press Save
and then Back. You are returned to the function module's source
code where you began.
</OL>
<P>
To see the include you just created, return to the Function Library
Initial screen. Choose the Main Program radio button and press
the Change button. You will see the Function Module: Edit screen.
At the bottom will be the <TT>include l<I>fgid</I>f01</TT>
statement. This statement was inserted by step 7 of the above
procedure. If you double-click on this line, you will see your
subroutine.
<H2><A NAME="ReleasingaFunctionModule"><FONT SIZE=5 COLOR=#FF0000>
Releasing a Function Module</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
The <TT>release</TT> function adds a level of protection to the
interface of a function module by protecting it from modification.
If you have completed testing of your function module, you might
want to <I>release</I> it to indicate that it is safe for other
developers to use in their code. By doing so, you are essentially
promising not to change the existing interface parameters in any
way that would cause problems to any programs that will call your
function module. You are promising interface stability.
<P>
For example, after releasing a function module, you shouldn't
add a required parameter, change the proposals, or remove a parameter.
If you did, any existing calls to your function module might fail
or work differently.
<P>
After releasing, you can still change the interface, but you need
to take an extra step to do it.
<P>
To release a function module, use the following procedure.
<P>
<img src="../button/screencam.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/screencam.gif">
<P>
Start the ScreenCam &quot;How to Release a Function Module&quot;
now.
<OL>
<LI>Begin at the Function Library Initial Screen.
<LI>Choose the Administration radio button.
<LI>Press the Change pushbutton. The Function Module Change: Administration
screen is shown. In the bottom right corner of the screen, at
the bottom of the General Data box, you will see <TT>Not Released</TT>.
<LI>Choose the menu path Function Module-&gt;Release-&gt;Release.
The message <I>Released</I> appears at the bottom of the window
in the status bar. In the bottom right corner of the window, <TT>Not
Released</TT> changes to <TT>Customer Release On</TT> and is followed
by the current date.
</OL>
<P>
If you try to change the interface after the function module has
been released, the input fields on the interface screen will be
grayed out. The message <TT>Function module has been released</TT>
will also appear at the bottom of the window. However, if you

⌨️ 快捷键说明

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