Fwtemporarytable

Asked

Viewed 297 times

1

Hi, I’m starting to program now in advpl and I saw that the recommended currently and the use of temperate tables with Fwtemporarytable, however I have some doubts, because I tried to make a code like some examples I saw on the net and in the advanced ADVPL booklet, and did not work.

Follows my code:

user function tpmsb1()

Local aFields := {}
Local oTempTable
Local nI as numeric
Local cAlias as char
Local cQuery

Local cFields := " B1_FILIAL, B1_COD, B1_DESC, B1_USPRE, B1_TIPO, B1_LOCPAD, B1_UM "

//-------------------------
//Monta os campos da tabela
//-------------------------

aadd(aFields,{"B1_FILIAL","N",5,0})
aadd(aFields,{"B1_COD","N",5,1})
aadd(aFields,{"B1_DESC","C",15,0})
aadd(aFields,{"B1_USPRE","C",15,0})
aadd(aFields,{"B1_TIPO","C",2,1})
aadd(aFields,{"B1_LOCPAD","N",2,0})
aadd(aFields,{"B1_UM","C",2,0})

//------------------
//Criação do objeto
//------------------

cAlias := getNextAlias()

oTempTable := FWTemporaryTable():New( cAlias )

oTempTable:SetFields( aFields )

oTempTable:AddIndex("01", {"B1_COD"} )

//-----------------
//Criação da tabela
//-----------------

oTempTable:Create()

//  cAlias := oTempTable:GetRealName()

//  MsgInfo(RetSqlName("SB1"), 'Executando a copia dos registros da tabela: ')

    cQuery := "select"+ cFields +" from "+ RetSqlName("SB1")

// Deveria mas... não esta funcionando.
//  oTempTable:InsertIntoSelect( {"B1_FILIAL", "B1_COD", "B1_DESC", "B1_USPRE", "B1_TIPO", "B1_LOCPAD", "B1_UM"} , cAlias , { "B1_FILIAL", "B1_COD", "B1_DESC", "B1_USPRE", "B1_TIPO", "B1_LOCPAD", "B1_UM" } )

    MPSysOpenQuery(cQuery, 'TPMSB1')

    DbSelectArea('TPMSB1')

// Ate aqui, temos nossas infos nas variáveis, mas, são da tabela temporária, ou da SB1??...

        while TPMSB1->(!eof()) 
            for nI := 1 to FCount()

                VarInfo(FieldName(nI),FieldGet(ni)) //? 

            next DbSkip()
        EndDo

   //Exclui a tabela
   oTempTable:Delete()
return 

If someone has a clearer reading, or videos on the subject, I also accept as help

  • Arnon, what didn’t work? Generated some error.log?

  • Hi Daniel, there was no apparent "error", however, I have as an example the function "oTempTable:Insertintoselect()" in the booklet, and in some examples, I saw what it should do, and because it is important, however, in my code it does not generate any impact. Always goes back to the first line of SB1 records, which left me in doubt whether, I’m just making a select on it, or I’m actually picking things up on temporary.

  • Arnon, there are examples of using this class in Medium, take a look, I hope it helps you: https://medium.com/totvsdevelopers/insert-into-select-populando-tabela-tempor%C3%A1ria-1b3e1d1c93f e https://medium.com/vstotdevelopers/protheus-tabela-tempor%C3%A1ria-b2e955f434

No answers

Browser other questions tagged

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