‎2007 Nov 28 4:54 PM
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.
‎2007 Nov 28 4:56 PM
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
‎2007 Nov 28 6:15 PM
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.
‎2007 Nov 28 5:01 PM
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
‎2007 Nov 28 6:05 PM
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.
‎2007 Nov 28 6:24 PM
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.
‎2007 Nov 28 6:39 PM
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.
:
‎2007 Nov 28 7:30 PM
You need to activate all the includes along with the FM and its main program
Regards,
Naimesh Patel
‎2007 Nov 29 10:56 AM
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
‎2007 Nov 28 5:02 PM
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