@accfa() Function

Top  Previous  Next

@accfa() (Accumulate from ADOM) function is similar to the @acc() function with a difference that the @accfa()function loops over the "item" nodes of the given ADOM to accumulate a result and returns it.

Syntax:

@accfa(adom-name, [precondition]accumulate-by-expression[, delimiter])
 

adom-name

The name of the ADOM whose item nodes will be traversed. An ADOM scope ("r","s" or "a") can be given prior to a ":" character. If omitted "s" (session) is assumed.

precondition

If this parameter is not left blank it is tested as a precondition for each item node existing in the ADOM and if the result is true, only then the accumulation is performed.

accumulate-by-expression

For each item node of the ADOM that satisfies the precondition this expression will be evaluated and accumulated in the result.

delimiter

This optional parameter can be used when accumulating string data and it will be placed between accumulate-by-expression values. The delimiter is not placed for the first accumulation.

Examples:

Example 1:

@accfa(s:cart,,1) @// For each item node exiting in the cart ADOM the result is incremented by 1.

 

 
This function is especially useful to achieve additional data from database for the records existing in an ADOM, by using it in a RelDB query.

Example 2:

SELECT NAME, STOCK FROM products WHERE @accfa(s:cart,, 'ID = ' + ID, ' OR ') 

 

ID          Accumulation

-------     --------------------------

12          ID = 12

35          ID = 12 OR ID = 35

55          ID = 12 OR ID = 35 OR ID = 55

 

 

Result:

SELECT NAME, STOCK FROM products WHERE ID = 12 OR ID = 35 OR ID = 55

 

See @acc(), @accfs()