SAP Bit
Home
Get Started
  • Overview
  • Transaction Codes
  • Tables
  • Function Modules
  • Data Elements
  • Domains
  • IMG Activities
  • Overview
  • Standard RFCs
  • Custom RFCs
  • Overview
  • OData URLs
  • OData Services
GitHub
Home
Get Started
  • Overview
  • Transaction Codes
  • Tables
  • Function Modules
  • Data Elements
  • Domains
  • IMG Activities
  • Overview
  • Standard RFCs
  • Custom RFCs
  • Overview
  • OData URLs
  • OData Services
GitHub
  • SAP Objects

    • SAP Objects
    • Transaction Codes (T-Codes)
    • SAP Tables
    • Function Modules
    • Data Elements
    • Domains
    • IMG Activities

Function Modules

Function modules are ABAP programs that encapsulate reusable functionality. They can be called from other ABAP programs and provide a modular approach to SAP development.

Understanding Function Modules

Function modules are self-contained units of code that:

  • Encapsulate specific business logic or technical functionality
  • Have well-defined interfaces with import, export, changing, and tables parameters
  • Can be called from any ABAP program
  • Support exception handling
  • Can be organized into function groups

Function Module Structure

A function module consists of:

Interface

  • Import Parameters: Input values passed to the function module
  • Export Parameters: Output values returned by the function module
  • Changing Parameters: Values that are both input and output
  • Tables Parameters: Internal tables passed to and from the function module
  • Exceptions: Error conditions that can be raised by the function module

Source Code

  • Global Data: Variables accessible throughout the function module
  • Processing Logic: The actual implementation of the function module
  • Exception Handling: Code to handle error conditions

Function Groups

Function modules are organized into function groups, which:

  • Group related function modules together
  • Share common global data
  • Are stored in the ABAP Repository
  • Have names up to 26 characters long (typically starting with 'F' for standard SAP function groups)

Common Function Module Categories

Standard SAP Function Modules

SAP provides thousands of standard function modules for various purposes:

Data Conversion

Function ModuleDescriptionParameters
CONVERSION_EXIT_ALPHA_INPUTConvert external format to internal formatINPUT, OUTPUT
CONVERSION_EXIT_ALPHA_OUTPUTConvert internal format to external formatINPUT, OUTPUT
UNIT_CONVERSION_SIMPLEConvert units of measureINPUT_UNIT, OUTPUT_UNIT, INPUT_VALUE, OUTPUT_VALUE

Date and Time Processing

Function ModuleDescriptionParameters
DATE_CHECK_PLAUSIBILITYCheck if a date is validDATE, MESSAGES
DATE_GET_WEEKGet week number for a dateDATE, WEEK, YEAR
MONTH_NAMES_GETGet month namesLANGUAGE, MONTH_NAMES

User Interface

Function ModuleDescriptionParameters
POPUP_TO_CONFIRMDisplay confirmation popupTEXT, ANSWER
POPUP_TO_SELECT_MONTHDisplay month selection popupMONTH, YEAR
F4IF_INT_TABLE_VALUE_REQUESTDisplay value help for internal tableRETFIELD, VALUE_TAB

Database Operations

Function ModuleDescriptionParameters
DB_COMMITCommit database changes-
DB_ROLLBACKRollback database changes-
REUSE_ALV_GRID_DISPLAYDisplay ALV gridIT_FIELDCAT, T_OUTTAB

RFC-Enabled Function Modules

Remote Function Call (RFC) enabled function modules can be called from external systems:

  • Must have the "Remote-Enabled Module" attribute set
  • Often used for system integration
  • Require special security considerations

Examples:

  • BAPI_USER_GET_DETAIL
  • BAPI_MATERIAL_GETLIST
  • RFC_READ_TABLE

Custom Function Modules

Organizations often create custom function modules for:

  • Encapsulating business logic
  • Standardizing common operations
  • Implementing interfaces with external systems

Custom function modules typically:

  • Start with 'Z' or 'Y'
  • Are organized into custom function groups
  • Follow naming conventions specific to the organization

Creating and Managing Function Modules

Transactions

  • SE37: Function Builder (create, modify, display function modules)
  • SE80: Object Navigator (access function modules in the ABAP Repository)
  • SE24: Class Builder (for object-oriented development)

Development Process

  1. Create or select a function group
  2. Define the function module interface (parameters and exceptions)
  3. Implement the function module logic
  4. Test the function module using the test function in SE37
  5. Document the function module

Best Practices

Naming Conventions

  • Use descriptive names that indicate the purpose of the function module
  • Follow SAP naming conventions for custom function modules (Z or Y prefix)
  • Use consistent naming patterns within your organization

Interface Design

  • Keep the interface simple and focused
  • Use appropriate parameter types (import, export, changing, tables)
  • Define meaningful exceptions for error handling
  • Document parameters thoroughly

Implementation

  • Write modular, maintainable code
  • Include error handling for all possible scenarios
  • Avoid side effects (changes to global data)
  • Optimize performance for frequently called function modules

Documentation

  • Document the purpose and usage of the function module
  • Describe parameters and exceptions clearly
  • Include examples of how to call the function module
  • Document any dependencies or prerequisites

Function Module vs. Methods

With the introduction of object-oriented programming in ABAP, methods in classes provide an alternative to function modules:

AspectFunction ModulesMethods
ParadigmProceduralObject-oriented
GroupingFunction groupsClasses
StateStateless (except for group data)Can maintain object state
InheritanceNot supportedSupported
PolymorphismNot supportedSupported
Remote callsSupported via RFCSupported via ABAP Objects

Finding Function Modules

Several methods exist to find function modules:

  • Transaction SE37: Search by name, description, or function group
  • Transaction SE80: Browse function groups in the ABAP Repository
  • Transaction SE16/SE16N: Query table TFDIR (function module directory)
  • Code search tools: Search for function module calls in existing code
Edit this page
Last Updated:: 4/12/25, 1:49 AM
Contributors: Taylor Brazelton
Prev
SAP Tables
Next
Data Elements