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?
0
Comments
SalesLine2.SETRANGE("Attached to Line No.", SalesLine."Line No.");
...
UNTIL SalesLine.NEXT=0;
END;
SalesLine.RESET;
SalesLine.SETRANGE("Document Type",SalesLine."Document Type");
SalesLine.SETRANGE("Document No.",SalesLine."Document No.");
SalesLine2.SETRANGE("Attached to Line No.", SalesLine."Line No."); this code tries to differentiate products in which "Attached to line no." <> 0 is a container and "line no." = 0 is a normal product.
The objective is to obtain the volume of the container dividing the number of products by the number of containers in the order and thus obtaining the cost.
SalesLine2.SETRANGE("Document Type", SalesLine."Document Type"); -> Here it gets the filter
SalesLine2.SETRANGE(SalesLine2."Document No.", SalesLine."Document No."); -> Not getting the filter or 0
SalesLine2.SETRANGE("Attached to Line No.", SalesLine."Line No."); Not getting the filter or 0
Any ideas?
It would make helping you so much easier...
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
... ...
But i have to see the consequences of the calculations if i remove this filter.
If i remove all, products (Item or Item containers) will be read.
Going to see hhow it goes...
Which version is the 'live' version?
Is it possible that you have copied the entire function from one place to another and the two listings are in fact two different versions of the same function taken from different objects?
Missing VAR next to SalesLine2 may explain why nothing is passed back
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
This is how it goes when i Run the Code Unit and use the debugger.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03