Professional Documents
Culture Documents
Function modules are procedures that are defined in special ABAP programs only, socalled function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder (SE37) or ABAP WORKBENCH (SE80). Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
Function Groups
Function groups are containers for function modules The following diagram shows the structure of a function group: The name of a function group, fgrpcan be up to 26 characters long. This is used by the system to create the components of the group (main program and corresponding include programs). When you create a function group or function module in the Function Builder , the main program and include programs are generated automatically.
WITH
BANDIS TECHNOLOGY
The main program SAPL<FG NAME> contains nothing but the INCLUDE statements for the following include programs: L<FG NAME>TOP. This contains the FUNCTION-POOL statement (equivalent for a function group of the REPORT or PROGRAM statement) and global data declarations for the entire function group. L<FG NAME>UXX. This contains further INCLUDE statements for the include programs L<FG NAME>U01, L<FG NAME>U02. These includes contain the actual function modules. The include programs L<FG NAME>F01, L<FG NAME>F02. can contain the coding of subroutines that can be called with internal subroutine calls from all function modules of the group.
CREATING FUNCTION MODULE: OPEN SE80->SELECT FUNCTION GROUP_GIVE A FUNCTION GROUP NAME>HIT ENTER
WITH
BANDIS TECHNOLOGY
SELECT SAVE: SYSTEM CREATES A PRPOGRAM WITH NAME SAPL<FG NAME> AND TWO INCLUDES WITH NAME L<FG NAME>TOP & L<FG NAME>UXX.
WITH
BANDIS TECHNOLOGY
BUSINESS REQUIREMNT: Develop an interface where user will send the material number & receive the material description. Also validate the material. if its not valid material , then raise the exception. Assumption: Get the material description in user login language. Note: SY-LANGU : Its a system variable which stores the user login language Right click on function group_>create->function module
WITH
BANDIS TECHNOLOGY
Different parameters a function module contains IMPORT : To import the business data EXPORT : To export the business data 5 ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT WITH
BANDIS TECHNOLOGY
CHANGING : act like both IMPORT & EXPORT TABLES : act like both IMPORT & EXPORT Note: TABLES parameter is obsolete, so should not use.
WITH
BANDIS TECHNOLOGY
TESTING:
WITH
BANDIS TECHNOLOGY
POSITIVE TESTING:
PRESS F8
WITH
BANDIS TECHNOLOGY
NEGATIVE TESTING:
WITH
BANDIS TECHNOLOGY
10
WITH
BANDIS TECHNOLOGY
TEST IT:
11
WITH
BANDIS TECHNOLOGY
THIS IS WRONG DATA WHICH DOES NOT EXIST IN MARA TABLE. TURN THE DEBUGGER ON
12
WITH
BANDIS TECHNOLOGY
EXAMPLE2: BUSINESS REQUIREMENT: DEVELOP AN INTERFACE WHERE USER WILL SEND THE PERSONNEL NUMBER(PERNR) & NEED THE TRIP NUMBER(REINR) & SCEHMA DESCRIPTION. TABLES USED: PTRV_HEAD , T706T
13
WITH
BANDIS TECHNOLOGY
ANLYZING THE TABLE T706T , WHAT WE FOUND IS , SHEMA DESCRIPTION IS DEPENDENT ON TRIP PROVISION VARIANT
14
WITH
BANDIS TECHNOLOGY
15
WITH
BANDIS TECHNOLOGY
16
WITH
BANDIS TECHNOLOGY
TEST IT:
17
WITH
BANDIS TECHNOLOGY
18
WITH
BANDIS TECHNOLOGY
EXAMPLE 3: BUSINESS REQUIREMENT; USER WILL SEND THE PERNR AND GET THE TRIP GENERAL DETAILS(PTRV_HEAD). TABLES USED: PTRV_HEAD. 1. FIRST CRAETE A TABLE TYPE IN GLOBAL INCLUDE I.E LZFG321TOP
19
WITH
BANDIS TECHNOLOGY
2. ACTIVATE IT
20
WITH
BANDIS TECHNOLOGY
4. SELECT YES
21
WITH
BANDIS TECHNOLOGY
6. Continue
22
WITH
BANDIS TECHNOLOGY
Test this:
23
WITH
BANDIS TECHNOLOGY
NON CLASS BASED EXCEPTIONS IN FUNCTION MODULE Raising Exceptions There are two ABAP statements for raising exceptions. They can only be used in function modules:
24
WITH
BANDIS TECHNOLOGY
1.
The effect of these statements depends on whether the calling program handles the exception or not. The calling program handles an exception If the name of the <EXCEPTION> exception or OTHERS is specified after the EXCEPTION option of the CALL FUNCTION statement. If the calling program does not handle the exception The RAISE statement terminates the program and switches to debugging mode.
The MESSAGE..... RAISING statement displays the specified message. Processing is continued in relation to the message type. If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE..... RAISING statement does not display a message. Instead, it fills the system fields sy-msgid, sy-msgty, sy-msgno , and SY-MSGV1 to SY-MSGV4. 1. Create a Function Module . 2. Make sure a message class ZMSG is created in SE91 and &1 &2 &3 &4 is maintained for message number 999.
25
WITH
BANDIS TECHNOLOGY
26
WITH
BANDIS TECHNOLOGY
TEST:
27
WITH
BANDIS TECHNOLOGY
*Note: Difference between class based exception & non class based exception will be covered in detail in OOPS class
ASSIGNMENT: GENERATE AN INTERFACE WHERE USER WILL SEND THE SALES DOCUMENT NUMBER(VBELN) AND GET THE PARTNET FUNCTION DETAILS ALONG WITH PARTNER FUNCTION DESCRIPTION. EXPECTED OUTPUT: VBPA-VBELN VBPA-PARVW TPART-VTEXT VBPA-KUNNR
28
WITH
BANDIS TECHNOLOGY