09-03-2007 7:58 AM
hi all,
i want to write one macro in my function module for selecting data from one table and give back to the function module.
how to code that and how to call in fm. i dont no anything about macro.
please help me.
thanks in advance.
vinod
09-03-2007 8:00 AM
Macro Add-Range Definition
define add-range.
&3-sign = &1.
&3-option = &2.
&3-low = &4.
&3-high = &5.
append &3.
end-of-definition.
Macro Implementation
add-range 'I' 'EQ' w_allc_n w_allc ' '.
<b><u>See the documentation below.</u></b>
DEFINE
Basic form
DEFINE macro.
Effect
Defines a section of source code (macro) that you can address using the name macro. Source code saved as a DEFINE macro may only consist of complete ABAP statements
All macro use is expanded fully in translation. Macros are a text substitute for the translation phase - not a modularization technique for runtime use.
You conclude a macro with the END-OF-DEFINITION statement.
When you define a macro, you can use placeholders (&n, where n = 1, 2, ..., 9). When the macro is expanded, &n is replaced with the n-th current parameter.
Example
Suppose you define a macro "INCREMENT", which you then use in your program.
DEFINE INCREMENT.
ADD 1 TO &1.
END-OF-DEFINITION.
DATA: NUMBER TYPE I VALUE 1.
...
INCREMENT NUMBER.
Notes
As a rule, you should use subroutines (FORM, FUNCTION) instead of macros. This is because subroutines - unlike macros - are supported by all of the ABAP Workbench tools (debugging, runtime analysis, runtime error handling, ...).
You cannot define a macro within a macro using the DEFINE statement.
You cannot use an ABAP keyword as a macro name.
The validity of a macro definition is determined by its position in the source code. You can use a given macro in any line of code following its definition. There is no distinction between global and local macros. For example, the fact that a macro is defined within a subroutine has no effect on its validity.
If you redefine a macro, that is, assign a new meaning to an existing name, the new meaning takes effect from the position in the program where the macro was redefined.
Regards
Pratyusha
Message was edited by:
Pratyu Usha
09-03-2007 8:01 AM
Hi,
Check this
define update_flg.
move &1 to &2-updkz.
modify &3 from &2 index &4.
end-of-definition. " Update_flg
update_flg c_x wa_ysccpvapitem i_ysccpvapitem v_tabix.
a®
09-03-2007 8:06 AM
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.
see this sample code
REPORT ZMACRO.
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.
*-- End of Program
regards,
srinivas
09-03-2007 8:10 AM
Hi,
See below code
<b>Macro in ABAP
*
Macro in ABAP
*
Submitted by : SAP Basis, ABAP Programming and Other IMG Stuff
*
REPORT ZMACRO.
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.
*-- End of Program</b>
reward if helpful.