cAliasAlias opened for the query; a missing alias causes a fatal error.
AdvPL GuideTCSetField( <cAlias>, <cField>, <cType>, [nSize], [nPrecision] )Adjusts the type, size and precision of a column returned by a DBAccess query.
Queries opened through TCGenQry() return numeric fields as 15,8 by default and treat other fields as character data. TCSetField() redefines how date, logical and numeric columns are exposed by the query alias. This is especially useful for ERP dates physically stored as CHAR or VARCHAR in YYYYMMDD format. It changes the logical cursor definition, not the data or physical table structure.
TCSetField( <cAlias>, <cField>, <cType>, [nSize], [nPrecision] )cAliasAlias opened for the query; a missing alias causes a fatal error.
cFieldCursor column to redefine.
cTypeAdvPL type: D, N or L.
nSizeTotal digits for N, from 1 to 18.
Default:0nPrecisionDecimal places for N, from 0 to nSize - 1.
Default:0The documentation does not define an application return value. The relevant effect is the updated column treatment.
#Include "TOTVS.ch"
#Include "TopConn.ch"
User Function ExQueryTypes()
Local cAlias := GetNextAlias()
Local cQuery := ""
Local dIssueDate
Local lActive
Local nAmount
cQuery := " SELECT C5_EMISSAO, C5_TIPO, C5_VALOR "
cQuery += " FROM " + RetSqlName("SC5")
cQuery += " WHERE D_E_L_E_T_ = '' "
cQuery := ChangeQuery(cQuery)
DbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), cAlias, .F., .T.)
TCSetField(cAlias, "C5_EMISSAO", "D")
TCSetField(cAlias, "C5_TIPO", "L")
TCSetField(cAlias, "C5_VALOR", "N", 15, 2)
dIssueDate := (cAlias)->C5_EMISSAO
lActive := (cAlias)->C5_TIPO
nAmount := (cAlias)->C5_VALOR
(cAlias)->(DbCloseArea())
Return {dIssueDate, lActive, nAmount}The columns are read with the configured AdvPL types. Validate actual dictionary fields and logical content.
Local aStructure := CT2->(DBStruct())
Local nField
For nField := 1 To Len(aStructure)
If aStructure[nField, 2] $ "DNL"
TCSetField("CT2TMP", aStructure[nField, 1], ;
aStructure[nField, 2], aStructure[nField, 3], ;
aStructure[nField, 4])
EndIf
Next nFieldD, N and L fields guide equivalent cursor columns.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use