Thursday, February 9, 2023

Working with Macros in X++ | Hardcode

Basic Macro: A macro is a variable known to the precompiler. The variable can have a value that is a sequence of characters, but it is not required to have a value.


Definition:

#define.Comma(",")


Use:

info(#Comma);



Query Macros: Query macros are defined a little differently as compared to a basic macro


Class Macro

{

    public static void main(Args _args)

    {

        #localmacro.SelectCustomer

        select * from custTable

        #endmacro


        #localmacro.SelectVendor

        select * from vendTable

        #endmacro


        #localmacro.whereClause

         where %1.AccountNum == %2

     &&    %1.Currency   == %3

        #endmacro


        #selectCustomer

        #WhereClause(custTable,'100','USD');


        #SelectVendor

        #WhereClause(vendTable,'1000','PKR');

    }

}