Software Development Exam  >  Software Development Notes  >  Learn and Master SAP ABAP  >  SAP ABAP - Function Modules

SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development PDF Download

Introduction

  • Function modules make up a major part of a SAP system, because for years SAP has modularized code using function modules, allowing for code reuse, by themselves, their developers and also by their customers.
  • Function modules are sub-programs that contain a set of reusable statements with importing and exporting parameters. Unlike Include programs, function modules can be executed independently. SAP system contains several predefined function modules that can be called from any ABAP program. The function group acts as a kind of container for a number of function modules that would logically belong together. For instance, the function modules for an HR payroll system would be put together into a function group.
  • To look at how to create function modules, the function builder must be explored. You can find the function builder with transaction code SE37. Just type a part of a function module name with a wild card character to demonstrate the way function modules can be searched for. Type *amount* and then press the F4 key.
    SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development
  • The results of the search will be displayed in a new window. The function modules are displayed in the lines with blue background and their function groups in pink lines. You may look further at the function group ISOC by using the Object Navigator screen (Transaction SE80). You can see a list of function modules and also other objects held in the function group. Let's consider the function module SPELL_AMOUNT. This function module converts numeric figures into words.

Creating a New Program

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.

SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development

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.

SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development

The above code produces the following output −

Spelling the Amount 

Amount in words is: 

FIVE THOUSAND SIX HUNDRED EIGHTY

The document SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development is a part of the Software Development Course Learn and Master SAP ABAP.
All you need of Software Development at this link: Software Development
73 videos|68 docs

Top Courses for Software Development

FAQs on SAP ABAP - Function Modules - Learn and Master SAP ABAP - Software Development

1. What is SAP ABAP?
Ans. SAP ABAP (Advanced Business Application Programming) is a high-level programming language used for developing business applications in the SAP environment.
2. What are Function Modules in SAP ABAP?
Ans. Function Modules in SAP ABAP are reusable programs that can be called from other programs or transactions to perform specific tasks or calculations.
3. How can Function Modules be created in SAP ABAP?
Ans. Function Modules in SAP ABAP can be created using transaction code SE37. Developers can define the interface, parameters, and logic of the Function Module in this transaction.
4. Can Function Modules in SAP ABAP be used across different SAP systems?
Ans. Yes, Function Modules in SAP ABAP can be transported between different SAP systems using transport requests, making them reusable in various environments.
5. How are Function Modules different from Subroutines in SAP ABAP?
Ans. Function Modules in SAP ABAP can be called from external programs and can return values, while Subroutines are called within the same program and cannot return values.
73 videos|68 docs
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

past year papers

,

practice quizzes

,

video lectures

,

Free

,

Viva Questions

,

SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development

,

SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development

,

Extra Questions

,

Exam

,

study material

,

MCQs

,

Objective type Questions

,

Previous Year Questions with Solutions

,

ppt

,

Important questions

,

SAP ABAP - Function Modules | Learn and Master SAP ABAP - Software Development

,

shortcuts and tricks

,

Summary

,

Semester Notes

,

pdf

,

mock tests for examination

,

Sample Paper

;