Macro :
- Macros are reusable components
- Macros are mostly used to remove hardcoding and for constant values
- Macros are pre-compiled/FASTER
- In AX, we have a macro processor
- Macros cannot be debugged
- Macros reduces line of code/optimizes the lines of code
- Macros will not end with semicolon
1) Local Macro
2) AOT Macro [Global macro - we can call it in all objects, tables, forms, jobs, reports etc]
3) Macro library
3) Macro library
1) Local Macro :
Local macro is a mcaro which is local to that function and cannot be used outside the method/function
static void TDS_LocalMacro(Args _args)
{
#define.pi(3.142)
#define.name('Tony')
#define.address('SR Nagar, Hyd')
;
info(strfmt('%1',#pi));
info(#name);
info(#name + "is a bad person");
info(#address);
}
{
#define.pi(3.142)
#define.name('Tony')
#define.address('SR Nagar, Hyd')
;
info(strfmt('%1',#pi));
info(#name);
info(#name + "is a bad person");
info(#address);
}
2) AOT Macro :
AOT Macros will help to resue the functions inside it.
>>Go to AOT >> Macros >> Right click on the Macros node >> New Macro >> rename it to TDSAdd 4 functions inside the macros by doubling clicking it
>>Go to AOT >> Macros >> Right click on the Macros node >> New Macro >> rename it to TDSAdd 4 functions inside the macros by doubling clicking it
#define.college('SR College')
#define.age(30)
#define.inst('Vertex soft')
#define.cl(4000.00)
#define.age(30)
#define.inst('Vertex soft')
#define.cl(4000.00)
>>How to call AOT Macro
>>Create a new job as shown below
>>Create a new job as shown below
static void TDS_CallAOTMacro(Args _args)
{
#TDS
;
info(#college);
info(int2str#age));
}
{
#TDS
;
info(#college);
info(int2str#age));
}
>>How to use in any other object:
Go to TDS_CustTable >> Methods >> Override initvalue() method and paste the following code
Go to TDS_CustTable >> Methods >> Override initvalue() method and paste the following code
public void initValue()
{
#TDS
;
super();
this.Creditlimit = #cl;
this.JoinedDate = systemdateget();
}
{
#TDS
;
super();
this.Creditlimit = #cl;
this.JoinedDate = systemdateget();
}
3) Macro library :
Microsoft has already given many macros in AOT >> Macros node
[sys] layer
we can go ahead and add any function to already existing macros [sys layer]
Microsoft has already given many macros in AOT >> Macros node
[sys] layer
we can go ahead and add any function to already existing macros [sys layer]
AOT >> Macros >> AOTExport >> open in editor and add a new function at the end
#define.marks(30)
How to call Macro library macro
How to call Macro library macro
static void TDS_MacroLib(Args _args)
{
#aotexport //#macrolib.aotexport
;
info(int2str(#marks));
}
{
#aotexport //#macrolib.aotexport
;
info(int2str(#marks));
}
How to pass values or nuMber of lines in Macros: possible
static void TDS_PassingValues_Macro(Args _args)
{
int c;
#localmacro.sum
c = %1 + %2;
#endmacro
;
#sum(10,20)
info(int2str(C));
#sum(1000,5466)
info(int2str(c));
}
{
int c;
#localmacro.sum
c = %1 + %2;
#endmacro
;
#sum(10,20)
info(int2str(C));
#sum(1000,5466)
info(int2str(c));
}
Macros reduces number of lines of code as well
static void TDS_PassingValues_Macro(Args _args)
{
int c;
#localmacro.sum
c = %1 + %2;
c = c - 4;
c = c * 4/100;
#endmacro
;
#sum(10,20)
info(int2str(C));
#sum(1000,5466)
info(int2str(c));
}
{
int c;
#localmacro.sum
c = %1 + %2;
c = c - 4;
c = c * 4/100;
#endmacro
;
#sum(10,20)
info(int2str(C));
#sum(1000,5466)
info(int2str(c));
}
Note : It is best practice to use macros only to define constants. Also TDS stands for Tushar Devendra Srivastava just using my initials as best pratice for creating my own customizations.
Hope you find it useful..... :)