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

Difference

Former Member
0 Likes
760

Explain difference between macro and subroutine

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
736

HII

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 . 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.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 28, 2008 4:51 PM

5 REPLIES 5
Read only

Former Member
0 Likes
736

Hi Jiccs,

Macros can only be used in the program the are defined in and only after the definition.

Macros can take max 9 parameters.

Macros are expanded at compilation / generation.

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).

Macros Cannot be Debugged.

Subroutines (FORM) can be called from both the program the are defined in and other programs ('perform

' of 'perform in program ').

Subroutines can take any amount of parameters.

Subroutines are 'expanded' at runtime.

A FUNCTION is (more or less) a subroutine that is called external.

Subroutines Can be Debugged.

Regards,

Sunil

Read only

Former Member
0 Likes
737

HII

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 . 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.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 28, 2008 4:51 PM

Read only

Former Member
0 Likes
736

Subroutine is a block of code you would execute with a PERFORM.

A Macro is a section of code that is normally redundent and you can save your self some work by using it to implement the code with different parameters.

Macro Example


*_________________________________________________ Macros
DEFINE filefrom.
* &1 file   field name
* &2 screen field name
* &3 radio group name
* &4 modif id name
* text-305 = From
* text-306 = File
* text-307 = Screen
  selection-screen begin of line.
  selection-screen comment 1(10)  text-305 modif id &4.
  selection-screen comment 14(05) text-306 modif id &4.
  selection-screen position 20.
  parameters: &1 radiobutton group &3 default 'X' modif id &4.
  selection-screen comment 24(06)  text-307 modif id &4.
  selection-screen position 31.
  parameters: &2 radiobutton group &3 modif id &4.
  selection-screen end   of line.
END-OF-DEFINITION.
*
*
*
*
*  And the use of it.
*
*
SELECTION-SCREEN: BEGIN OF BLOCK blk3 WITH FRAME TITLE text-003.

filefrom p_cmtf p_cmts grp3 new.           " <== Macro being used will generate the above code using the 4 parameter passed

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10)  text-361 MODIF ID new.
SELECTION-SCREEN POSITION 12.
PARAMETERS: p_comm(132)      TYPE c LOWER CASE MODIF ID new.
SELECTION-SCREEN END   OF LINE.

SELECTION-SCREEN: END OF BLOCK blk3.
*
*
*

Read only

Former Member
0 Likes
736

hi,

Macros can only be used in the program the are defined in and only after the definition are expanded at compilation / generation. A macro is more or less an abbreviation for some lines of code that are used more than once or twice. Since debugging a MACRO is not really possible, prevent the use of them.

Subroutines can be called from both the program the are defined in and other programs . A FORM is a local subroutine (which can be called external). A FUNCTION is (more or less) a subroutine that is called external. If the subroutine is used only local (called internal) use a FORM to call it. If the subroutine is called externally use a Function to call it.

regards,

madhu

Read only

Former Member
0 Likes
736

Macros do NOT evaluate the values passed during run-time. This creates the effect of abbreviating code. It is as if the compiler writes the code over and over again. This is the reason why you cant debug macros.

Subroutines evaluate their values during run-time. Memory is alloted.