<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Difference between Macros and subroutine in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349021#M518414</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shriram , &lt;/P&gt;&lt;P&gt; Here are few diffreneces between macro , subroutines and FM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Macro and Subroutine are local ,i.e. they are visible only in the program they are declared in and so can be used only in them , where FM is global and can be used by any program&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. When you call a subroutine or FM the control passes to that section of the code , but in case of macros during compilation the macro call is replaced with the code and hence no transfer of control takes place hence macros are better when it comes to performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Arun&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Jun 2007 11:13:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-06-08T11:13:10Z</dc:date>
    <item>
      <title>Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349019#M518412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the difference between the macros subroutine and function module functinalitywise.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2007 11:07:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349019#M518412</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-08T11:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349020#M518413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the notes of differences bet. FM and Subroutines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Function modules are for modularization urpose. You can the Function Module in any program. That is available all over in the SAP system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where as subroutine is program specific. Once you create a subroutine in one program then you can use that in that program and related programs like includes in the program or you have to call the subroutine specifically using the main program name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally subroutines are for program modularization. Not for generic use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FM's are for generic use. Not program dependent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FMs are mainly used when a routine is to be performed by many programs. &lt;/P&gt;&lt;P&gt;Subroutines (forms) are generally only executed within one program.&lt;/P&gt;&lt;P&gt;You can perform routines from other programs, but it's not often done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;both forms and FMs are reusable modularization units. &lt;/P&gt;&lt;P&gt;To distinguish we generally say that forms are used for internal modularization and &lt;/P&gt;&lt;P&gt;FMs are used for external modularization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To decide on which to implement, consider whether you need the content to be used just for a limited program&lt;/P&gt;&lt;P&gt;or wheteher it can be called from many independent programs. &lt;/P&gt;&lt;P&gt;For the first purpose it is better to implement a form whereas for the second we implement an FM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, ABAP does not isolate the usage context. &lt;/P&gt;&lt;P&gt;That is; you can call a form from another program within whose code the form is not actually implemented.&lt;/P&gt;&lt;P&gt;However, this requires attention since the form may utilize global variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The same issue holds for FMs.&lt;/P&gt;&lt;P&gt;FMs are encapsulated in function groups and function groups may have global variables that can be globally &lt;/P&gt;&lt;P&gt;used by all FMs inside it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Vasanth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2007 11:09:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349020#M518413</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-08T11:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349021#M518414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shriram , &lt;/P&gt;&lt;P&gt; Here are few diffreneces between macro , subroutines and FM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Macro and Subroutine are local ,i.e. they are visible only in the program they are declared in and so can be used only in them , where FM is global and can be used by any program&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. When you call a subroutine or FM the control passes to that section of the code , but in case of macros during compilation the macro call is replaced with the code and hence no transfer of control takes place hence macros are better when it comes to performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Arun&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2007 11:13:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349021#M518414</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-08T11:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349022#M518415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Macros can only be used in the program the are defined in and only after the definition.&lt;/P&gt;&lt;P&gt;Macros can take max 9 parameters.&lt;/P&gt;&lt;P&gt;Macros are expanded at compilation / generation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subroutines (FORM) can be called from both the program the are defined in and other programs ('perform&lt;/P&gt;&lt;P&gt;' of 'perform in program ').&lt;/P&gt;&lt;P&gt;Subroutines can take any amount of parameters.&lt;/P&gt;&lt;P&gt;Subroutines are 'expanded' at runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Functions are just like FORMs, but are intended to be called external.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some differences between FUNCTIONs and FORMs:&lt;/P&gt;&lt;P&gt;The name of a FORM must be unique within the program (two programs can have different FORMs with the same name). A FORM is intended to be called internal (from within the program, however by a 'trick' you can call them external).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The name of a FUNCTION has to be unique throughout the system. A FUNCTION is intended to be called external (and is thus shared by 'many' programs).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The latter is more important for programmers and maintenance. Since a FUNCTION is called external, it is important to keep the interface (parameters) the same. The interface of a FORM (which is intended to be called internal) is check when debugging a program (but it is only checked within the program that is debugged). So if the interface of a FORM is changed, but the call to the FORM (perform ) is not, the debugger will notice this and issue an error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general:&lt;/P&gt;&lt;P&gt;A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice.&lt;/P&gt;&lt;P&gt;A FORM is a local subroutine (which can be called external).&lt;/P&gt;&lt;P&gt;A FUNCTION is (more or less) a subroutine that is called external.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since debugging a MACRO is not really possible, prevent the use of them (I've never used them, but seen them in action). If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Excerpt from &lt;A href="http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594#" target="test_blank"&gt;http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594#&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA p_c(10).&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &amp;lt;fs&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;DATA p_old1 TYPE i VALUE 10.&lt;/P&gt;&lt;P&gt;DATA p_old2 TYPE i VALUE 11.&lt;/P&gt;&lt;P&gt;DATA p_old3 TYPE i VALUE 12.&lt;/P&gt;&lt;P&gt;DATA p_old4 TYPE i VALUE 13.&lt;/P&gt;&lt;P&gt;DATA p_old5 TYPE i VALUE 14.&lt;/P&gt;&lt;P&gt;DATA p_old6 TYPE i VALUE 15.&lt;/P&gt;&lt;P&gt;DATA p_old7 TYPE i VALUE 16.&lt;/P&gt;&lt;P&gt;DATA p_old8 TYPE i VALUE 17.&lt;/P&gt;&lt;P&gt;DATA p_old9 TYPE i VALUE 18.&lt;/P&gt;&lt;P&gt;DATA p_old10 TYPE i VALUE 19.&lt;/P&gt;&lt;P&gt;DATA p_old11 TYPE i VALUE 21.&lt;/P&gt;&lt;P&gt;DATA p_old12 TYPE i VALUE 22.&lt;/P&gt;&lt;P&gt;DATA p_old13 TYPE i VALUE 23.&lt;/P&gt;&lt;P&gt;DATA p_old14 TYPE i VALUE 24.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEFINE ADD_MAPPING.&lt;/P&gt;&lt;P&gt;p_c = &amp;amp;1.&lt;/P&gt;&lt;P&gt;CONDENSE p_c.&lt;/P&gt;&lt;P&gt;CONCATENATE 'p_old' p_c INTO p_c.&lt;/P&gt;&lt;P&gt;ASSIGN (p_c) TO &amp;lt;fs&amp;gt;.&lt;/P&gt;&lt;P&gt;WRITE &amp;lt;fs&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;DO 14 TIMES.&lt;/P&gt;&lt;P&gt;ADD_MAPPING sy-index.&lt;/P&gt;&lt;P&gt;ENDDO. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594" target="test_blank"&gt;http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/frameset.htm" target="test_blank"&gt;http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/frameset.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Priyanka.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2007 11:21:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349022#M518415</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-08T11:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349023#M518416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;       MACROS =&amp;gt;&lt;/P&gt;&lt;P&gt;Getting a feel of macros&lt;/P&gt;&lt;P&gt;The basic syntax of macros is as follows:&lt;/P&gt;&lt;P&gt;DEFINE macro_name. "Macro Definition&lt;/P&gt;&lt;P&gt;&amp;#133;&amp;#133;&amp;#133;&amp;#133;&amp;#133;. Statements&lt;/P&gt;&lt;P&gt;&amp;#133;&amp;#133;&amp;#133;&amp;#133;&amp;#133;. Statements&lt;/P&gt;&lt;P&gt;&amp;#133;&amp;#133;&amp;#133;&amp;#133;&amp;#133;&amp;#133;&amp;#133;&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION. "Macro Definition&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;macro_name par1 par2 &amp;#133;par9. "Macro call -parameters separated by spaces&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within the DEFINE... and END-OF-DEFINITION lies the body of the macro&amp;#151;the statements that you wish to be executed each time the macro is called. These statements may be any valid ABAP statements, such as WRITE, CLEAR, FORM calls, or database statements such as SELECT or UPDATE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To familiarize yourself with the working of macros, it's necessary to take a close look at exactly what happens when an ABAP program containing a macro call is generated. Consider Listing A.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All ABAP programs must be generated before they can be executed. At the time of program generation, the system supplants each macro call, as shown in Listing A, with the statement(s) placed between the macro definition. Furthermore, the parameters passed at the time of macro calling are copied in place of the any placeholders (numbered &amp;amp;1, &amp;amp;2 &amp;#133;&amp;amp;9) found in the body of the macro definition. The system simply ignores the presence of the macros during the execution of the program&amp;#151;that is, all statements are executed as a single block of code:&lt;/P&gt;&lt;P&gt;write : int1.&lt;/P&gt;&lt;P&gt;write : int2.&lt;/P&gt;&lt;P&gt;write : int3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other than readability and meaningfulness, macros also offer performance advantages. For testing purposes, I wrote a macro that incremented the value of a variable by 1 and called the macro N times via a DO loop, as shown here:&lt;/P&gt;&lt;P&gt;DEFINE INCREMENT.&lt;/P&gt;&lt;P&gt;ADD 1 TO &amp;amp;1.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DO N TIMES.&lt;/P&gt;&lt;P&gt;INCREMENT VAR1.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SUBROUTINES=&amp;gt;&lt;/P&gt;&lt;P&gt;Subroutines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You call subroutines from ABAP programs using the PERFORM statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subroutines are introduced with the FORM statement and concluded with the ENDFORM statement.&lt;/P&gt;&lt;P&gt;You can define subroutines in any ABAP program. You can either call a subroutine that is part of the same program or an external subroutine, that is, one that belongs to a different program. If you call an internal subroutine, you can use global data to pass values between the main program and the subroutine. When you call an external subroutine, you must pass actual parameters from the main program to formal parameters in the subroutine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function Modules are Global ABAP programs created by SAP for reusable purpose. They have IMPORT, EXPORT and TABLE parameters, and EXCEPTIONS to through when error occurs.&lt;/P&gt;&lt;P&gt;You can create them from TCode SE37.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this resolves your query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2007 12:15:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349023#M518416</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-08T12:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349024#M518417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main differences are :&lt;/P&gt;&lt;P&gt;When the program is generated, all the body of the macro is copied at the place of the call. The parameters with '&amp;amp;' are replaced with the data of the call.So at the execution, the program doesn't see lines of call macro but just the body of the maro.&lt;/P&gt;&lt;P&gt;With a macro : no jump, no transfering of parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With a subroutine, when the program run, parameters are transfering in memory, index of program are changing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro are faster but the programme in memory is longer.&lt;/P&gt;&lt;P&gt;The subroutine are reusable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally we use macro to read the code of a program more easely.&lt;/P&gt;&lt;P&gt;We use rarely the macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bertrand.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2007 09:51:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349024#M518417</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-11T09:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Macros and subroutine</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349025#M518418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;- Macros can only be used in the program the are defined in and only after the definition are expanded at compilation / generation. Subroutines (FORM) can be called from both the program the are defined in and other programs . A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice. A FORM is a local subroutine (which can be called external). A FUNCTION is (more or less) a subroutine that is called external. Since debugging a MACRO is not really possible, prevent the use of them (I&amp;#146;ve never used them, but seen them in action). If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION.&lt;/P&gt;&lt;P&gt;Rewards points if help full&lt;/P&gt;&lt;P&gt;Regars&lt;/P&gt;&lt;P&gt;Suresh.D&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jun 2007 11:21:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-macros-and-subroutine/m-p/2349025#M518418</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-11T11:21:16Z</dc:date>
    </item>
  </channel>
</rss>

