Macros in axapta

In Axapta’s predecessor, macros were widely used. The predecessor did not support
classes, so macros were used instead. This might be the reason that macros are a part of
MorphX today. In MorphX macros are not commonly used. A few places make use of
macros such as keeping track of the list of fields stored when using dialogs. It is
recommended only to use macros to define constants. Macros are not supposed to be
used for code, as reusing code from macros is not flexible as using methods.
Macros can be created under the Macro node in the AOT, as a local macro in a method
or a single line defining a constant. The main difference between a macro and a method
is that a macro has no variable declaration part, and the code in a macro is not validated
for errors before executed from a method. This is one of the main reasons not to put
code in macros, as it makes the code more difficult to read.

When using macros in your code, the macros must be declared after the variable
declaration. The common place to put the definition is in the ClassDeclaration of a
class, form or a report. This will make the macro definition available for all parts of the
Macro commands
For writing macros a set of simple macro commands are used. You have commands for
setting the start and the end of a macro like in a method. An if-statement can be set to
control the flow of a macro. Macro if statements are used to validate whether a
parameter is specified for a macro or not. For a list of the macro commands.

Used to define a constant.
See macro HRMConstants.


Ends a #if.empty or a #if.notempty statement.

No difference whether declaring the start of a macro with #localmacro or

#globalmacro. #globalmacro is not used in the standard package, consider using
#localmacro instead.

Will return true if the macro has not been called with the parameter validated in the
%3 = %2;

Will return true if the macro has been called with the parameter validated in the
See macro InventDimJoin.
print %3;

Returns the current line number of the macro. Can be used while debugging, but not
of must use.

Specify the start of a local macro. See classDeclaration for class
print %1;

Used to load an AOT macro from code. See class method

Source Steen Andreasen’s book

An introduction to Axapta X++
and the MorphX Development Suite

  1. No comments yet.

  1. No trackbacks yet.