Hello,
I have been programming in C/AL for some time but I have a doubt in this particular case.
I'm trying to get a cost of a particular product line from an order, in which the dividend is the result of another function, and the divisor will be a new variable as the code shows below:
GetPVmin(VAR SalesLine : Record "Sales Line";VAR SalesLine2 : Record "Sales Line";ShipAgent : Code[20];Contacto : Code[20];ShipPostCode : Code[20];Country : Code[10]) : Decimal
SalesLine.SETFILTER(Type,'<>0');
IF SalesLine.FINDSET THEN
BEGIN
IF SalesLine."Document Type"<>SalesLine."Document Type"::Order THEN
EXIT;
ltcontact.GET(Contacto);
IF NOT ltTabDiv.GET('RUBCUSTO',0,'TAXAJURO') THEN
EXIT;
ltLocation.GET(SalesLine."Location Code");
IF ltLocation."Country/Region Code"='' THEN
ltLocation."Country/Region Code":='PT';
IF Country='' THEN
Country:='PT';
KgTotais:=0;
distancia:=GetDist(ltLocation."Post Code",ShipPostCode,ltLocation."Country/Region Code",Country);
REPEAT
IF NOT SalesLine."Item Container" THEN
KgTotais+=SalesLine.Quantity
ELSE
BEGIN
ltValueEntry."Entry No.":=SalesLine."Attached to Line No.";
ltValueEntry."Item No.":=SalesLine."No.";
ltValueEntry."Valued Quantity":=SalesLine.Quantity;
ltValueEntry.INSERT;
END;
UNTIL SalesLine.NEXT=0;
SalesLine.SETRANGE("Item Container",FALSE);
VVasilhame:=0;
IF SalesLine.FINDSET THEN
REPEAT
SalesLine2.RESET;
SalesLine2.SETRANGE("Document Type", SalesLine."Document Type");
SalesLine2.SETRANGE(SalesLine2."Document No.", SalesLine."Document No.");
SalesLine2.SETRANGE("Attached to Line No.", SalesLine."Line No.");
QProduto:=0;
QVasilhame:=0;
IF SalesLine2.FINDFIRST THEN
IF (SalesLine2."Attached to Line No." <>0) THEN
BEGIN
QProduto+=SalesLine.Quantity;
QVasilhame+=SalesLine2.Quantity;
VVasilhame:=QProduto/QVasilhame;
END;
SalesLine."Custo Operação":=GetCustoOperacao(SalesLine."No.",SalesLine."Variant Code")/(SalesLine.Quantity); <- replace by VVasilhame.
//VVasilhame will be always 0
The SalesLine2 won't initialize or won't get any value
Any sugestions of what am i doing wrong?
*This post is locked for comments