Constants and Macros

[Previous] [Next]

You can define macros by using the macro and macro-end keywords. Macros are useful for three purposes:

  • defining constants
  • defining complex patterns
  • encapsulating code

The following macro defines a constant:

 macro pi is 3.14159265358979323846264 macro-end 

You can use this macro in an equation, as in this program:

 include "ombcd.xin" macro pi is 3.1415926535897932 macro-end process local bcd area local bcd r initial {5.9} set area to pi * r * r output "d" % area 

The following macro defines a pattern for a decimal number:

 macro decimal-number is ("-"? digit+ ("." digit+)?) macro-end 

You can use this macro in a find rule:

 find "[" decimal-number => number "]" 

NOTE
It is wise to surround any pattern defined in a macro with parentheses to ensure that the whole pattern is assigned to a pattern variable (if you use a pattern variable in the pattern).

The following macro encapsulates a block of code. In this case, the code is a catch block. You cannot encapsulate the code in a function, since a function would create a new scope, and a catch block must occur in the scope it is intended to catch for.

 macro catch-and-report-program-errors is catch #program-error code c message m location l log-message ( "Error " || "d" % c || "%n" || m || "%n" || l || "%n" ) macro-end 

You can use this macro where you would have placed a catch in your program.

 include "ombcd.xin" include "builtins.xin" macro pi is 3.1415926535897932 macro-end macro catch-and-report-program-errors is catch #program-error code c message m location l log-message ( "Error " || "d" % c || "%n" || m || "%n" || l || "%n" ) macro-end process local bcd area local bcd r initial {"5.9"} set area to pi * r * r output "d" % area catch-and-report-program-errors 



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net