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

Diff Subroutine & FM

Former Member
0 Likes
1,750

Hi!

1) Can any one tell the main diff btween subroutine and FM.

and

What is the use end-of-selction event apart from triggering at the end of program.

& where it has used?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,720

Hi

Returning values means for a subroutine or a function module u will exporting some values and based on that values the subroutine or fm will perform some logic, based on that logic the values which u have send may change so they will be returned to ur program.

for ex: to a function module u have exported a and b values and importing c in the function module

c = a + b. So here it will return the sum of a and b through c.

That is what is called as returning the values.

Hope u got the point.

Regards

Haritha.

15 REPLIES 15
Read only

Former Member
0 Likes
1,720

Hello,

In contrast to normal subroutines function modules have uniquely defined interface. Declaring data as common parts is not possible for function modules. Function modules are stored in a central library.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2d74358411d1829f0000e829fbfe/content.htm

Regards

Vasanth

Read only

Former Member
0 Likes
1,720

Hi,

In External subroutine perform statement is in one program and form routine is in another program.It is used for Reusability purpose.

External Subroutines are better for documentational purposes. You can have all the subroutines related to the program into single include program.

Another difference is that they are compiled with the program so they share the same memory, so there's no context change while calling a subroutine. It does save system time.

Also, you can access all the global variables of the program in External subroutine but you can not access them in Function module unless they are passed as a parameter.

Which one to use depends on the case you are dealing with.

For example, if you are developing functionality to convert ouptut in PDF format then it is better to create a function module so that all the programs across all packages can use that functionality.

if you are developing functionality which will be used by a defined set of programs(which are handling same kind of data) then it's better to use External subroutines, where you can defined common data in External subroutines program.

<b>END-OF-SELECTION:</b>

In report programs using LDB for every value selected the program issues the output, to control this you would use END-OF-SELECTION. Now if you call your output in this event, the output is made only after all the values are selected as per the selection criteria.

but i will give u a nice example where u need end-of-selection.

suppose while coding, u need a logic like below

if a condition is satisfied continue with the report

and if not satisfied, then display a message and end the report.

then u can code like below.

start-of-slection.

if a = <condition>.

do the following.......

else.

stop.

end-of-selection.

write: 'THIS IS END'.

Note: Stop command triggers end-of-slection from anywhere.

Regards,

Padmam.

Read only

0 Likes
1,720

Hi!

Whats mean by returning values does subroutine & FM return vales whats mean bt that.

Read only

Former Member
0 Likes
1,720

Hi,

1. Well, they can both return values. FMs are mainly used when a routine is to be performed by many programs. Subroutines (forms) are generally only executed within one program. You can perform routines from other programs, but it's not often done.

2. End of Selction event is generaly used to divide the business logic while coding your report. Like INITIALISATION, START-OF-SELECTION, END-OF-SLECTION. in the inititailisation, you will do all the intialisation things like setting the dafult values, in the stat-of-selction, you will write the business logic part like you will fetch the date from the dictionary and in the End-of-selection you will wirte the logic for display part this will have write statements and logic related to ouput display.

Thanks,

Anitha

Read only

0 Likes
1,720

Hi Anitha!

Whats mean by returning values.

Read only

former_member404244
Active Contributor
0 Likes
1,720

Hi,

plz go throgh the below link.

Reagrds,

nagaraj

Read only

Former Member
0 Likes
1,720

Hi,

FM are global while subroutines are local.

you can test a FM but you can not test a subroutine.

regards,

Ruchika

Read only

0 Likes
1,720

Hi,

end of selction is used for final data display.

In ALV report data is dieplayed in this event.

regrads,

Ruchika

Read only

Former Member
0 Likes
1,720

Hi,

As mentioned, both forms and FMs are reusable modularization units. To distinguish we generally say that forms are used for internal modularization and FMs are used for external modularization.

To decide on which to implement, consider whether you need the content to be used just for a limited program or wheteher it can be called from many independent programs. For the first purpose it is better to implement a form whereas for the second we implement an FM.

However, ABAP does not isolate the usage context. That is; you can call a form from another program within whose code the form is not actually implemented. However, this requires attention since the form may utilize global variables.

The same issue holds for FMs. FMs are encapsulated in function groups and function groups may have global variables that can be globally used by all FMs inside it.

Regards

Read only

Former Member
0 Likes
1,720

hi rahul,

Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program. Function groups act as containers for function modules that logically belong together,Function modules allow you to encapsulate and reuse global functions in the R/3 System. They are stored in a central library,Unlike subroutines, you do not define function modules in the source code of your program.

Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module

End-of-selection is used mostly while using ldb's. It is used to display the output.

Regards...

Arun.

Reward points if useful.

Read only

Former Member
0 Likes
1,720

hi,

FM : are placed in data dictionary for global access.

Fm can return a value to any program.

a Fm can be executed to check whether it working properly used or not.

Fm can be made as a remote-enabled Fm n can be used for bapi's n in idocs........

subroutines: they are locally used.

doesnt have any treturn parameters.

cant be executed by itself.

used mainly for modularization purpose and to reduce the size of report prgm.

end-of-selection mainly useful for displaying data n for triggering end of prgm.

if helpful reward some points.

with regards,

suresh.

Read only

Former Member
0 Likes
1,720

Hello Rahul...

<b>Sub routine</b> is <b>local</b> with in the program... Ofcourse there are ways to access subroutines from other programs...

<b>Function Modules</b> are <b>global</b> throughout the system... And one more advantage is we can make function module remote enable to access data from ohter clients/systems.

<b>REWARD POINTS IF HELPFUL</b>

Regards

--

Sasidhar Reddy Matli

Message was edited by:

Sasidhar Reddy Matli

Read only

0 Likes
1,720

whats mean by returning values

Read only

Former Member
0 Likes
1,721

Hi

Returning values means for a subroutine or a function module u will exporting some values and based on that values the subroutine or fm will perform some logic, based on that logic the values which u have send may change so they will be returned to ur program.

for ex: to a function module u have exported a and b values and importing c in the function module

c = a + b. So here it will return the sum of a and b through c.

That is what is called as returning the values.

Hope u got the point.

Regards

Haritha.

Read only

0 Likes
1,720

Hi Haritha!

Thanks, i understood so both ill ruturn values i am right

Thank you.