Step 1 − Go to transaction SE38 and create a new program called Z_SPELLAMOUNT.
Step 2 − Enter some code so that a parameter can be set up where a value could be entered and passed on to the function module. The text element text-001 here reads ‘Enter a Value’.
Step 3 − To write the code for this, use CTRL+F6. After this, a window appears where ‘CALL FUNCTION’ is the first option in a list. Enter 'spell_amount' in the text box and click the continue button.
Step 4 − Some code is generated automatically. But we need to enhance the IF statement to include a code to WRITE a message to the screen to say "The function module returned a value of: sy-subrc” and add the ELSE statement so as to write the correct result out when the function module is successful. Here, a new variable must be set up to hold the value returned from the function module. Let's call this as 'result'.
Following is the code −
REPORT Z_SPELLAMOUNT.
data result like SPELL.
selection-screen begin of line.
selection-screen comment 1(15) text-001.
parameter num_1 Type I.
selection-screen end of line.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = num_1
IMPORTING
IN_WORDS = result.
IF SY-SUBRC <> 0.
Write: 'Value returned is:', SY-SUBRC.
else.
Write: 'Amount in words is:', result-word.
ENDIF.
Step 5 − The variable which the function module returns is called IN_WORDS. Set up the corresponding variable in the program called ‘result’. Define IN_WORDS by using the LIKE statement to refer to a structure called SPELL.
Step 6 − Save, activate and execute the program. Enter a value as shown in the following screenshot and press F8.
The above code produces the following output −
Spelling the Amount
Amount in words is:
FIVE THOUSAND SIX HUNDRED EIGHTY
73 videos|68 docs
|
1. What is SAP ABAP? |
2. What are Function Modules in SAP ABAP? |
3. How can Function Modules be created in SAP ABAP? |
4. Can Function Modules in SAP ABAP be used across different SAP systems? |
5. How are Function Modules different from Subroutines in SAP ABAP? |
|
Explore Courses for Software Development exam
|