The Wayback Machine - https://web.archive.org/web/20240726195059/https://www.geeksforgeeks.org/sap-abap-function-modules/
Open In App

SAP ABAP | Function Modules

Last Updated : 06 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which includes enterprise resource planning (ERP) systems and other business software solutions. C++ is used to implement the ABAP kernel. A procedural and object-oriented programming model are both supported by the hybrid programming language ABAP.

SAP ABAP Function Modules

SAP ABAP | Function Modules

SAP ABAP | Function Modules

Function Modules in SAP ABAP (Advanced Business Application Programming) are reusable chunks of code that execute certain operations inside a SAP system. They contain a group of linked capabilities and may be accessed from a variety of applications, making them an important component of SAP’s modular and efficient design. The Function Builder (SE37 transaction code) is used to generate them. Function Modules can be invoked from various applications to carry out specified tasks.

Creating a New Function Module in SAP ABAP

  • To use the Function Builder, go to Development > ABAP Workbench > Function Builder on the SAP Menu.
  • Form a Function set: A set of linked function modules is called a function group. “Create Function Group” may be selected by right-clicking on the “Function Groups” node in the Project Explorer. Please provide a descriptive name and unique name for the function group.
  • To generate a new function module, right-click on it and choose “Create ABAP Function Module” from the menu. Give the function module a distinctive name and provide a short explanation.
  • Describe the Function Module Interface: The interface lists the function module’s arguments and exceptions. Choose the “Parameters” tab in the Function Module Editor. Names, data types, and whether the parameters are input, output, or both should all be specified when defining the parameters.
  • To put the Function Module logic into practice, go to the “Source Code” tab in the Function Module Editor. Write the logic for the function module in ABAP code. To carry out computations, get data, or communicate with external systems, use the parameter values.
  • Function Module: Save and Activate: First, save the function module, and then activate it. This allows other ABAP applications to utilize the function module.

Meaning and Importance of Function Modules in SAP ABAP

  • In SAP programming, Function Modules allow modularity and reusability.
  • They aid with the effective maintenance and organization of code.
  • They provide greater code abstraction, which reduces redundancy and mistakes.

Include Programs Vs. Function Modules in SAP ABAP

  • Include programs are portions of code that may be included in other programs, whereas function modules are freestanding units with well-defined inputs and outputs.
  • Include programs are often used for code sharing inside a program, whereas function modules are better suited for reusable, modular programming.

Groups of Functions

  • For better organization, function modules are frequently organized into function groups.
  • Function groups aid in the collective management of linked function modules.

Builder of Functions

  • Function Modules are created, modified, and managed using the Function Builder (transaction SE37).
  • Within the Function Builder, you may create import/export arguments, exceptions, and documentation.

Developing a New Program

  • You can call the Function Module from a new program (report, transaction, or other ABAP program type).

Parameter Configuration

  • You must give input parameters and possibly create tables or structures to accept output data before running a Function Module.

Modules Invoked

  • The CALL FUNCTION command is used to invoke a Function Module within your application.
  • The call specifies the name of the function module, as well as the input and output arguments.

Return Values Handling

  • You may manage the return values of a Function Module, including any exceptions it may raise, after executing it.
  • Error handling is critical to ensuring that your software runs smoothly.

Code Improvement

  • Function Modules can be customized to add or change functionality.
  • Function Exit, BAdI (Business Add-Ins), and other approaches are used for enhancements.

Execution

  • Finally, you run your program, which contains the function module call.
  • The Function Module completes its duty, and the results can be used in your application as needed.

Example of SAP ABAP Functional Module

Select the “Source Code” tab after launching the just built application.

Write your program’s ABAP code. In this scenario, you may translate an amount into words by using the SPELL_AMOUNT function module.

REPORT ZDEMO_SPELL_AMOUNT.

DATA(lv_amount) TYPE p DECIMALS 2 VALUE '12345.67'.
DATA(lv_currency) TYPE c LENGTH 5 VALUE 'USD'.
DATA(lv_spell_out) TYPE string.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = lv_amount
CURRENCY = lv_currency
IMPORTING
IN_WORDS = lv_spell_out
EXCEPTIONS
AMOUNT_TOO_LARGE = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE: / 'Amount:', lv_amount,
/ 'Currency:', lv_currency,
/ 'In Words:', lv_spell_out.
ELSE.
WRITE: / 'Error in SPELL_AMOUNT function module.'.
ENDIF.

Customize the Code (Enhancement)

Custom logic may be added to the code to improve it. For instance, you may want to handle more cases or change the result.

DATA(lv_custom_spell_out) TYPE string.
" Custom logic to enhance the output
lv_custom_spell_out = lv_spell_out && ', which is a customized output.'.
WRITE: / 'Customized In Words:', lv_custom_spell_out.

Output

Amount: 12345.67
Currency: USD
In Words: TWELVE THOUSAND THREE HUNDRED FORTY-FIVE AND 67/100 DOLLARS
Customized In Words: TWELVE THOUSAND THREE HUNDRED FORTY-FIVE AND 67/100 DOLLARS, which is a customized output.



Previous Article
Next Article

Similar Reads

SAP ABAP: A complete Guide to Events in ABAP Report
SAP created the high-level programming language known as SAP ABAP (Advanced Business Application Programming) to be used for creating business applications. Reports are an essential tool for extracting and presenting data in SAP development. To manage the execution flow and improve the functionality of their systems, developers must comprehend the
5 min read
SAP S/4 HANA Vs SAP HANA | Difference between SAP S/4 HANA , SAP HANA
SAP S/4HANA is the most recent ERP suite, with advanced architecture allowing for real-time processing. SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP S/4 HANA?SAP, which stands f
3 min read
SAP HANA Vs SAP ECC | Difference between SAP HANA and SAP ECC
SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP HANA?SAP HANA stands for High-performance analytic appliance, which is faster than any other database management system that we use
2 min read
SAP MM Vs SAP SRM | Difference Between SAP MM and SAP SRM
SAP MM helps companies optimize their material and logistics management procedures, guaranteeing effective and economical handling of items. SAP SRM stands for Supplier Relationship Management and is an efficient tool that helps companies optimize procurement operations and helps to improve relationships with suppliers and other business vendors. W
2 min read
SAP EWM Vs SAP WM | Difference Between SAP EWM and SAP WM
SAP EWM is a version created by enhancing the SAP Warehouse Management (SAP WM) solution, one of the world’s most popular warehouse management applications, with new features. What is SAP EWM?The SAP EWM solution was created to organize and manage goods storage in warehouses, distribution centers, and logistical centers. Its primary goal is to impr
3 min read
Diffrence Between SAP and SAP ABAP(Advanced Business Application Programming)
In this article, we are going to learn the difference between an SAP and SAP ABAP. SAP ABAP is created by SAP which is a domain-specific language, it is 4th generation programming language. It is also called ABAP/4(Fourth Generation Language” or 4GL). What is SAP?SAP stands for Systems, Applications, and Products in Data Processing. It’s a German m
2 min read
Difference Between SAP ERP and SAP ABAP
In this article, we are going to learn the difference between an SAP ERP and SAP ABAP. SAP ABAP is created by SAP which is a domain-specific language, it is 4th generation programming language. It is also called ABAP/4(Fourth Generation Language” or 4GL). SAP Enterprise Resource Planning (ERP) systems are essential for simplifying and maximizing a
2 min read
Difference between SAP S/4 HANA , SAP HANA and SAP ECC
SAP S/4HANA is the most recent ERP suite, with advanced architecture allowing for real-time processing. SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP S/4 HANA?SAP, which stands f
3 min read
SAP ABAP | Loop Control
Introduction to Loop Control in SAP ABAPIn SAP ABAP programming, loop control is an esse­ntial concept that allows you to execute­ a block of code multiple times. This is e­specially useful when proce­ssing data in an efficient manner. Loops help automate repetitive­ tasks and handle large datasets effectively. In ABAP, there are various types of l
4 min read
SAP ABAP | Constants & Literals Explained
In the world of SAP ABAP (Advanced Business Application Programming), the use of Constants and Literals is necessary for the effective handling of data. Literals are used to denote specific data types such as numbers, characters, strings, and boolean values. What are Literals?Literals in programming refer to fixed values that are directly represent
7 min read
Article Tags :
three90RightbarBannerImg