2007 Dec 28 3:29 AM
Hi friends,
please tell me the steps to write a function module.
HOw it works.Please provide a example.
Thanks,
cheta.
2007 Dec 28 3:35 AM
HI,
The Steps to create FM is
1.Goto SE37.
2.First Create A Function Group
Goto--> Function Group --> Create Group
2.after that create FM there provide the Function Group which u created and short text.
3. After that as per u r requirements enter IMPORT EXPORT SOURCE CODE etc details.
Note : in one function group we can store upto 99 Function Modules ..
THX
2007 Dec 28 3:37 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.
Plz follow these steps:::
for creating the function modile initiallly we need to create the function group in se37 tcode.
1.later create the function module:
2. let us take some example
in import -
> im_kunnr type kunnr.
3. export:::
Ex_kna1 Type kna1.
4. Source code: tab
if not Im_kunnr is initial.
select single * into ex_kna1
from kna1
where kunnr eq im_kunnr.
5.save
6. goto se80 and activate all the function module as a set.
now u can use it in se38 z programs.
hope u understood the logic to use try this..
Regards,
Sana.
reward points if found helpful..
2007 Dec 28 4:06 AM
Hi Sultana,
I am still unable to follow MPORt,EXPORT,TABLES,CHANGING.
please explain the functionality of the code once so that I can understand better.
Great explanation tech.....GR8 MAM
Thanks,
cheta.
2007 Dec 28 3:38 AM
Hi,
goto se37 tcode
inthat menu bar we have goto menu is there in that we have option of create function group.
give the function group name and activate it.
then it open the function module name.
in function module we have a Tabs as ATTRIBUTES,
IMPORt,EXPORT,TABLES,CHANGING,SOURCECODE,
ATTRIBUTES tab we select the normal function module.
then give the import values in IMPORT TAB. and internal tables aTABLES TAB.
whatever the code do u want to write in Source code.
after that activate it.
it will create function module.
please reward points,
regards,
satish.
2007 Dec 28 4:24 AM
Creation:
You create a RFC function module just as you create a normal function module.
After you create the function module, in the general tab of the function module select the "Remote Enabled" radio button which makes the function module as RFC function module.
Also the parameters should be Pass by value so select the "Pass value" check box against each of the parameters.
Last but not the least. RFC function modules cannot have exceptions, so define a return structure and pass all your messages like success, error etc. in the return structure.
After the function module is created, the RFC function moule can be called using the statement
CALL FUNCTION <FN Name> DESTINATION <RFC Dest>.
where RFC Dest it the remote destination created in SM59.
RFC (Remote Function Call) is similar to the general SAP fun module: except that in the attributes you click the radio button: RFC enabled;
and you will be passing an Import parameter DESTINATION to it.
Other code and usage will be similar to any fun module;
Have a look at any fun module in SE37 to understand better about the different components of Fun modules;
Refer this link:
http://help.sap.com/saphelp_nw04/helpdata/en/22/042518488911d189490000e829fbbd/frameset.htm
A Normal Function Module cant be called from external system. but a RFC(Remote Function) can be.
e.g. If I have a Lotus Notes sysytem interacting with my SAP system. Now, to access trhe data from SAP, Lotus Notes system has to call some functions in SAP. RFC is designed for that purpose only that an extrenal system can access SAP system.
2007 Dec 28 5:06 AM
Hi cheta,
to create a Function module u need to create a function group so first create a function group using se80
after creating the function goup in se80 create a function module in se37 give the name of the functin group given in se80 and a function module is created
Reward if useful
thanks,
swaroop