You are on page 1of 28

Function Modules

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.

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

SELECT YES TO CREATE A FUNCTION GROUP

SELECT SAVE: SYSTEM CREATES A PRPOGRAM WITH NAME SAPL<FG NAME> AND TWO INCLUDES WITH NAME L<FG NAME>TOP & L<FG NAME>UXX.

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

RIGHT CLICK & ACTIVATE THE FUNCTION GROUP

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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

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

CONTACT: 040-64608866 ,9030098866

CHANGING : act like both IMPORT & EXPORT TABLES : act like both IMPORT & EXPORT Note: TABLES parameter is obsolete, so should not use.

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

TESTING:

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

POSITIVE TESTING:

PRESS F8

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

NEGATIVE TESTING:

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

DEVLOPEMENT IS DONE!!. USE THIS INTERFACE IN ANY PROGRAM.

10

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

TEST IT:

11

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

THIS IS WRONG DATA WHICH DOES NOT EXIST IN MARA TABLE. TURN THE DEBUGGER ON

12

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

AGAIN TEST WITH RIGHT ENTRY

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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

ANLYZING THE TABLE T706T , WHAT WE FOUND IS , SHEMA DESCRIPTION IS DEPENDENT ON TRIP PROVISION VARIANT

1. FIRST CREATE A STRUCTURE IN SE11

14

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

2.CREATE A TABLE TYPE

1. CREATE A FM WITH REQUIRED PARAMTERS

15

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

16

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

TEST IT:

17

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

18

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

2. ACTIVATE IT

3. DOUBLE CLICK TO CREATE THIS SUBROUTINE

20

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

4. SELECT YES

5. CONTINUE WITH SELECTED INCLUDE I.E LZFG321F01

21

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

6. Continue

22

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

Test this:

23

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

1.

RAISE <EXCEPTION> 2. MESSAGE.....RAISING <EXCEPTION>..

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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

26

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

TEST:

DEVELOP A REPORT & CALL THIS FUNCTION MODULE

27

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

*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

ABAP/CA/OOPS/WORKFLOW/HR ABAP/ADOBE FORMS PROJECT

WITH

BANDIS TECHNOLOGY

CONTACT: 040-64608866 ,9030098866

You might also like