Function Modules in SAP

 

Some Important Function Modules

RANDOM_I4

FITRV_CALCULATOR

HR_99S_MONTHS_BETWEEN_DATES

MONTHS_BETWEEN_TWO_DATES

RH_GET_DATE_DAYNAME

DATE_GET_WEEK

SPELL_AMOUNT

F4_DATE

F4_CLOCK

F4_FILENAME

Function Modules
  • SE37 is the transaction code for creating function modules.
  • A function module name has a practical minimum length of three characters and a maximum length of 30 characters
  • Customer function modules must begin with Y_ or Z_
  • The name of each function module is unique within the entire BW system
  • Function modules have a special screen used for defining parameters. Parameters are not defined via ABAP/4 statements.
  • Leaving a function module is accompanied via the RAISE statement instead of check, exit or stop.
  • Every function module should be assigned to a Function group.
  • Function Group is to group all logically related Function Modules.
Function Groups

As stated before, a function group is a program that contains function modules. With each R/3 system, SAP supplies more than 5000 pre-existing function groups. In total, they contain more than 30,000 function modules. If the functionality you require is not already covered by these SAP supplied function modules, you can also create your own function groups and function modules.

Menu path to create a function group in the initial Screen of SE37 transaction is

Goto -> Function Groups -> Create Group

Syntax for the CALL FUNCTION Statement

The following is the syntax for the call function statement.

Call Function 'Sample'

[exporting p1 = v1 ....]

[importing p2=v2 ...]

[changing p3=v3 ...]

[tables p4=it ...]

[exceptions x1=n [others = n] ] .

where:

  • 'Sample' is the function module name
  • p1 through p4 are parameter names defined in the function module interface
  • v1 through v3 are variable or field string names defined within the calling program
  • 'IT' is an internal table defined within the calling program
  • n is any integer literal; n cannot be a variable
  • x1 is an exception name raised within the function module
  • All additions are optional
  • Call Function is a single statement. Do not place periods or commas after parameters or exception names
  • The function module name must be coded in upper case. If it is coded in lowercase, the function will not be found and a short dump will result.
  • It is recommended to use Pattern Button to call a Function Module
Function Module Interface

To pass parameters to a function module, you must define a function module interface. The function module interface is the description of the parameters that are passed to and received from the function module.

A function module interface includes

  • Import parameters
  • Export parameters
  • Changing parameters
  • Table parameters and
  • Exceptions
Import Parameters

Import   parameters are variables or field strings that contain values passed into the function module from the calling program.

Export Parameters

Export Parameters are variables or field strings that contain values returned from the function module.

Changing Parameters

Changing parameters are variables or field strings that contain values that are passed into the function module,  changed by the code within the function module, and then returned.

Table Parameters

Table parameters are internal tables that are passed to the function module, changed within it, and returned. The internal tables must be defined in the calling program.

Exceptions

An exception is a name for an error that occurs within a function module.

Example

Program which is calling a user defined function module that displays text

REPORT Sample1.

*--calling the function module.

CALL FUNCTION 'ZDISPLAY'

EXPORTING

text        = 'GOD is great'

row         = 12

column  =40

text_color = 3.
*--calling the function module.

CALL FUNCTION 'ZDISPLAY'

EXPORTING

text    ='Rose is red'

row    =5

column  = 10

text_color  =6.

*--------------------------------------------------------

Function module preparation in SE37 transaction.

*--Import Parameters

TEXT TYPE C

ROW TYPE I

COLUMN TYPE I

TEXT_COLOR TYPE I
*--Source code

SKIP TO LINE row.

POSITION column.

WRITE text
COLOR = text_color.

Comments

Popular posts from this blog

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

OPEN SQL EXAMPLES IN ABAP – PART 2

Domains and Data Elements