1
I need to load the field CK_XLOTE typing the code of the product in the field CK_PRODUTO, I am generating a function to perform this procedure, but it is not returning the lot in the field. Can someone help me.
Follow the code
#INCLUDE 'PROTHEUS.CH'
#INCLUDE 'PARMTYPE.CH'
User Function TESTE()
//MsgAlert(M->CK_PRODUTO)
Local cQuery := ""
Local cLote := ""
cQuery := " SELECT TOP 1 "
cQuery += " SB8.B8_LOTECTL, "
cQuery += " SB8.B8_DTVALID "
cQuery += " FROM " + RetSQLName("SB8") + " AS SB8 "
cQuery += " WHERE SB8.B8_FILIAL = '" + xFilial("SB8") + "' "
cQuery += " AND SB8.B8_LOCAL = '01' "
cQuery += " AND SB8.B8_DTVALID > GETDATE() "
cQuery += " AND SB8.B8_SALDO > SB8.B8_EMPENHO "
cQuery += " AND SB8.B8_PRODUTO = '" + M->CK_PRODUTO + "' "
cQuery += " AND SB8.D_E_L_E_T_ = '' "
cQuery += " ORDER BY SB8.B8_DTVALID "
If SELECT("SQL") > 0
dbSelectArea("SQL")
dbCloseArea()
EndIf
cQuery := ChangeQuery(cQuery)
dbUseArea(.T., 'TOPCONN', TCGENQRY(,,cQuery),"SQL", .F., .T.)
dbSelectArea("SQL")
If SQL->(!EOF())
cLote := SQL->B8_LOTECTL
EndIf
return(cLote)
A hint, do not use table alias starting with S, mainly with 3 letters.. As it is used by the standard tables, try using a Getnextalias() to determine the alias and see if it works...
– thur
Vlw thanks for the help.
– Junior Guerreiro
Thanks for your help. Now you can take me a doubt,this my function and to load a field that the query is bringing, now my doubt is, if in this same query, I bring two fields as a result, for me to fill two fields in the system and need to create two functions one for each trigger of the specific field against domain.
– Junior Guerreiro