Tricks to find the Last PK

navuser1
Member Posts: 1,334
Sir,
The following Standard Code in NAV is occasionally used to find the LAST No. (read Last PK) of the targeted* table.
* in where the programme is going to INSERT the records.
May I know why does NAV use the First Line --"IF ItemLedgEntryNo = 0" in the beginning ?
What will be the problem if the mentioned is removed ?
Kindly reply.
Thanks.
The following Standard Code in NAV is occasionally used to find the LAST No. (read Last PK) of the targeted* table.
* in where the programme is going to INSERT the records.
IF ItemLedgEntryNo = 0 THEN BEGIN GlobalItemLedgEntry.LOCKTABLE; IF GlobalItemLedgEntry.FINDLAST THEN ItemLedgEntryNo := GlobalItemLedgEntry."Entry No."; END;
May I know why does NAV use the First Line --"IF ItemLedgEntryNo = 0" in the beginning ?
What will be the problem if the mentioned is removed ?
Kindly reply.
Thanks.
Now or Never
0
Comments
-
Well the PK could be populated somewhere before, so the Code is not necessary. It is always good to avoide LOCKTABLE.
If there is a problem if you remove it depends on the exact situation, and if it is somewhere in the posting process like Cu 22 it is hard to tell.
Anyway i see no reason to remove it in first place, bad idea imo.0 -
The reason for that line is performance, basically when posting multiple journal lines you only need to check for the last posted entry once and then you can simply increment for each journal line being posted. If you remove that line (and the corresponding END) then you won't break anything - it will still work correctly but it will just be a bit slower.0
-
Thanks for your reply.
Apart from your (Technical) opinions I have come to know the below function part also.
A LOCKTABLE in SQL Server does not lock anything. It's used to set the SET TRANSACTION ISOLATION LEVEL(SERIALIZABLE).
When we post a (Batch Posting) Item Journal Lines/Gen. Journal Lines, we all know that the posted entries(Item Ledger Entry & G/L Entry) are (should be) in Sequence in PK.
If we remove the mentioned line from the code then there is a possibility for the system to have a GAP in PK sequence.Now or Never0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions