‎2005 Jul 16 5:47 PM
hi,
One of the main difference between Function module and the subroutine is that Function module can return values but subroutine cannot.I could not understand this point.
can anybody tell me how i can see the difference between fm and subroutine with an example?
Thanks in advance.
‎2005 Jul 16 10:18 PM
Hi
As mentioned, both forms and FMs are <i>reusable modularization units</i>. To distinguish we generally say that forms are used for <b>internal modularization</b> and FMs are used for <b>external modularization</b>.
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 <i>function groups</i> and function groups may have global variables that can be globally used by all FMs inside it.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>
‎2005 Jul 16 6:32 PM
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.
REPORT ztest.
DATA: count TYPE i VALUE 0.
DO 5 TIMES.
PERFORM add CHANGING count.
WRITE: /001 'The new value is:', count.
ENDDO.
FORM add CHANGING p_count.
ADD 1 TO p_count.
ENDFORM.
Rob
‎2005 Jul 16 7:35 PM
Both are for same purpose, modularisation and reuse.
If you want to use same set of code in the same program multiple times, then use subroutines.
If the same code is used in multiple programs, then create a function module.
Both can accept and return values. You can use USING, CHANGING and TABLE parameters in subroutine and IMPORT, EXPORT, TABLES and EXCEPTIONS in function module.
Vinod
‎2005 Jul 16 10:18 PM
Hi
As mentioned, both forms and FMs are <i>reusable modularization units</i>. To distinguish we generally say that forms are used for <b>internal modularization</b> and FMs are used for <b>external modularization</b>.
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 <i>function groups</i> and function groups may have global variables that can be globally used by all FMs inside it.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>