Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

AScan

AScan( <aDest>, <xExpr>, [nStart], [nCount] ) --> nRet

Finds the first position matching a value or search block.

AScanAdvPL
01 · OVERVIEW

Overview

AScan returns the matched position or zero. For multidimensional structures its block receives each first-level element and must return logical. Simple string comparisons depend on SET EXACT; a block using == makes equality explicit. The returned index belongs to the source even when the search range starts elsewhere. (TOTVS, s.d., ref. 1)

02 · SYNTAX

Syntax

AScan( <aDest>, <xExpr>, [nStart], [nCount] ) --> nRet

Parameters

aDest
ArrayRequired

Searched array.

xExpr
AnyRequired

Simple value or logical block.

nStart
NumericOptional

First position; default 1.

nCount
NumericOptional

Count from the starting position; defaults through the end.

Return value

Position starting at 1; zero when not found.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function EdAscan()
    Local aItems := {{"A", 10}, {"B", 20}}
    Local nPos := AScan(aItems, {|aRow| aRow[1] == "B"})
    // Zero is not a valid array index.
    If nPos > 0
        ConOut(cValToChar(aItems[nPos][2]))
    EndIf
Return Nil
Expected result

Expected position: 2; output 20. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Validate external row shapes and types before indexing in the block. Do not modify the collection during search.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. AScan. TDN. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR

Was this content helpful?

👍 Like 0👎 Dislike 0

Sign in to rate this article.

0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha