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

Function module

Former Member
0 Likes
727

Hi ,

I am trying to write a sub-routine inside a function module. But it is giving errors saying a particular variable is not declared etc. Is not possible to write a sub routine inside a fm?

Vishnu.

9 REPLIES 9
Read only

naimesh_patel
Active Contributor
0 Likes
712

It is possible but you have to use the variables in the parameters of the routine.

LIKE:

PERFORM GET_DATA TABLES ITAB USING P_WERKS P_NAME.

FORM GET_DATA TABLES I_ITAB STRCUTRE MARC
USING I_WERKS TYPE WERKS_D
I_NAME TYPE SY-USNAME.

* USE I_ITAB, I_WERKS AND I_NAME inside the form

ENDFORM.

Regards,

Naimesh Patel

Read only

0 Likes
712

Hi Naimesh ,

I went to SE80 and I have declared all the variables declaration in the Top include.But when I am trying to write a sub-routine in the FM, it is giving the error

that the particular form doesnt exist.Please resolve my problem.

Vishnu.

Read only

Former Member
0 Likes
712

Hi Vishwanath,

you can create subroutines in a FM in the same way as you do in a report program. Only difference if that you have to create the form routines after the endfunction.

Also the variables declared in the FM will not be accesible in these routines as the variables you declare in the FM are local to that include.

In case you need Global variables create a top Include in the Function Group.

Lokesh

Read only

0 Likes
712

Hi Lokesh,

If we create a Top include and if we declare all the variables there, then is it possible to create sub-routines with these variables as we do normally in reports?

If so how to create a top include and how to declare vars in that.

Vishnu.

Read only

0 Likes
712

yes vishwanath you can declare global variables in Top Include and then use them in a similar way as in report.

Top Include is automatically created when you create a Function group.

goto se80 and display the function group, you will be able to see the top include, include ending with TOP.

Declare all global variables in there.

Lokesh

Pls. reward if it helps.

Read only

0 Likes
712

Yes I did Lokesh.I declared the global vars in the Top include in SE80.But still when I write a sub-routine say " perform sample ". Once I create that in a new include or Top include it is givinng the error " Form sample" doesnt exist. Please help me out.

:

Read only

0 Likes
712

You need to activate all the includes along with the FM and its main program

Regards,

Naimesh Patel

Read only

0 Likes
712

Hi Vishwanath,

May be your issue would have been resolved by now. If not,

Goto Se80, right click on the Function Group and Activate.

It should work, if still it does not help:

Right click on the FG -> More Functions -> Rebuild Object List.

Hope it works.

Lokesh

Read only

Former Member
0 Likes
712

When you write the perform statement and double click on it, it will show the include names one is top include for the declarations and the other is to give the subroutines. You can not place the subroutine on the function module.

Thanks,

Srinivas