WE'VE FOUND SAPhelpdesk!!!

***** Read the Reviews / Rate the Solution
We're not quite there yet.But we're getting there!-and we really want you to know when we're ready.
We can send the latest updates to ur email.Just subscribe to the email updates below and confirm the confirmation link in your email

Here's how to stay updated:

Enter ur email:

What is the difference between macro and subroutine


difference between macro and subroutine


Macros can only be used in the program they are defined in and only after the definition are expanded at compilation /generation. If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
The following statement block defines a macro macro:
DEFINE makro.
   statements
END-OF-DEFINITION.
You must specify complete statements between DEFINE and END‑OF‑DEFINITION. These statements can contain up to nine placeholders &1&2,...., &9). You must define the macro before the point in the program at which you want to use it.
Macros do not belong to the definition part of the program. This means that the DEFINE statement block is not interpreted before the processing blocks in the program. At the same time, however, macros are not operational statements that are executed within a processing block at runtime. When the program is generated, macro definitions are not taken into account at the point at which they are defined. For this reason, they do not appear in the overview of the structure of processing logic.
A macro definition inserts a form of shortcut at any point in a program and can be used at any subsequent point in the program. As the programmer, you must ensure that the macro definition occurs in the program before the macro itself is used. Particular care is required if you use both macros and include programs, since not all include programs are included in the syntax check (exception: TOP include).
To use a macro, use the following form:
makro [p1 p2... p9].
When the program is generated, the system replaces the macro by the appropriate statements and the placeholders &1&2, …, &9 by the parameter p1p2, …, p9. You can use macros within macros. However, a macro cannot call itself.


Defining Subroutines

A subroutine is a block of code introduced by FORM and concluded by ENDFORM.
FORM <subr> [USING   ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]
            [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ].
 ...
ENDFORM.
<subr> is the name of the subroutine. The optional additions USING and CHANGING define the parameter interface. Like any other processing block, subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program, especially for executable programs (type 1). In this way, you eliminate the risk of accidentally ending an event block in the wrong place by inserting a FORM...ENDFORM block.


(FORM) can be called from both the program they 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’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.

Confused? Feel free to ask

saphelpdesk.co.inYour feedback is always appreciated.I will try to reply Ur queries as soon as time allows.
Regards,
SAPhelpdesk

0 comments:

Post a Comment

Your Ad Here
Write 4 Us ( Support me ) !!!