Macros in SQL statements.

One of the benefits to use Macros, is that it allows to specify  partial statements on X++ querry code, that can be reused in several parts along any application.


  • Reused the code
  • It enhances the Reading source code
  • Flexibility in  modifications
  • Reduce the development time


Class with two methods that make Querys to the DataBase

Method: custPaymentProcess



Method: advancesProcess



After the analysis made to the methods, we can see that the querys can be use inside the Macros, in this way, the visibility of the code can be improved and make use of the reused code.

For this, we create two Macros:

All simplifies when we use Macros

Macro FieldsCustPaymentHeader



Below we explain the code.

  • The %1, %2, %n allows our Macro to receive args, this identifies from where we call the Macro and the variables that we use inside of this.
  • #ifNot.Empty(%n) allows identifies a conditioning range according to the arg that is beign sending to the Macro. In this example we check if the send parameter in the thirth position isn’t empty, so execute all block #ifNot.Empty(%3) …#EndIf
  • #EndIf identify that is the final of the conditioning Macro
  • #if.Empty(%n) it permits check if the send parameter in the position %n is empty, so it executes all if contain #If .Empty…#EndIf

Macro FieldsCustPaymentLine



The explication shows in the first Macro apply in this Macro.

Using a Macro in SQL querys in X++

Modified our original code for replace with the Macros created before




  • Francisco Ordonez

    by iu