Hi Experts!!
NAV2018, shared customer table for all companies
In a report I need to put the client balance per company,for which I have a temporary table, but the value only calculates it to me correctly for the first company, for the rest it leaves the same value and does not recalculate it, this is my code:
pCompany.RESET;
IF pCompany.FINDFIRST THEN REPEAT
pCustomer.RESET;
pCustomer.CHANGECOMPANY(pEmpresa.Name);
IF pCustomer.FINDFIRST THEN REPEAT
pCustomer.CALCFIELDS("Balance (LCY)");
IF pCustomer."Balance (LCY)"<>0 THEN BEGIN
pSaldos.INIT;
pSaldos.Empresa:=pCompany."Display Name";
pSaldos.NIF:=pCustomer."VAT Registration No.";
pSaldos.Nombre:=pCustomer.Name;
pSaldos."Saldo Deudor":=pCustomer."Balance (LCY)";
pSaldos.INSERT(TRUE);
END;
UNTIL pCustomer.NEXT=0;
UNTIL pCompany.NEXT=0;
Any ideas? thanks in advance
0
Answers
it should be pCompany.Name
side note: "IF xyz.FINDFIRST THEN REPEAT" is bad practise. Use "IF xyz.FINDSET THEN REPEAT" for better performance.
Reason: If you want to loop through several records, "findset" is made to get a few of them into the NSTs buffer for faster processing. With Findfirst, your NST doesn't expect you to need more than one record so it will only ask the SQL server for the "top 1" and i guess it will repeat that practise with every "next".
If you don't belive me, please read the "remarks"-Section of those two functions in the help.
but in the code is well placed
StLi , I belive you!!
Same behaviour with validates.
lubost, that's what I did and it works perfectly