Skip to Content
author's profile photo Former Member
Former Member

subroutine & FM

Hi All,

Can anybody tell me about the main difference between subroutine and a function module???

Thanks in Advance!

Kiran

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 07, 2007 at 10:07 AM

    function modules are mainlu useful n case of global declaration. and function modules return values whee as subroutines doex not.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2007 at 10:06 AM

    <b>SUBROUTINE</b>

    PERFORM GET_DATA.

    select * FROM ..........

    ENDFORM.

    <b>FM</b>

    COMMIT_WORK

    GUI_DOWNLOAD

    GUI_UPLOAD

    FM can be used in different programs.

    Subroutine can be used only in a single program

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2007 at 10:08 AM

    Hi,

    Sunroutines and function modules does the same work..

    Subroutines are with in a program and Function modules are global across SAP..

    you can call FM in any program but Subroutine you can call with in a program..

    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.

    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.

    Subroutines are defined locally in the program and FMs are globally defined in SAP system.

    You cant upload data or remotely access data using Subroutines, its possible in FM

    rewads if useful,

    regards,

    nazeer

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 07, 2007 at 10:08 AM

    Subroutine can be used in the same program and it is not global.

    FM can be used by any number of programs and are global.

    You can create your own FMs too and use existing FMs which are defined for different puposes

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2007 at 10:08 AM

    Hi Kiran..

    Function Module:

    These are for Global modularizaiton. Name of a FM is unique within SAP.

    Can be independently tested

    Can be Remote enabled.

    Can have exceptions

    Subroutine:

    These are for Local modularizaiton. Name of a subroutine is unique within a PROGRAM.

    Cannot be independently tested

    Cannot be remote enabled

    Cannot have exceptions.

    <b>Reward if helpful</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2007 at 10:10 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2007 at 10:12 AM

    Hi,

    Subroutine <b>cannot have OPTIONAL</b> parameters.

    Subroutine is <b>not a seperate reposiotry</b> object.(<b>No TADIR entry</b> for routines)

    Subroutine <b>cannot be Remote</b> enabled.

    Subroutine <b>cannot have Exceptions</b>

    You can create as many subroutines as you want in a Function group but you can create only <b>99 Function modules.</b>

    Regards,

    Sesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 07, 2007 at 10:15 AM

    Hi,

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

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

    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.

    Regards,

    Priyanka.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 07, 2007 at 10:19 AM

    Hi kiran,

    Differences between subroutine and FM r as follows:

    <b>Function</b> : Stored in the central library and has a global presence.

    <b>Subroutine</b> : It is confined to a particular program.

    <b>Function</b> : It can return values.

    <b>Subroutine</b> : It cannot return values.

    <b>Function</b> : Can handle exceptions.

    <b>Subroutine</b> : Can't handle exceptions.

    <b>Function</b> : The way the parameters are passed will differ from that subroutine.

    Regards...

    Arun.

    Reward points if useful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 07, 2007 at 10:33 AM

    Compared to Subroutines, FMs have a well defined Interface and exception handling mechanism. All the global data within a Function group can be accessed by all the FMs in that group.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.