Macro example

Hai all,

I am working on Macros. I am geting syntax error in the below code in the line #LMacReportLog. Could you please help me.

static void MacroExample(Args _arg)
{
int a =1;
;
#localmacro.LMacReportLog
a
print(“Hai-%1 --LM, print.”);
info(“Hai-%1 --LM, Infolog.”);
#endmacro

#LMacReportLog
pause;

}

Try this out:

static void MacroExample(Args _arg)

{

int a =1;

;

#localmacro.LMacReportLog

print(“Hai-%1 --LM, print.”);

info(“Hai-%1 --LM, Infolog.”);

#endmacro

#LMacReportLog

pause;

}

Hai vishal,

Thanks for the reply. My problem is, I want to catch integer value in Macro. That is i want to include “a” in the macro.

Can u include ‘a’ in the lacal macro and rectify the problem.

Reference to a macro is simply replaced by its body and a is not a valid X++ statement. You could use the variable in a valid statement (e.g. info(int2str(a));) but it’s strange to have macros that depend on specific variable names. The right way is to use parameters - for example:

int a = 1;
;
#localmacro.LMacReportLog
    info(int2str(%1));
#endmacro
    
#LMacReportLog(a)

This would help you:

static void MacroExample(Args _arg)

{

int a =1;

;

#localmacro.LMacReportLog

a

#endmacro

info(“Hai-%1 --LM, Infolog.”);

info(strfmt("%1", #LMacReportLog));

}

Hai Vishal and Martin,

Thanks for ur help.