01-31-2008 2:49 AM
Hi Friends
can u explain what is the use of macro? also i need a sample program for Macro.
Regards
Anbu
01-31-2008 3:02 AM
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.
Few Uses and advantages of Macro are
Instead of writing the same data declaration statement each time a new variable is declared, you can simply reuse the code via macros.
You can use macros to define variables. A simple example is:
DEFINE table
data: &1 like &2 occurs 0 with header line.
END-OF-DEFINITION.
table itab1 lfa1.
table itab2 pernr.
Instead of writing the same data declaration statement each time a new variable is declared, you can simply reuse the code via macros.
Complex WRITE statements
Programs often get unnecessarily verbose and difficult to understand because they contain lengthy and redundant WRITE statements. Macros allow you to maintain readability while writing complex WRITE statements. You can write macros to replace all variants supported by the WRITE statement. Here's a simple example:
DEFINE Write_stat
Write : &1 no-zero right-justified color &2.
END-OF-DEFINITION.
The example declares a macro write_stat. The macro printsafter truncating their zerosvariables in a right-aligned format in the color specified by number &2. Instead of writing similar WRITE statements repeatedly, you can simply call the macro and pass the desired output specifications as parameters, like this:
Write_stat var1 1.
Write_stat var2 2.
Reading/changing variable values
You can use macros to replace any set of repetitive statements that check or modify values of variables. Typical examples are simple IF checks or CLEAR statements. For simplicity's sake, I'm showing only how the body of such macros may look:
If not &1 is initial.
Endif.
clear: &1,
&2.
Formulas or calculations
You can use macros to define formulas for complex calculations. In this case, the placeholders may be operands (such as +, -), constant values, or local variables. Here's an example:
DEFINE operation.
result = ( &1 &2 &3 ) &4 ( &5 &6 &7 ).
END-OF-DEFINITION.
Operation 5 3 / var2 + 9.
Operation var1 + 7 * 6 + 5.
Working with heavy data
Many SAP programs use macros to export and import data to and from the database. Consumption of system resources is optimal if macros are employed, particularly when a large amount of data is involved:
DEFINE EXPORT_MACRO.
Export &1 &2 &3 to database indx(DB) id 'DATA'.
END-OF-DEFINITION.
EXPORT_MACRO itab1 itab2 itab3.
In this example, the data of three internal tables that may each consist of a large number of records is exported to the table INDX. Had we used form routines in this case, you can't imagine the resources (CPU time and memory) that would be consumed while passing tables as parameters.
Hope this Helps
VB
01-31-2008 3:01 AM
Hi anbulakshmi arul,
Macros:
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 <macro>.
<statements>
END-OF-DEFINITION.
Example:
DATA: RESULT TYPE I,
N1 TYPE I VALUE 5,
N2 TYPE I VALUE 6.
DEFINE OPERATION.
RESULT = &1 &2 &3.
OUTPUT &1 &2 &3 RESULT.
END-OF-DEFINITION.
DEFINE OUTPUT.
WRITE: / 'The result of &1 &2 &3 is', &4.
END-OF-DEFINITION.
OPERATION 4 + 3.
OPERATION 2 ** 7.
OPERATION N2 - N1.
See this link.
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db972835c111d1829f0000e829fbfe/frameset.htm
Plzz reward if it is useful,
Mahi.
01-31-2008 3:02 AM
Hi Lakshmi
Macro is also like a perform, but macro is local to the specific program..
check this code:
*Macro for assigning space rather than 0.00 for numeric fields
DEFINE concat_nonull.
your code in between "<< what ever u wanted that code to do
END-OF-DEFINITION.
"calling the macro here:
concat_nonull lf_line lf_buf lf_line c_tab <fs_comp>.
concat_nonull is the name of the macro
01-31-2008 3:02 AM
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.
Few Uses and advantages of Macro are
Instead of writing the same data declaration statement each time a new variable is declared, you can simply reuse the code via macros.
You can use macros to define variables. A simple example is:
DEFINE table
data: &1 like &2 occurs 0 with header line.
END-OF-DEFINITION.
table itab1 lfa1.
table itab2 pernr.
Instead of writing the same data declaration statement each time a new variable is declared, you can simply reuse the code via macros.
Complex WRITE statements
Programs often get unnecessarily verbose and difficult to understand because they contain lengthy and redundant WRITE statements. Macros allow you to maintain readability while writing complex WRITE statements. You can write macros to replace all variants supported by the WRITE statement. Here's a simple example:
DEFINE Write_stat
Write : &1 no-zero right-justified color &2.
END-OF-DEFINITION.
The example declares a macro write_stat. The macro printsafter truncating their zerosvariables in a right-aligned format in the color specified by number &2. Instead of writing similar WRITE statements repeatedly, you can simply call the macro and pass the desired output specifications as parameters, like this:
Write_stat var1 1.
Write_stat var2 2.
Reading/changing variable values
You can use macros to replace any set of repetitive statements that check or modify values of variables. Typical examples are simple IF checks or CLEAR statements. For simplicity's sake, I'm showing only how the body of such macros may look:
If not &1 is initial.
Endif.
clear: &1,
&2.
Formulas or calculations
You can use macros to define formulas for complex calculations. In this case, the placeholders may be operands (such as +, -), constant values, or local variables. Here's an example:
DEFINE operation.
result = ( &1 &2 &3 ) &4 ( &5 &6 &7 ).
END-OF-DEFINITION.
Operation 5 3 / var2 + 9.
Operation var1 + 7 * 6 + 5.
Working with heavy data
Many SAP programs use macros to export and import data to and from the database. Consumption of system resources is optimal if macros are employed, particularly when a large amount of data is involved:
DEFINE EXPORT_MACRO.
Export &1 &2 &3 to database indx(DB) id 'DATA'.
END-OF-DEFINITION.
EXPORT_MACRO itab1 itab2 itab3.
In this example, the data of three internal tables that may each consist of a large number of records is exported to the table INDX. Had we used form routines in this case, you can't imagine the resources (CPU time and memory) that would be consumed while passing tables as parameters.
Hope this Helps
VB