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.

Benefits:

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

Example:

Class with two methods that make Querys to the DataBase

Method: custPaymentProcess

imagen1

 

Method: advancesProcess

imagen2

 

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

imagen3

 

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

imagen4

 

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

imagen5

 

imagen6

  • Francisco Ordonez

    by iu