Exercise 1: Creating a Function module

本文指导如何在ABAP环境中创建并测试一个函数模块。首先创建一个功能组,并将其激活;接着定义全局数据,用于共享同一功能组内的所有函数模块;然后创建一个用于从SPFLI表读取数据的远程启用函数模块,包括设置参数和异常处理;最后测试该函数模块的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Use

Function modules are ABAP routines that are administered in a central function library. They apply across applications and are available throughout the system. You must assign function modules to a function pool that is called a function group. A function group is nothing but a container for the function modules. Now create a function group and then a function module, which you can use for the next exercise steps.

Procedure

Create a Function Group:

  1. To open the Object Navigator choose from the SAP Menu Overview ® Object Navigator.
  2. From the Object Selection window select Function group, enter FG_Tutorial as name of your function group, and choose Display.
  3. Since the function group FG_Tutorial does not yet exist, the system asks you whether to create it. Confirm with Yes.
  4. Enter a short description and choose Save.
  5. In the window Create Object Catalog Entry choose Local object.

You created a local function group. Before it can receive function modules, you must activate it.

  1. In the object list, use the right mouse button to select the function group FG_Tutorial you just created and choose Activate.
  2. On the next screen choose Continue.

The function group is now active.

Create Global Data:

Within the function group you can declare global data. All function modules of this function group share this global data.

  1. In the Object Selection window open the directory tree Includes and double-click on LFG_TutorialTOP.
  2. Choose Create « Change ( STRG+F1 ) and enter the following data declarations in the tool area:

TABLES spfli.
DATA spfli_workarea LIKE spfli.

  1. Check ( STRG+F2 ) and activate ( STRG+F3 ) the include file.

Create a Function Module:

Create a function module that reads data from table SPFLI .

  1. If you are not yet in the Object Navigator, choose from the SAP Menu Overview à Object Navigator and display the function group FG_Tutorial .
  2. In the Object selection window, use the right mouse button to select function group FG_Tutorial , and choose Create à Function module.
  3. Enter as function module name XX_RFC_READ_SPFLI and replace XX with the initials of your name.
  4. Enter a short description and choose Save.

The system lists the function module in the object list in a new directory Function modules, and displays it on the right side in the Function Builder.

  1. Select the Attributes tab and under Processing type choose Remote-enabled module.
  2. Select the Import tab and enter in the appropriate columns the names of the import parameters: carrid with reference type like spfli-carrid and connid with reference type like spfli-connid . For each parameter set the Pass value flag.
  3. Select the Export tab and enter in the appropriate columns the names of the export parameters: ex_spfli with reference type like spfli and sys with reference type like sy-sysid . For each parameter set the Pass value flag.
  4. Select the Exceptions tab and enter the exception invalid_data .
  5. Select the Source code tab.

The system copies the entries you made in the other tabs and creates a source text.

  1. Complete the function module with the actual flight data retrieval.

Compare your function with the model solution.

 

 FUNCTION ZFG_RFC_READ_SPFLI.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(CARRID) TYPE  SPFLI-CARRID
*"     VALUE(CONNID) TYPE  SPFLI-CONNID
*"  EXPORTING
*"     VALUE(EX_SPFLI) TYPE  SPFLI
*"     VALUE(SYS) TYPE  SY-SYSID
*"  EXCEPTIONS
*"      INVALID_DATA
*"----------------------------------------------------------------------
SELECT SINGLE * FROM spfli INTO spfli_workarea
         WHERE  carrid      = carrid
         AND    connid      = connid.
  IF sy-subrc EQ 0.
    ex_spfli = spfli_workarea.
  ELSE.
    RAISE invalid_data.
  ENDIF.
  Sys   = sy-sysid.
ENDFUNCTION.

  1. Save the function module ( STRG+S ). When the note on remote-enabled function modules appears, choose Continue.
  2. Check the function for errors ( STRG+F2 ) and then activate it ( STRG+F3 ).

Test the Function Module:

  1. Choose Test/Execute ( F8 ) or Function module à Test à Test function module.
  2. As import parameter for CARRID enter LH ; for CONNID enter 400 . Leave the RFC target system line empty.
  3. Choose Execute ( F8 ).

The system displays the export parameters EX_SPFLI and SYS in an additional table.

  1. For a detailed display of the data select the value in line EX_SPFLI.

Result

You created a function module and assigned it to a function group.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值