Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

FieldPut

FieldPut( nPos, xValue ) --> xRet

Assigns a typed value to a locked record field.

FieldPutAdvPL
01 · OVERVIEW

Overview

FieldPut requires a type-compatible value and record lock like direct assignment. It returns the assigned value rather than complete business success. The GitHub source modifies SA1 field five without testing RecLock; this adaptation uses only an owned table, finds the named field, checks type/length and writes only after acquiring the lock. It does not replace complete routine validation and error handling. 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

FieldPut( nPos, xValue ) --> xRet

Parameters

nPos
NumericRequired

Valid field position.

xValue
AnyRequired

Type- and length-compatible value.

Return value

Assigned value; Nil for an invalid field number.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed385()
    Local nPosition
    Local aStructure
    Local cValue := "SAMPLE"
    If Select("EDTRB") > 0
        nPosition := EDTRB->(FieldPos("ED_COD"))
        If nPosition > 0 .And. !EDTRB->(Eof())
            aStructure := EDTRB->(DBStruct())
            If aStructure[nPosition,2] == "C" .And. aStructure[nPosition,3] >= Len(cValue)
                // Write only to the locked test record.
                If RecLock("EDTRB", .F.)
                    EDTRB->(FieldPut(nPosition, cValue))
                    EDTRB->(MsUnlock())
                EndIf
            EndIf
        EndIf
    EndIf
Return Nil
Expected result

Assigns fictional text only when requirements are met; no Protheus persistence test performed. 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. FieldPut. TDN. Accessed on 2026-10-26.
  2. EURAI. ADVPL/Funcoes/Acesso a Dados/FieldPut.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