‎2007 Jun 20 8:34 AM
Is their any need to create function Module.
If yes thn where do we require it and how to do it.
‎2007 Jun 20 8:36 AM
Hi
Function Modules;
Check this matter.
Function Modules are Global ABAP programs created by SAP for reusable purpose.they have IMPORT,EXPORT and TABLE parameters, and EXCEPTIONS to through when error occurs.
You can create them from TCode SE37.
Go through the following doc:
Function modules are cross-program, reusable procedures that are organized into function groups, and whose functions are implemented between the statements FUNCTION and ENDFUNCTION. Function modules and their interfaces are created in the Function Builder.
Function Module Interfaces
The parameter interface of a function module is defined in the Function Builder. It includes the definition of interface parameters and the specification of exceptions that can be triggered by a function module. The Function Builder automatically generates comment lines below the FUNCTION statement in the source code of the function module, which represent the interface of the function module with the following syntax:
Syntax
... [IMPORTING parameters]
[EXPORTING parameters]
[CHANGING parameters]
[TABLES table_parameters]
[{RAISING|EXCEPTIONS} exc1 exc2 ...]
The syntax and semantics of IMPORTING, EXPORTING, CHANGING, RAISING, and EXCEPTIONS mainly correspond to the definition of method interfaces with [CLASS-]METHODS. The additional option of defining table parameters using TABLES is obsolete.
Interface parameters
The interface parameters are defined on the relevant tab pages in the Function Builder.
IMPORTING parameters are input parameters. When the function module is called, a suitable actual parameter must be specified for every non-optional input parameter. The content of the actual parameter is passed to the input parameter when the call is made. The content of an input parameter for which 'pass by reference' is defined cannot be changed in the function module.
EXPORTING parameters are output parameters. When the function module is called, a suitable actual parameter can be specified for every output parameter. The content of an output parameter that is defined for 'pass by value' is transferred to the actual parameter if the function module is completed without errors. An output parameter that is defined for pass by reference is not initialized when the function module is called.
CHANGING parameters are input and output parameters. When the function module is called, a suitable actual parameter must be specified for every non-optional input or output parameter. When the function module is called, the content of the actual parameter is passed to the input/output parameter, and when the function module is completed, the content of the input/output parameter is passed to the actual parameter.
TABLES parameters are table parameters. Table parameters are obsolete CHANGING parameters that are typed as standard tables with a header line. If an internal table without a header line or a table body is passed as an actual parameter to a formal parameter of this type, an empty local header line is generated in the function module. If an internal table with a header line is used as an actual parameter, both the table body and the header line are passed to the function module. Pass by value is not possible in formal parameters defined using TABLES. Formal parameters defined with TABLES can be replaced by formal parameters defined with CHANGING. A local work area can be created for the internal table in the function module by using the addition LIKE LINE OF itab of the DATA statement.
Exceptions
The exception of a function module are defined on the Exceptions tab page in the Function Builder. Here you can select exception classes to define whether class-based exceptions are declared or non-class-based exception are defined. Class-based exceptions are represented in the above syntax by RAISING, and non-class-based exceptions are represented by EXCEPTIONS.
The addition RAISING is used to declare class-based exceptions that can be propagated from the function module to the caller. Exceptions in the categories CX_STATIC_CHECK and CX_DYNAMIC_CHECK must be explicitly declared, otherwise a propagation can lead to an interface violation. A violation of the interface leads to the treatable exception CX_SY_NO_HANDLER. Exceptions of the category CX_NO_CHECK are implicitly always declared. The declaration of exceptions of the category CX_STATIC_CHECK is statically checked in the syntax check. For exceptions of the category CX_DYNAMIC_CHECK, the check is not performed until runtime. In a function module in which class-based exceptions are declared with the RAISING addition, the statement CATCH SYSTEM-EXCEPTIONS cannot be used. Instead, the relevant treatable exceptions should be handled in a TRY control structure.
The addition EXCEPTIONS is used to define a list of non-class-based exceptions that can be triggered in the function module using the statements RAISE or MESSAGE RAISING. Exceptions defined in this way - as with formal parameters - are bound to the function module and cannot be propagated. If an exception of this type is triggered in a function module, and no return value has been assigned to it with the homonymous addition EXCEPTIONS of the CALL FUNCTION statement when the call was made, this leads to a runtime error.
Note
For new developments after release 6.10, SAP recommends that you work with class-based exceptions that are independent of the function module.
RFC is a technology which is used to access a functions (Modules) from
the remote systems.
If a function module is set as remote enabled which can be access from
the remote system via RFC.Eg: U can access the Remote enabled function modules in ur VB,Webdynpro,Java,Visual composer program.
A function module can be set as remote enabled by SE37->Go to ur FM->click the option Button "remote enabled".
But Normal function modules can not accessd from the remote system.
Good Example for RFC enabled function module is : BAPI(Business Application Programming Interface)
Note: All BAPIs are Remote enabled but not all remote enabled function modules are BAPI.
CALLING A FUNCTION MODULE:
1)In U ABAP Editor --> Click "Patter" ---> Selection Option Button "Call Function"
--> Write the Corresponding FM name --> Hit Enter
2)The appropriate import ,export Parameters will be displayed in ur editor
3)Pass the Values Here.
Also check these links.
http://www.geocities.com/victorav15/sapr3/abapfun.html
Check this link:
http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/d94b78ebf811d295b100a0c94260a5/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm
Check this link:
http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/d94b78ebf811d295b100a0c94260a5/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm
See the following links:
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm
Reward points for useful Answers
Regards
Anji
‎2007 Jun 20 8:41 AM
Hi,
Basically the need to create Function module arises when you wish to write a code to do a functionality which can be reused in other programs...
example...
You wish to read data from a customer control table you can create a function module for the same to read the table and do the necessary processing depending on the input parameters
1. Goto SE37.
2. Follow the path
Goto --> Function Group --> Create Group
3. Then enter a function name Z***** and click create.
The following link gives you more information about the functions and groups and others:
http://cma.zdnet.com/book/abap/ch19/ch19.htm
Please do not confuse it with customer master..We have written a function module to read a control table created by us eg ZLL_GEN_CTRL, where we define certain parameters and corresponding arguments.
ZLL_GEN_CTRL.
Ctrl Argument.
EMAILTO_MPC XYZ@test.com
EMAILCC_MPC ABC@test.com,DEF@test.com
We use the same in many programs so to make it standard and easy to fetch the data...we have created a fm.
call function 'Get_control_data'
exporting
ctrl = 'EMAILCC_MPC'
delimeter = ','
importing
arg = larg
tables
dtab = itab.
In the function module we return the result of the select statement and in dtab we split the argument on the delimeter and update the internal table with the data as individual row.
Regards
‎2007 Jun 20 8:51 AM
Hi Swati,
Function modules are mainly used for "Code Reusability"....If once you wrote a peice of code for a particular program say
//sum
int a ,b,result.
result =a+b.
print result.
if suppose you want to use the same code in some other program,u no need to write it again,you can save the memory capacity as well as time.
Same way ABAP also has function modules which performs many functions which is used in other programs too...
FMs are created in Tcode SE37 there give ZXXXX FM name and click on create button. it will asks a Function group it is nothing but a group FM will save under a Function group. Function module will create and opens it.
You can find the Attributes, Import, Export, Changing,Tables, Exceptions, Sourcecode tabs.
Attribues: Nothing it will give info about your FM
Import: Here you have to give FM which parameters should receive
Export: Here Which Parameters should export (return)
Changin: it will receives and exports
Tables: Tables also receives and exports
Exceptions: Error handlig
Sourcecode: Here you have to implement the logic.
save and activate it. then you can call FM in any program.
Hope u will find this matter useful as i have described it in very simple words.
Do reward points
Regards:
Sapna
‎2007 Jun 20 8:52 AM
Hi,
Custom Function Modules are craeted only when there is a requirement of such type.
Most of the items SAP provided FM's serve our purpose but there are instances when there are no SAP provided FM's to serve our purpose.
So in these type of cases we need to create a custom FM.
You can create a custom FM in SE37.
You have to know what are the importing parameters on which the FM will work and what parameters it will return,also called EXPORTING parameters.
If there are messages to be issues when something goes wrong in the FM can be written in EXCEPTIONS.
There are also TABLES and CHANGING parameters which you have to fill if required.
Hope it was useful.
Thanks,
Sandeep.
‎2007 Jun 20 8:56 AM
Hi,
For Reusability purpose.
use SE37 for Creating Fucntion module, before creating function module assign it to the function group.
Creation of function group - menu(goto -function group - create function group)
Thanks,
Anitha