Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

AEval

AEval( <aArray>, <bBlock>, [nStart], [nCount] ) --> aRet

Executes a block for each element in a range.

AEvalAdvPL
01 · OVERVIEW

Overview

The block receives the element and its index. In multidimensional arrays, a first-level element may be a nested array; AEval does not automatically traverse every cell. Individual block results do not build a new mapped collection: write into a separate destination for that. The example accumulates a sum without modifying source values. (TOTVS, s.d., ref. 1)

02 · SYNTAX

Syntax

AEval( <aArray>, <bBlock>, [nStart], [nCount] ) --> aRet

Parameters

aArray
ArrayRequired

Traversed array.

bBlock
Code blockRequired

Block receiving element and index.

nStart
NumericOptional

First position; default 1.

nCount
NumericOptional

Count from the starting position; defaults through the end.

Return value

Array after the operation; do not assume independent cloning.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function EdAeval()
    Local aValues := {10, 20, 30}
    Local nTotal := 0
    // The accumulator is external; no assignments change the array.
    AEval(aValues, {|nValue| nTotal += nValue})
    ConOut(cValToChar(nTotal))
Return Nil
Expected result

Expected result: 60. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Validate element types before summing external data. Avoid resizing the array during evaluation.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. AEval. TDN. Accessed on 2026-10-25.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha