Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

FieldGet

FieldGet( nPos ) --> xRet

Reads a field value at the current record position.

FieldGetAdvPL
01 · OVERVIEW

Overview

FieldGet uses an ordinal position rather than a name. Invalid positions can return Nil with a warning; type depends on schema and queries may need TCSetField for dates/logicals. The GitHub source skips three SA1 records and reads field five without checking EOF. The adaptation locates ED_COD using FieldPos and verifies a valid record before reading without hardcoding an ordinal. Only type is shown. EDTRB is an already-open owned test alias; ED_COD, when used, is a length-10 character field in the teaching schema. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

FieldGet( nPos ) --> xRet

Parameters

nPos
NumericRequired

Valid ordinal position in the alias.

Return value

Field content under its type; Nil in documented error cases.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed384()
    Local nPosition
    Local xValue
    If Select("EDTRB") > 0
        nPosition := EDTRB->(FieldPos("ED_COD"))
        // Field existence alone is not enough: check the cursor.
        If nPosition > 0 .And. !EDTRB->(Eof())
            xValue := EDTRB->(FieldGet(nPosition))
            ConOut(ValType(xValue))
        EndIf
    EndIf
Return Nil
Expected result

Expected type C under the test schema; field content is not exposed. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Use only an owned test table with known schema. Qualify the alias, check record position and manage context changes under the caller contract.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FieldGet. TDN. Accessed on 2026-10-26.
  2. EURAI. ADVPL/Funcoes/Acesso a Dados/FieldGet.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado. Accessed on 2026-10-26.
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