Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem in understanding Functional Module

0 Likes
2,953

Hi frnds,

Please teach me the process understanding any kind of Funtional Module.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,459

Go to SE37 Transaction Code.

Give the Function Module Name and go for Display

Go to Function Module Documentation tab in the Right side of the Window.

Note :

Maximun SAP Provides Documentation for any function Modules, If there is no documentation is found go for where used list or else go to SDN and Search, otherwise experience people will tell the Functionality of a Perticular Function Module.

5 REPLIES 5
Read only

Former Member
0 Likes
1,459

Please dont post such weird question.

Learn ABAP.

Read only

Former Member
0 Likes
1,459

go to sm37

open the desired function module there u'll get description of fields present inside the function module

Read only

Former Member
0 Likes
1,460

Go to SE37 Transaction Code.

Give the Function Module Name and go for Display

Go to Function Module Documentation tab in the Right side of the Window.

Note :

Maximun SAP Provides Documentation for any function Modules, If there is no documentation is found go for where used list or else go to SDN and Search, otherwise experience people will tell the Functionality of a Perticular Function Module.

Read only

Former Member
0 Likes
1,459
Read only

Former Member
0 Likes
1,459

hi kishore,

1. Start the ABAP Workbench.

2. Choose Function Builder.

The Function Builder initial screen appears:

3. Enter the name of the function module that you want to create, change, display, or test.

You can select any of the following components:

Interface Lists the interface parameters (import, export, tables, exceptions), attributes, and parameter documentation.

If you are working in change mode, you can extend the parameter list.

Source code Displays the source code between the FUNCTION and ENDFUNCTION statements.

Global data Displays the TOP include of the function group, containing the global data declarations.

Main program Displays the main program with its list of includes.

4. Select one of the above components.

5. Choose Display or Change.

Looking Up Function Modules

Before creating a new application, you can search in the Function Builder to see if suitable function modules already exist. You can do this in the Repository Information System or in the Application Hierarchy.

Using the Repository Information System

To search for a module, choose Find from the initial screen of the Function Builder. The system displays the standard Function Module search screen.

The Repository Information System's search screen offers you a number of selection options. Only some of these options are displayed when you first call the screen. To view the rest of the selection options, choose Edit ï‚® All selections :

Enter either a function group or a package for a quick search. You can also limit your selection to function modules of a particular type. You can search for remote function call (RFC) modules or for those that are used in update routines.

You can also generate a list of only those function modules that are released for customers. For more information about searching with the Repository, see The Repository Information System .

Using the Application Hierarchy

You can also search for function modules using the Workbench's Application Hierarchy. The Application Hierarchy provides an overview of all the applications in your R/3 system. You can use this hierarchy to display function modules associated with particular applications. Proceed as follows:

The Application Hierarchy

1. In the Function module field of the initial screen of the Function Builder, or in the CALL FUNCTION field of the insert statement dialog box, press F4.

2. Choose SAP applications in the Input Help Personal Values List dialog box.

The system branches to the SAP application hierarchy.

3. Open the application hierarchy down to the lowest level, and double-click a function module to choose it.

The system jumps back to the point where you started your search, and inserts the name of the function module in the corresponding field.

Getting Information about Interface Parameters

A function module's interface determines how you can use the module from within your own program. It is important that you understand a module's programming interface before you use the module. There are five different interface parameters:

Name Explanation

Import Values transferred from the calling program to the function module. You cannot overwrite the contents of import parameters at runtime.

Export Values transferred from the function module back to the calling program.

Changing Values that act as import and export parameters simultaneously. The original value of a changing parameter is transferred from the calling program to the function module. The function module can alter the initial value and send it back to the calling program.

Tables Internal tables that can be imported and exported. The internal table's contents are transferred from the calling program to the function module. The function module can alter the contents of the internal table and then send it back to the calling program. Tables are always passed by reference.

Exceptions Error situations that can occur within the function module.

The calling program uses exceptions to find out if an error has occurred in the function module. It can then react accordingly.

To find out what parameters are needed to call a function module, enter the module's name in the initial screen of the Function Builder and display the object component Interface:

The following display uses a tab, with separate pages for various parts of the interface information (administration, formal parameters, exceptions, and documentation). Our example contains a list of all import parameters and their further attributes:

Particularly important here is the information about which parameters must be passed when the function module is called. If a parameter does not have to be passed, select the Optional checkbox.

If the parameter does have to be passed, the checkbox is deselected.

Choose Changing or Tables to see the changing and tables parameters and whether they are optional or required.

There is no Optional checkbox for export parameters, since they are always optional.

You can also specify the data type of a formal parameter by linking it to a data type in a type pool. Type pools are ABAP Dictionary objects that allow you to define your own global types. If you want to use the types in a type pool for formal parameters, you must declare the type pool in the TOP include of the function group. You can then enter the types in the Reference type field for formal parameters.

In the Reference field/structure field, you can enter ABAP Dictionary reference structures, against which the system checks the actual parameters at runtime.

Use the Default field to assign a default value to a parameter. In the Reference field, you can indicate whether you want to pass the parameter by reference or by value.

For more information about setting the attributes of parameters, see Specifying Parameters and Exceptions

The Documentation tab page contains short descriptions of the parameters and exceptions. To display further information about a particular parameter or exception, double-click its name.

For a full description of the task of the function module, double-click the Short text field, or choose Function module doc.

Displaying Function Module Attributes

The Administration feature of the Function Builder shows you a function module's attributes. Administration information includes the function module's:

u2022 Function Group

u2022 Process type

u2022 status

If you want to print out all a module's interface information, choose Function module ï‚® Print. This option lets you specify the aspects of the function module (documentation, code, and so on) you want.

Calling Function Modules From Your Programs

You can call a function module from within any ABAP program by using the following ABAP statement:

CALL FUNCTION <function module>

[EXPORTING f1 = a1.... fn = an]

[IMPORTING f1 = a1.... fn = an]

[CHANGING f1 = a1.... fn = an]

[TABLES f1 = a1.... fn = an]

[EXCEPTIONS e1 = r1.... en = rn

[ERROR_MESSAGE = rE]

[OTHERS = ro]].

You enter the name of the function module <function module> as a literal. You pass parameters by explicitly assigning the actual parameters to the formal parameters in lists following the EXPORTING, IMPORTING, CHANGING, and TABLES options.

You assign parameters in the form <formal parameter> = <actual parameter>

If you assign more than one parameter within an option, separate them with spaces (or by starting a new line).

u2022 The EXPORTING option passes the actual parameter ai to the formal input parameter.fi. The formal parameters must be declared as import parameters in the function module. The parameters may have any data type. If you specify a reference field, the system checks the parameter.

u2022 The IMPORTING option passes the formal output parameter fi of the function module to the actual parameter ai. The formal parameters must be declared as export parameters in the function module. The parameters may have any data type.

u2022 The CHANGING option passes the actual parameter ai to the formal parameter fi. After the function module has been processed, the system returns the (changed) values of the formal parameters fi to the actual parameters fi. The formal parameters must be declared as CHANGING parameters in the function module. These parameters, too, may have any data type.

u2022 The TABLES option passes internal tables between the actual and formal parameters. The internal tables are always passed by reference. The parameters in this option must always reference internal tables.

u2022 The EXCEPTIONS option allows you to react to errors in the function module. Exceptions are provided as special parameters in order to be able to react to possible error events during processing of the function module. When an exception occurs, function module processing terminates. Example: If exception ei is triggered, the system stops processing the function module and does not pass any values back to the program. The calling program receives the exception ei by assigning the value ri as a return code to the system field SY-SUBRC. This functions as a return code. ri must be a numeric literal. You can then evaluate the system field in the calling program.

You can change the error handling in the function module by specifying an ERROR_MESSAGE in the EXCEPTIONS list. Normally, messages should only be called in exception handling (using the statements MESSAGE.....RAISING or RAISE within the function module). For more information, refer to the section Overview of Coding for Function Modules.

Using ERROR_MESSAGE, you can have the system treat messages that are called in the function module, by exception, without this explicit treatment as follows:

o Messages of classes S, I, and W are ignored (but entered in the log if you are running the program in the background).

o Messages of classes E and A cause the function module to terminate as though the ERROR_MESSAGE exception had been triggered (SY-SUBRC is set to rE).

If you enter OTHERS in the EXCEPTION list, you can allow for all exceptions, even though they are not listed. It acts as a default exception.

You can use the same number ri for different exceptions, as long as the system does not require further specification of the exceptions.

You can use the function Pattern in the ABAP editor to call a function from within your coding. Perform the following steps:

1. Position the cursor at the point in your coding where you want to call the function.

2. Choose Pattern.

3. In the dialog box that then appears, mark the selection field in front of CALL FUNCTION.

4. Enter the name of the function module in the input field.

If you do not know the name, you can search using the input help key.

5. Choose Continue.

The system inserts the function module with the interface into your coding.

6. Maintain the appropriate parameters and handle the exceptions.

In our example, the function module is displayed as follows:

7. If you need more information about the function module, you can call this up through the information icon. The Help dialog box appears. Select Function module, and enter the function module name. Choose Continue.

The system displays the interface definition for the function module. From there, you can display all of the other function module elements.

Parameters not marked as commentary elements must be supplied with values by your program. For this purpose, you can use fixed values or parameters.

The import interface is commented out. In your coding, remove the asterisk (*) before IMPORTING and pass the required data of the function module to variables.

There are other parameters that you can use with the CALL FUNCTION statement if the function is to run in an update task or on a remote host.

When a function module runs in the update task, the system processes it asynchronously. This call is not executed immediately. Instead, the system waits until the next database update is triggered by COMMIT WORK. Running a function module on a remote host means that you call a function module within another SAP system or a non-SAP system.

For further information about how to call function modules from programs, see the Function Modules section of the u201CABAP Useru2019s Guide u201C

Creating a Function Group

1. Choose Goto ï‚® Function groups ï‚® Create group.

2. Specify the function group name and a short text.

3. Choose Save.

Function group names are freely definable up to a maximum length of 26 alphanumeric characters. Remember to observe the normal naming conventions for the first character (A-X for SAP development, Y and Z for customers).

When you create a new function group, the system automatically creates a main program containing two includes. Like any other programs and includes, you can display them in the Repository Browser.

The name of the main program is assigned by the system. This is made up of the prefix SAPL followed by the function group name. For example, the main program for function group SXXX is called SAPLSXXX.

The names of the include files begin with L followed by the name of the function group, and conclude with UXX ( or TOP for the TOP include). The TOP include contains global data declarations that are used by all of the function modules in the function group. The other include file within the main program is used to hold the function modules within the group.

Specifying Parameters and Exceptions

The parameters and exceptions for a function module constitute its interface. The Function Builder contains a tab page for each of the following interface components: tables, exceptions, import, export, and changing parameters.

To set the parameters and exceptions of your function module:

1. Enter the function module name on the initial screen of the Function Builder.

2. Select Interface and choose Change.

3. Enter any further required information for the parameters (import, changing, export, or table).

Field Explanation

Parameter Name of the formal parameter, for identification

Reference field/

structure A database field, component of an ABAP Dictionary structure, or an entire ABAP Dictionary structure. This is the same as the ABAP Dictionary field name in the Reference field/ reference structure column.

Use this field to create a field based on an ABAP Dictionary field. You should always use a reference structure if the data in the parameter must have the same structure as the reference field (for example, when you want to add new entries to the database).

Reference type You can enter any system type, either generic or fully typed.

For further information, refer to the Data Types section of the ABAP User's Guide.

Default This is the parameter's default value. Applies to import and changing parameters only. The system transfers this value to the function module if the caller sets its own value for that parameter.

Reference The parameter reference. Specify this if you want the parameter to be called by reference instead of by value. When a parameter is called by reference, the system points to the original parameter without making a copy of it. The function module works with and, if necessary, alters the original parameter and not a copy. Table parameters are always passed by reference.

4.

5. Enter the exceptions.

The exceptions screen only allows you to enter a text with which the exception can be triggered in the function module.

6. You can also document the interface on this screen.

On the documentation screen, you can enter short descriptions of the parameters and exceptions.

You can also write full documentation of the entire function module from here.

For further information, see Documenting and Releasing Function Modules

7. Save your entries.

Understanding Function Module Code

The system predefines the organization of objects for a function group and its function modules. When you create a function group, the Workbench automatically generates a main program, global data, and source code. The system uses the format SAPL<fgrp> to name the Main program. The <fgrp> variable is the function group's name.

For each successive function module in a function group, the Workbench automatically creates an include file. You can view this include file by selecting Source Code on the Function Builder initial screen. The system gives the include file a name using the form L<functgrp>U<nn> . For example, in the function group FGRP, the first function module resides in include file LFGRPU01. The subsequent function modules are in include files LFGRPU02, LFGRPU03, LFGRPU04, and so on.

The Main Function Program

The Function Builder generates the main function program includes for you. The system uses the L<functgrp>UXX form to name a main function program. So, for the function group FGRP, the main functions include would be LFGRPUXX .

Writing Function Modules

Once you have defined the interface of your function module, you can start writing the code itself.

On the initial screen of the Function Builder, select Source code. The ABAP Editor appears, in which you can write the code of the function module between the FUNCTION and ENDFUNCTION statements.

The parameters and exceptions of the function module appear in the Editor as commented lines.

A few features to bear in mind when writing function modules:

Data Handling in Function Modules

u2022 You do not declare export and import parameters in the source code of the function module. The system does this automatically, using an INCLUDE program that inserts a list of the parameters as comment lines in the source code.

u2022 You can declare local data types and objects in function modules in the same way that you would in subroutines.

u2022 You can declare data using the TYPES and DATA statements in L<fgrp>TOP. This data is then available to all of the function modules in a function group. The system creates the data the first time a function module in the group is called. It always saves the values from the last function module to be called.

Calling Subroutines from Function Modules

You can call various subroutines from function modules.

u2022 You can write internal subroutines, adding them after the ENDFUNCTION statement. These subroutines can be called from all function modules in the group. However, we recommend that you only call them from the function module in which you wrote the function module. This makes your function group easier to understand.

u2022 If you want to create internal subroutines and call them from all of the function modules in the function group <fgrp>, use the special INCLUDE programs L<fgrp>F<XX>.

u2022 You can call any external subroutines from a function module.

Triggering Exceptions

Within a function module, you can address all exceptions using the names you defined in the interface. Exceptions can be handled either by the system or by the calling program. You decide this when you call the function, by assigning a numeric value to the exceptions that you want to handle yourself. For further information, see Calling Function Modules From Your Programs.

Exceptions must be explicitly triggered.

There are two ABAP statements that may only be used in function modules that you can use to trigger exceptions:

Syntax

RAISE <Exception>.

MESSAGE..... RAISING <Exception>.

The effect of these statements depends on whether you handle the exception in the calling program or let the system process it.

u2022 If you trigger the exception in the RAISE statement and the calling program is to handle it, the function module processing is terminated, and the numeric value assigned to the exception is placed in the system field SY-SUBRC. Further processing then takes place in the calling program.

If the calling program fails to handle the exception, the system triggers a runtime error.

u2022 If you use the MESSAGE... RAISING statement, the processing is similar if you want to handle the exception in the calling program. If you want the system to handle the exception, there is no runtime error generated in this case. Instead, processing continues, and the system displays a message with the defined type. To do this, you must specify the MESSAGE-ID in the first statement of the include program L<fgrp>TOP. The MESSAGE... RAISING statement also enters values in the following system fields:

o SY-MSGID (message ID)

o SY-MSGTY (message type)

o SY-MSGNO (message number)

o SY-MSGV1 to SY-MSGV4 (contents of the fields <f1> to <f4> that are included in the message).

For further information, see the keyword documentation for the MESSAGE statement.

Here is an example for raising exceptions:

Suppose we have the following function module:

If N1 is unequal to zero, it divides Z1 by N1. Otherwise, it triggers the exception DIV_ZERO.

Example: Program MDTEST calls the function MY_DIVIDE:

When you run the program, the output looks like this:

Result = 1,500000

If you replace N1 = 4 with N1 = 0 in the EXPORTING list, the program MDTEST processes the exception DIV_ZERO by assigning the value 1 to SY-SUBRC. The output now looks like this:

Division by zero

Checking and Activating Modules

Before you can activate a function module, you must check to make certain that the module's syntax is correct. Open one of the module's interface screens and use Function module ï‚® Check to check your module. Checking Source Code explains in detail how to use this feature.

Newly created function modules are automatically set to Inactive.

If a function module is inactive, the normal syntax check only checks that module. If you want to check the module as part of the whole function group without activating it, choose Function module ï‚® Check ï‚® Main program. The check program checks all of the function modules and include programs regardless of whether they are active or inactive.

To activate a completed function, choose Function module ï‚® Activate. An activated function module is included in all syntax-checking for the module's entire function group. When the system checks an activated function module's syntax, the system actually applies the check to all activated members of the function group. When you activate a function module, syntax-checking is performed automatically.

See also:

Inactive sources in the ABAP Workbench.

Restoring the Active Version of a Function Module

You can replace the inactive version of a function module with its last active version by choosing Function module ï‚® Return to active version. The inactive version is deleted.

Step1:GOTO se80.

Step2:Select : Package

Create Package named as u want like u201CZMUKESHu201D

Step3:Click on u201CDisplayu201D icon with u201CSPACu201D

There we see CREATE OBJECT POP Up and we have to click on u201CYESu201D

STEP4:After clicking u201CYESu201D we come to Package Builder : create Package where we edit the short description and we have to choose one of the Application component

STEP5: Choose software component here u201CHomeu201D is chosen.

STEP6: After clicking on u201CCREATEu201D we requested for request

STEP7: Create a request there .

STEP8:After this we get our Package in Object Name Column :

STEP9:Select u201CFunction groupu201D and named as we want.

STEP10:Clicking on display we again ask to create as in previous case:

STEP11: We are at Create Function Group screen where we gave description for Function Group

STEP12:After passing package to u201CCreate object Directory Entryu201D click on local object to save the function group.

STEP13: we get two includes in our function group which are SAP provided and we cannot change them. But we are now able to create function modules and add them to this function group we created just .

STEP14: Before leaving to Object Navigator right click on u201CYMUKESH1u201D and activate it

STEP15:GOTO SE37 to create any function module hereu201DYMUKESHu201D click on create:

STEP16:We get to FUNCTION BUILDER where we saw 7 tabs , who have there own significance which are given in theory at the starting of the DOCument. Here we have to give our Function group created earlier.

Always select for u201CNormal Function moduleu201D for extractors

i think this will help u

regards,

sindhu.