FwTemporaryTable [closed]

closed . This question needs details or to be clearer and is not currently accepting answers.

want to improve this question? Add details and make it clearer what problem is being solved by editing this post .

Closed 1 year ago .

improve this question

Hi, I'm starting to program now in advpl and saw that the currently recommended and the use of tables would temper with FwTemporaryTable, but I have some doubts, because I tried to make a code equal some examples that I saw on the net and in the advpl advanced Apostille, and they did not work.

Follow 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 anyone has a clearer reading, or videos on the subject, I also accept it as a form of help \ O

 1
Author: Daniel Mendes, 2019-11-08