@accfs Function

Top  Previous  Next

@accfs() (Accumulate from String) function is similar to the @accfa() function with a difference that the @accfs() function parses the delimited substrings in the given string and performs an accumulation for the each substring that satisfies the specified precondition and returns the accumulated value.

Syntax:

@accfs(stringsubstring-delimiter, [precondition]accumulate-by-expression[, delimiter])
 

string

The string that contains the delimited substrings to process.

substring-delimiter

The character that delimits the substring in the given string. When parsing the substrings the quotes and the parenthesizes are considered to be the grouping symbols and the delimiter characters existing within them are ignored.
 
Example:

String:

AA, (BBB , (CCC)), DDD + 'Clooney, George'

Delimiter:

','

Substrings:

AA
(BBB , (CCC))
DDD + 'Clooney, George'

If no value is given as the delimiter then each character in the string accepted to be a substring.
 
Example:

String:

ABC

Delimiter:

''

Substrings:

A
B
C

precondition

If this parameter is not left blank it is tested as a precondition for each substring parsed and if the result is true, only then the accumulation is performed.

accumulate-by-expression

For each parsed substring 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.

'.' Symbol

'.' character represents the parsed substring and it can be used as a symbol within precondition and accumulate-by-expression.

 

Examples:

Example 1:

@accfs(i:SSTR,' ',,1)
 
For each substring delimited with spaces in the value of i:SSTR symbol, the result value will be increased by one and at the end, the accumulated result will be returned.

 

 
Example 2:

SELECT NAME, STOCK FROM products WHERE @accfs(i:IDS,' ', . > 0, 'ID = ' + ., ' OR ')

 

The value of i:IDS is '12 35 -44 55'

 

ID          Accumulation

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

12          ID = 12

35          ID = 12 OR ID = 35

-44         ID = 12 OR ID = 35      // Will not be processed since the precondition is not satisfied

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(), @accfa()