Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Rookie needs help

Posted on by 85

I started working at company that uses NAV 5.0. I have to write a stored procedure to report on the data in SQlServer. The table I'm looking at is the Item table (I hope this is a standard NAV table) and at the inventory column. NAV shows it as column 68, so I'm assuming this is a standard NAV entity. My problem is that this column is not in the Item table in database. Perhaps is a computed column but can't find it anywhere in the NAV code. Any hints? Thank you in advance.

-rpg

*This post is locked for comments

  • Neville Foyn Profile Picture
    Neville Foyn 4,320 on at
    RE: Rookie needs help

    Great, glad you got it sorted

  • rpg Profile Picture
    rpg 85 on at
    RE: Rookie needs help

    Thank you so much again. For the record if someone else needs help, I run the SQL Profiler and these are the queries I got:

    SELECT SUM("SUM$Quantity") as 'On Hand',

    SUM("SUM$Invoiced Quantity") FROM dbo.[Buxton$Item Ledger Entry$VSIFT$2]

    WITH(NOEXPAND)   WHERE (([Item No_]='39316.BK.00'))

    SELECT SUM("Quantity") as 'On Hand',

    SUM("Invoiced Quantity") FROM dbo.[Buxton$Item Ledger Entry]

     WHERE (([Item No_]='39316.BK.00'))

    SELECT SUM([Outstanding Qty_ (Base)]) as 'Qty on PO' FROM dbo.[Buxton$Purchase Line]  

    WHERE (([Document Type]=1)) AND (([Type]=2)) AND (([No_]='39316.BK.00'))

    SELECT SUM("Outstanding Qty_ (Base)") as 'On Sales Order' FROM dbo.[Buxton$Sales Line]

    WHERE (([Document Type]=1)) AND ((Type=2)) AND (([No_]='39316.BK.00'))

    SELECT SUM([Remaining Qty_ (Base)]) FROM dbo.[Buxton$Prod_ Order Line]  

    WHERE ((Status>=1 AND "Status"<=3)) AND (([Item No_]='39316.BK.00'))

    SELECT SUM([Remaining Qty_ (Base)]) FROM dbo.[Buxton$Prod_ Order Component]  

    WHERE (([Status]>=1 AND [Status]<=3)) AND (([Item No_]='39316.BK.00'))

    SELECT SUM([SUM$Outstanding Qty_ (Base)]) FROM dbo.[Buxton$Kit Sales Line$VSIFT$1]

    WITH(NOEXPAND)   WHERE (([Document Type]=1)) AND ((Type=1)) AND (([No_]='39316.BK.00'))

    SELECT SUM([Quantity (Base)]) FROM dbo.[Buxton$Reservation Entry]  WHERE (([Item No_]='39316.BK.00'))

    AND (([Source Type]=32)) AND (([Source Subtype]=0)) AND (([Reservation Status]=0))

    SELECT SUM("SUM$Intrans Qty") as 'In Transit' FROM dbo.[Buxton$Purchase Line$VSIFT$14] WITH(NOEXPAND)

      WHERE (([Document Type]=1)) AND ((Type=2)) AND (([No_]='39316.BK.00')) AND

    (([Outstanding Quantity]>0))

    SELECT SUM([SUM$Quantity]) FROM dbo.[Buxton$Item Ledger Entry$VSIFT$2]

    WITH(NOEXPAND)   WHERE (([Item No_]='39316.BK.00')) AND (([Location Code]='RC'))

    SELECT SUM("Quantity (Base)") FROM dbo.[Buxton$Package Line]  WHERE

    (([No_]='39316.BK.00')) AND (([Type]=2))

    SELECT TOP 1 NULL FROM dbo.[Record Link]  WHERE

    (([Company]='Buxton')) AND (([Type]=0))

    AND (([Record ID]=0x1B0000000089FF4F4D31303032322E424B2E4258000000))

  • Neville Foyn Profile Picture
    Neville Foyn 4,320 on at
    RE: Rookie needs help

    P.S. the types is represented as an integer in the SQL table so the first type of blank is zero, GL account is 1, item is 2 etc...

    ,G/L Account,Item,Resource,Fixed Asset,Charge (Item)

  • Neville Foyn Profile Picture
    Neville Foyn 4,320 on at
    RE: Rookie needs help

    Yep, not the highest performance setup, it was significantly improved in 2009 and 2013 though and these tables were done away with,

    My suggestion to customers running pre-2009 R2 systems it to at least upgrade the application to 2009 r2 it is a pretty simple upgrade and the performance improvement is noticeable in most cases

    The easiest explanation of the calculation is the actual NAV sum code (Think of it as the query code for the field inside of NAV)

    Sum("Purchase Line"."Outstanding Qty. (Base)"

    WHERE (Document Type=CONST(Order),

    Type=CONST(Item),

    No.=FIELD(No.),

    Shortcut Dimension 1 Code=FIELD(Global Dimension 1 Filter),

    Shortcut Dimension 2 Code=FIELD(Global Dimension 2 Filter),

    Location Code=FIELD(Location Filter),

    Drop Shipment=FIELD(Drop Shipment Filter),

    Variant Code=FIELD(Variant Filter),

    Expected Receipt Date=FIELD(Date Filter)))

    I formatted this first one to make it easier to understand, The filter fields are used internally by NAV when it wants a total by key fields so ignore them for your code, the bold bit is the important bit

    Here is the sales one:

    Sum("Sales Line"."Outstanding Qty. (Base)" WHERE (Document Type=CONST(Order),Type=CONST(Item),No.=FIELD(No.),Shortcut Dimension 1 Code=FIELD(Global Dimension 1 Filter),Shortcut Dimension 2 Code=FIELD(Global Dimension 2 Filter),Location Code=FIELD(Location Filter),Drop Shipment=FIELD(Drop Shipment Filter),Build Kit=FIELD(Build Kit Filter),Variant Code=FIELD(Variant Filter),Shipment Date=FIELD(Date Filter)))

    Hope this makes sense?

    Nev

  • rpg Profile Picture
    rpg 85 on at
    RE: Rookie needs help

    thank you for your reply, now I feel better that I'm not losing my mind :-) This computed field concept is not new in the database world, it simply is better documented allowing reverse engineering. I think I found where the "inventory" flow field is calculated - on the item ledger table - Any idea how the "Quantity on PO" and "Quantity on Sales Order"  are calculated? If I'm right NAV appears to sum the rows in a table for these 3 fields (what an horrible concept that explains why we have such a poor performance database). Thank you in advance

  • Suggested answer
    Neville Foyn Profile Picture
    Neville Foyn 4,320 on at
    RE: Rookie needs help

    Hi

    You not loosing your mind as it is not there :)

    That is what is called a flow field in NAV, it is an always up to date field containing the totals from a sub table, these totals are stored in the tables at the top of the list in SQL with the numbers in the table name (For this reason you should never update records in SQL for a NAV system or all sorts of things break)

    The number in the table name is actually the table number that it is holding these sums for so if you look for 32, then for the key of the record from NAV you will see the set of field totals

    I haven't looked at it in a while as the way that works changes in NAV 2009 and up but if you look at the record in NAV then compare the numbers to that table you can figure out how it fits together,

    My suggestion though, don't use that table, rather see how NAV calculates that amount and just add it up yourself in your SQL Query, in the long run it will give you less grey hairs

    Hope this helps

    Nev

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans