How To Create a ABAP Function Modules In SAP with Steps

0
424
ABAP function module, Function module in ABAP , SAP function module
Function Module

How to create a function module in SAP ABAP

ABAP function module
Function Module steps

What is function module in sap

Each function module must be attached to one function group. Each contains two include programs by default. One is for global declaration another one is for common subroutines. All the function modules can access the both the include programs.
When ever we are calling any one of the function module then all other function modules will be loaded into the memory of calling program. So it’s better to group related function module into one function group.
Note: – ‘SE37’ is the transaction code function module Tcode in SAP. 

Function group in SAP ABAP

A function group is a collection of function modules that are logically related and share global data. These modules can be executed independently but are often part of a larger, cohesive process. Function groups help in organizing code, making it easier to manage and understand.

How to create function group in SAP ABAP: –

  • Execute SE37 is the sap function module Tcode.
  • In the menu bar click on GO TO–>Function groups–>Create group(zbbstech_fg).
  • Provide the function group name & short description.
  • Save. Click on local object.

Steps to activate function group: –

  • In the menu bar click on environment–>inactive objects.
  • Expand the function group under local objects.
  • Select the function group–>Right click on it.
  • Click active. Enter.

Components of function module in SAP ABAP: –

  1. Attributes
  2. Import
  3. Export
  4. Changing
  5. Tables
  6. Exceptions
  7. Source code

Attributes: –

Attributes specify the type of function module whether it’s a normal or remote enable. If the function module type is normal then we can access the function module within the server only.
If the function module type is remote enable then we can access the function module within the server as well as outside the server also.

Import: –

Import acts like input parameters [using in the server].

Export: –

Export acts like output parameters [changing in the server].

Changing: –

Changing acts like both import & export.

Tables: –

Tables acts like both import & export only for internal tables.

Exceptions: –

These are used to handle the errors in function module.

Source code: –

It contains the logic related function module.

Difference between Function Module and Subroutine
Difference between Function Module & Subroutine

Practice:- Develop a function module to display the all the purchasing order header details based on the given purchasing document number

Steps to create function module: –
  • Execute SE37.
  • Provide the function module name(zmktao_fm1).
  • Click on create.
  • Provide the function group name. Provide the short text. Click on save. Enter.
  • Click on import.
  • Provide parameter name, type, associated type.
  • I_EBELN type EKKO-EBELN
  • Click on export.
  • Provide parameter name, type, associated type.
  • E_WA TYPE EKKO
  • Click on source code.
  • Write source code.
  • Select single * from EKKO into E_WA where EBELN = I_EBELN.
  • End function.
  • Save, check, activate the function module.
Steps to call the function module: –

Place the cursor where you want to call the function module. Click on pattern in the application tool bar. Provide the function module name.

Steps to call the function module
Call Function module

Practice

Based on the given customer numbers, to display the Customer number, customer name and city by developing function module.

Steps to create structure: –

  • Execute SE11.
  • Select the radio button data type.
  • Provide the structure name.
  • Click on create.
  • Select the radio button structure. Enter.
  • Provide the short description.
  • Provide component, component type.
  • KUNNR KUNNR
  • NAME1 NAME1_GP
  • ORT01 ORT01_GP
  • Save, check, activate.

Steps to create function module: –

  • Execute function module Tcode in sap SE37 .
  • Provide the function module name(zstwpo_fm2).
  • Click on create.
  • Provide the function group name. Provide the short text. Click on save. Enter.
  • Click on import.
  • Provide parameter name, type, associated type.
  • I_KUNNR type KNA1-KUNNR
  • Click on export.
  • Provide parameter name, type, associated type.
  • E_WA TYPE ZBBSRT_SKR
  • Click on Exceptions.
  • Provide Exception name, text.
  • Raise Nodata
  • Click on source code.
  • Write source code.
  • Select single KUNNR NAME1 ORT01 from KNA1 into E_WA where KUNNR = I_KUNNR.
  • if sy-subrc <> 0.
  • Raise Nodata .
  • endif.
  • Endfunction.
  • Save, check, activate the function module.

Steps to call the function module in SAP ABAP: -(SAP SE38)

Place the cursor where you want to call the function module. Click on pattern in the application tool bar. Provide the function module name.

Parameter p_kunnr type kna1-kunnr.
Data wa_kna1 like zsoupa_str.
Call function ‘zstwpo_fm2’
Exporting.
i_kunnr = p_kunnr
Importing
E_wa = WA_KNA1
Exceptions
NODATA = 1
OTHERS = 2.
If SY-SUBRC = 0.
Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-ort01.
Elseif SY-SUBRC = 1.
Write: ‘INVALID INPUT’.
Endif.

Note:

In the function module all parameters are either pass by value or pass by reference. By default all parameters are pass by reference. Pass by reference means from calling to definition & definition to calling all parameter values are passing along with the memory.
Pass by value means from calling to definition & definition to calling only parameters values are passed.

In the remote enable function module all parameters are pass by value only.
Difference.

If want to read more about SAP MM/FI integration please visit

To learn more on SAP please visit

Types of Function Modules in SAP ABAP

Types of function module in sap ABAP

1.Standard Function Modules.

Standard function modules are pre-defined and provided by SAP for common tasks such as data retrieval, date calculations, and conversions. These are robust and extensively tested modules that can be used across various SAP applications.

2. Remote-Enabled Function Modules (RFC)

Remote-enabled function modules allow you to call functions remotely between different SAP systems or from an external system to an SAP system. They are designed for seamless integration and communication across disparate platforms.

3. Update Function Modules

These function modules are specifically designed for database updates. They ensure data consistency and integrity by performing updates in a controlled manner, typically within the context of a transaction.

4.Customer Function Modules

Customer function modules are custom-built by developers to meet specific business requirements that are not covered by standard SAP function modules. They are tailored to address unique workflows and processes within an organization.

5.BAPI (Business Application Programming Interface)

BAPIs are standardized programming interfaces that allow external applications to interact with SAP systems. They are essentially special types of RFCs designed for specific business operations, ensuring consistent and reliable data exchange.

6.Dialog Function Modules

These function modules are used to handle dialog processing, such as user interactions within SAP GUI. They manage tasks like screen handling, user input validation, and navigation within applications.

7.System Function Modules

System function modules are used for system-related operations such as system monitoring, user management, and performance tuning. They provide essential utilities for maintaining the health and efficiency of the SAP system.

8.Conversion Function Modules

Conversion function modules are used for data conversion tasks such as format changes, unit conversions, and data type transformations. They are essential for ensuring data compatibility and coherence across different parts of the system.

Update Function Module in SAP ABAP:

Updating a function module in SAP ABAP is a crucial task for maintaining and enhancing the functionality of your SAP system. Whether you need to adjust parameters, modify the logic, or optimize performance, here’s a step-by-step guide on how to effectively update a function module.

Step 1: Access the Function Builder
  1. Log in to the SAP System: Start by logging into your SAP system using your appropriate credentials.

  2. Navigate to SE37: Enter transaction code SE37 in the command field and press Enter. This will open the Function Builder.

Step 2: Locate the Function Module
  1. Enter the Function Module Name: In the Function Builder, enter the name of the function module you wish to update in the “Function Module” field.

  2. Display the Function Module: Click on the Display button to load the function module details.

Step 3: Edit the Function Module
  1. Switch to Change Mode: Click on the Change button to switch from display mode to change mode.

  2. Update Parameters: If you need to update the parameters, navigate to the “Import”, “Export”, “Changing”, or “Tables” tab. Modify the parameters as required.

  3. Modify Source Code: Go to the “Source Code” tab to change the logic of the function module. Make your necessary code adjustments.

Step 4: Save and Activate
  1. Save Changes: Once you have made the necessary updates, click the Save button to save your changes.

  2. Check Syntax: Always check the syntax of your function module to ensure there are no errors. Use the Check button for this purpose.

  3. Activate the Function Module: Finally, click the Activate button to activate the function module. This will make your changes effective in the SAP system.

Step 5: Test the Updated Function Module
  1. Test the Function Module: Use the Test/Execute functionality in SE37 to test your updated function module. Ensure that it behaves as expected with the new changes.

  2. Debug if Necessary: If there are issues, use the Debugging tools to identify and fix any problems.

For complete ABAP tutorial please click here.

To learn SAP ABAP from SAP please click here

LEAVE A REPLY

Please enter your comment!
Please enter your name here