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.
SAP ABAP | Function Modules
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.
Table of Content
- SAP ABAP | Function Modules
- Creating a New Function Module in SAP ABAP
- Meaning and Importance of Function Modules in SAP ABAP
- Include Programs Vs. Function Modules in SAP ABAP
- Groups of Functions
- Builder of Functions
- Developing a New Program
- Parameter Configuration
- Modules Invoked
- Return Values Handling
- Code Improvement
- Execution
- Example of SAP ABAP Functional Module