How to Update a BD Record using ADVPL

Asked

Viewed 2,004 times

1

I’m struggling to do something that should be very simple.

I created a custom field for a table called SALDO.

In my code is made a SELECT to access the records that interest me with an alias TMP. After that SELECT I loop these records and show them to my user in product list form. My user will change some values of the aCols and based on what it changes I must make a calculation and save that value in the bank in the field SALDO of this such record, but I am not able to do it. What I tried and failed is the following:

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

I can’t post my full code by 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 bug TOP Error -19 - Invalid Operation - Update NOT ALLOWED on Query File. when I try to update.

  • 3

    If you can’t post then you’ll have to turn around. One thing I can already tell, the documentation examples are all very bad. When I worked there, I made much simpler codes than these they teach you to do. I can’t help anymore either because this SQL thing isn’t from my day.

  • 3

    @bigown by the way, this mixture of SQL with function and with ->alias becomes a beautiful salad. It looks like a creation of Dr. Frankenstein. One of the most interesting things about xbase in general is the fact that you don’t need SQL, and it seems that people are going against each other, creating something with no identity. I abandoned the DB Riginals functions a long time ago in favor of SQL, but only for lack of a modern equivalent to Harbour (for now.

  • 3

    @Bacco but look at the bright side, it gives a lot of trouble and thus generates a huge amount of jobs. I have the impression that 90% of the people who work with Advpl would be unemployed or doing something else if it were made to work. The dbSelectArea() are there to make trouble. What I find most curious is the mixture of them with alias in each member :) When the technology provider uses wrong there is no way things will work out. You traded the RDD for the SQL, you didn’t keep them both, so yes.

  • 2

    @Only one left moustache SET FILTER there to solve everything /s

  • The error is self-explanatory: "TOP Error -19 - Invalid Operation - Update NOT ALLOWED on Query File." means that the application is trying to update a field of an ALIAS opened by a QUERY, which does not accept change via Advpl. A Query in Advpl is a read only and forward-only result-set.

  • For more information on how database access works in Advpl, I recommend reading the two posts below: Drivers and Rdds in Advpl And Data Access - Alias and Workarea in Advpl

Show 1 more comment

1 answer

3


See if that helps you:

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

I report an index: dbSetOrder(1)
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.

  • I tried that there already also but nothing of the right.

  • the problem I think is because I do a query in the database to select one record at a time to populate the table of items to be shown to the user. Therefore there is already an active Dbselectarea() . Another question, that dbSeek, what does it actually do? which parameters are those passed to him? and the dbSetOrder what it does? in the documentation I could not understand exactly in a generic way what is done

  • Not to abuse but just to see if I get it. dbSetOrder is like an input for the database columns? if I have 4 columns, they are respectively A, B, C, D. and I use dbSetOrder(2) I set the Dice to column B. Therefore dbSeek() should contain the parameters of the record I want to change from index B, in case I should do dbSeek(value_de_b, value_de_c, value_de_D) to select the desired record? Thanks for the help

  • 4

    I find it unbelievable that we still use such a code today that can be done in 2 lines. These Protheus codes are tragic, so it’s such a problem.

  • Unfortunately I don’t have that concept, I’m an intern at a company, I started working with Totvs last week, I’m getting a lot of... Could you explain or tell me how I have to set the parameters for my code to work? The table I want to update is D4. The field created calls USALDO and was created by myself. The branch I want to change is branch 01, and to select the record you need to set the fields D4_OP and D4_COD

  • 1

    I had forgotten to mark as solved, I just needed to discover the concept of same Indice and the code posted by Voce worked. The Dice is the sequence in which the columns appear when doing a search in the bank roughly.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.