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

Help me in Creating Function Module

Former Member
0 Likes
654

Hi All,

I am new to SAP, please help me doing the following task given to me.

Given EE group and EE subgroup, how to write a custom function module that displays all the employees in it?

The output should be displayed in 2 tables where first table has the infotypes 0001 and 0002 and second table has infotype 0006.

Thank you

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
524

hi,

1.Goto transaction SE37. On the menu bar, click on GOTO Function Group  Create Group. Create a function group of your choice. Skip this step if you want to assign the function module to an existing function group.

2.Give the name of the new function group you want to create (must begin with z), and a meaningful short text.

3.Save the function group assigning a development class

.4Enter the name of the function module you wish to create. Click on CREATE

5.Enter the name of the Function group with which you wish to associate the function module. Click on SAVE

6.The function module has been saved. Enter the interface parameters in IMPORT, EXPORT, USING and CHANGING tabs. The function module has to be activated before using it in any program.

7.While activating, care needs to be taken that the REPS elements of the function group are selected for activation, alongwith the function module. This step is to be done when creating a new function group and attaching a new function module to it. If you have attached your function module to an existing function group, you may activate the unction module only.

8.Now that the function module is activated, you can write the code between FUNCTION and ENDFUNCTION .

reward if its useful

3 REPLIES 3
Read only

Former Member
0 Likes
524

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

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..

To be reward all helpfull naswers.

Jay

Read only

Former Member
0 Likes
525

hi,

1.Goto transaction SE37. On the menu bar, click on GOTO Function Group  Create Group. Create a function group of your choice. Skip this step if you want to assign the function module to an existing function group.

2.Give the name of the new function group you want to create (must begin with z), and a meaningful short text.

3.Save the function group assigning a development class

.4Enter the name of the function module you wish to create. Click on CREATE

5.Enter the name of the Function group with which you wish to associate the function module. Click on SAVE

6.The function module has been saved. Enter the interface parameters in IMPORT, EXPORT, USING and CHANGING tabs. The function module has to be activated before using it in any program.

7.While activating, care needs to be taken that the REPS elements of the function group are selected for activation, alongwith the function module. This step is to be done when creating a new function group and attaching a new function module to it. If you have attached your function module to an existing function group, you may activate the unction module only.

8.Now that the function module is activated, you can write the code between FUNCTION and ENDFUNCTION .

reward if its useful

Read only

Former Member
0 Likes
524

Thanks for the information. That was helpful

Now, I have created the function module but how do I send the details of infotype 0001, infotype 0002 into one table and details of infotype 0006 into another table.