0
I created a source to update a field within a table based on a query validation, ask it works in debug, but for some reason it doesn’t go through the array, and also doesn’t update any record, even though it has 6000 to update.
User Function IM06SCX01()
Private oProcess := Nil
FWMsgRun(, {|oSay| U_IM06SC01()}, "Processando Registros", "Processando")
Return()
User Function IM06SC01()
Local cQuery := ""
Local aCols := {}
Local cAlias := "SE2"
Private cPerg := "IM06SC01 "
/*PRIVATE mv_par01
PRIVATE mv_par02
PRIVATE mv_par03
PRIVATE mv_par04
*/
ValidPerg(cPerg)
If !Pergunte(cPerg,.T.)
Return
EndIf
cQuery := " SELECT * " + CRLF
cQuery += " FROM "+RetSQLName("SE2")+" SE2 " + CRLF
cQuery += " WHERE D_E_L_E_T_ = ' ' " + CRLF
cQuery += " AND E2_EMISSAO <> E2_EMIS1 " + CRLF
cQuery += " AND E2_FILIAL BETWEEN '"+ mv_par01 +"' AND '"+ mv_par02 +"' " + CRLF
cQuery += " AND E2_EMISSAO BETWEEN '" + Dtos(mv_par03)+"' AND '" + Dtos(mv_par04)+"'"+ CRLF
TCQUERY cQuery NEW ALIAS (cAlias)
(cAlias)->(DbGoTop())
Do While !(cAlias)->(Eof())
aAdd(aCols,{.F.,;
(cAlias)->E2_FILIAL,;
(cAlias)->E2_NUM,;
(cAlias)->E2_TIPO,;
(cAlias)->E2_FORNECE,;
(cAlias)->E2_LOJA})
(cAlias)->(dbSkip())
EndDo
(cAlias)->(DbGoTop())
DbSelectArea("SE2")
SE2->(dbSetOrder(1))
SE2->(dbGoTop())
For nx := 1 To Len(aCols)
If SE2->(dbSeek(aCols[nx][2]+aCols[nx][3]+aCols[nx][4]+aCols[nx][5]+aCols[nx][6]))
RecLock("SE2",.F.)
SE2->E2_EMIS1 := SE2->E2_EMISSAO
SE2->(MsUnlock())
nCont++
Endif
Next nx
If nCont > 0
MsgInfo(cValtoChar(nCont) + " registros processados.", "TOTVS")
Else
MsgInfo("Nenhum registro processado","TOTVS")
Endif
Return
//*--------------------------------------------------------------------------------------------------------------------
Static Function ValidPerg(cPerg)
Local aArea := GetArea()
cPerg := PADR(cPerg,10)
PutSx1(cPerg,"01","Filial de ","","","mv_ch1","C",06,0,0,"G","","","","","mv_par01","","","","","","","","","","","","","","","","","","","","","","")
PutSx1(cPerg,"02","Filial ate ","","","mv_ch2","C",06,0,0,"G","","","","","mv_par02","","","","","","","","","","","","","","","","","","","","","","")
PutSx1(cPerg,"03","Data de ","","","mv_ch3","D",08,0,0,"G","","","","","mv_par03","","","","","","","","","","","","","","","","","","","","","","")
PutSx1(cPerg,"04","Data Ate ","","","mv_ch4","D",08,0,0,"G","","","","","mv_par04","","","","","","","","","","","","","","","","","","","","","","")
RestArea(aArea)
Return
Check the error logs, something pops up ? If yes, edit the question by adding the log
– Murilo Melo
Returns only : Output value: 1
– user106077