
First Example
The macro will select records from a table ‘CustTable’ and print a field from the same as the table to be fetched, and the fields (%1, %2, %3) to be printed are specified in the parameters for the first Macro call.
In the second Macro call, the table has not been specified so text will be printed to the Infolog.
public static void main(Args _args)
{
CustTable custTable;
#localmacro.selectCustTable //Macro definition starts here
#ifnot.empty(%1)
while select %1
#ifnot.empty(%3)
order by %3
#endif
{
info(queryValue(%1.%2));
}
#endif
#if.empty(%1)
info('No table specified.');
#endif
#endmacro //Macro definition ends here
#selectCustTable(CustTable, accountNum) //Calling Macro with valid parameters
#selectCustTable //Calling Macro with no parameters – output will be text “No table specified” as per the validation.
}
Second Example
The SELECT-Statement in the example lists only active BOM items (Table BOM) on (active using the fields FromDate and ToDate).
If the second parameter of the macro is empty (zero date ()), so all BOM items are listed.
static void useMacroInSelectStatement(Args _args)
{
bom bom;
date emptyDate;
// parameters: %1 = table instance, %2 date, %3 empty date value
#localmacro.bomDateFilter
&& ( %2 == dateNull() || (
((%1.FromDate <= %2) && (%1.ToDate >= %2)) ||
((%1.FromDate == %3) && (%1.ToDate == %3)) ||
((%1.FromDate <= %2) && (%1.ToDate == %3)) ||
((%1.FromDate == %3) && (%1.ToDate >= %2))
))
#endMacro
;
while select bom
where bom.ItemId == '123'
#bomDateFilter(bom, systemDateGet(), emptyDate)
{
info(bom.bomid);
}
}
Leave a comment