How to Update a Record in DB Using ADVPL

0

I'm having trouble doing something that should be pretty simple.

I created a custom field for a table named SALDO .

In my code a SELECT is made to access the records that interest me with an alias TMP . After that SELECT loop these records and show to my user as a list of products. My user will change some values of aCols and based on what it changes I should make a calculation and save this value in the bank in the SALDO field of that registry, however I am not able to do this. What I tried and did not work for is the following:

DbSelectArea("TABELA")
RecLock("TMP2", .F.)
TMP2->SALDO := 400
MSUnLock()

I can not post my complete code per company policy but an outline of how it works can be seen below:

_cQuery := "SELECT C1,C2,C3,C4,SALDO FROM TABELA
_cQuery := ChangeQuery(_cQuery)
TCQUERY _cQuery NEW ALIAS "TMP"
DbSelectArea("TMP")
DbGoTop()
While TMP->(!(EOF()))
//Carrega valores no aCols dentro do while


RecLock("TMP2", .F.)
TMP2->SALDO := 400
MSUnLock()
TMP->(Dbskip())
EndDo
TMP->(DbCloseArea())

I'm getting the error TOP Error -19 - Invalid Operation - Update NOT ALLOWED on Query File. when I try to update.

    
asked by anonymous 25.05.2017 / 13:57

1 answer

3

See if this helps you:

Contrary to what you reported, the example below does not use an explicit sql clause:

I enter an index: dbSetOrder(1)
I pass the information to the index: dbSeek(xFilial("SA1") + "900001" + "01")

dbSelectArea("SA1")
dbSetOrder(1) // A1_FILIAL + A1_COD + A1_LOJA
dbSeek(xFilial("SA1") + "900001" + "01")

IF FOUND() // Avalia o retorno da pesquisa realizada
          RECLOCK("SA1", .F.)

          SA1->A1_NOME := "MARCOS AURELIUS TERCEIRUS"
          SA1->A1_NREDUZ := "MARCOS AURELIUS"

          MSUNLOCK()     // Destrava o registro
ENDIF

Link TDN .

    
25.05.2017 / 14:09