Can someone help me understand this C/AL code?

ekornmeyerekornmeyer Member Posts: 12
edited 2013-08-13 in NAV Three Tier
We are using this program called Jet Reports which is basically just an excel add-in that lets you run Nav reports using their functions. I'm trying to re-create the Inventory Valuation report inside of Jet because we need additional info and don't have a developer's license for Nav..

I looked at the C/AL code in the classic client for the report and the part I'm having trouble understanding is this:
WITH ItemLedgEntry DO BEGIN
  // adjust remaining quantity
  "Remaining Quantity" := Quantity;
  IF Positive THEN BEGIN
    ItemApplnEntry.RESET;
    ItemApplnEntry.SETCURRENTKEY(
      "Inbound Item Entry No.","Item Ledger Entry No.","Outbound Item Entry No.","Cost Application");
    ItemApplnEntry.SETRANGE("Inbound Item Entry No.","Entry No.");
    ItemApplnEntry.SETRANGE("Posting Date",0D,AsOfDate);
    ItemApplnEntry.SETFILTER("Outbound Item Entry No.",'<>%1',0);
    ItemApplnEntry.SETFILTER("Item Ledger Entry No.",'<>%1',"Entry No.");
    IF ItemApplnEntry.FIND('-') THEN
      REPEAT
        IF ItemLedgEntry2.GET(ItemApplnEntry."Item Ledger Entry No.") AND
           (ItemLedgEntry2."Posting Date" <= AsOfDate)
        THEN
          "Remaining Quantity" := "Remaining Quantity" + ItemApplnEntry.Quantity;
      UNTIL ItemApplnEntry.NEXT = 0;
  END ELSE BEGIN
    ItemApplnEntry.RESET;
    ItemApplnEntry.SETCURRENTKEY(
      "Outbound Item Entry No.","Item Ledger Entry No.","Cost Application","Transferred-from Entry No.");
    ItemApplnEntry.SETRANGE("Item Ledger Entry No.","Entry No.");
    ItemApplnEntry.SETRANGE("Outbound Item Entry No.","Entry No.");
    ItemApplnEntry.SETRANGE("Posting Date",0D,AsOfDate);
    IF ItemApplnEntry.FIND('-') THEN
      REPEAT
        IF ItemLedgEntry2.GET(ItemApplnEntry."Inbound Item Entry No.") AND
           (ItemLedgEntry2."Posting Date" <= AsOfDate)
        THEN
          "Remaining Quantity" := "Remaining Quantity" - ItemApplnEntry.Quantity;
      UNTIL ItemApplnEntry.NEXT = 0;
  END;

  // calculate adjusted cost of entry
  ValueEntry.RESET;
  ValueEntry.SETCURRENTKEY("Item Ledger Entry No.","Entry Type");
  ValueEntry.SETRANGE("Item Ledger Entry No.","Entry No.");
  ValueEntry.SETRANGE("Posting Date",0D,AsOfDate);
  IF ValueEntry.FIND('-') THEN
    REPEAT
      ExpectedValue := ExpectedValue + ValueEntry."Cost Amount (Expected)";
      ExpectedValueACY := ExpectedValueACY + ValueEntry."Cost Amount (Expected) (ACY)";
      InvoicedValue := InvoicedValue + ValueEntry."Cost Amount (Actual)";
      InvoicedValueACY := InvoicedValueACY + ValueEntry."Cost Amount (Actual) (ACY)";
    UNTIL ValueEntry.NEXT = 0;
  "Cost Amount (Actual)" := ROUND(InvoicedValue + ExpectedValue);
  "Cost Amount (Actual) (ACY)" := ROUND(InvoicedValueACY + ExpectedValueACY,Currency."Amount Rounding Precision");
END;

Specifically:

// adjust remaining quantity
"Remaining Quantity" := Quantity;

Is the line above saying take the Remaining Quantity field from the ILE and set it to the Quantity field on the ILE?

ItemApplnEntry.SETRANGE("Inbound Item Entry No.","Entry No.");
ItemApplnEntry.SETRANGE("Posting Date",0D,AsOfDate);
ItemApplnEntry.SETFILTER("Outbound Item Entry No.",'<>%1',0);
ItemApplnEntry.SETFILTER("Item Ledger Entry No.",'<>%1',"Entry No.");

What exactly is happening above? Are they matching the Entry No. from the ILE to related purchase??

"Remaining Quantity" := "Remaining Quantity" + ItemApplnEntry.Quantity;

Why would they be taking the Remaining Quantity (which is now the Quantity field) and adding the Quantity from the ILE? When I do that on a positive entry it doesn't make sense at all..

I'm just pretty confused over all as I'm not a big programmer.. it would help so much if I could get this dumbed down a little
Sign In or Register to comment.