Using FieldRefs and RecordRefs vs. regular tables

Mike_HWG
Member Posts: 104
Hi all,
After a long time of ignoring them, I'm venturing into RecordRefs and FieldRefs. Unfortunately, they aren't impressing me... I think. Below I have two different versions of the same function. To me, the second version seems better, so why would I want to use RecordRefs/FieldRefs? Is it for when the data is far more ambiguous, rather than me knowing exactly what I want to get at?
Also, you'll notice that when using FIELD(), I just went with the hard-coded field numbers. I can switch to "Sales Invoice Line".FIELDNO(myfield), but then I'd need to declare that table as a variable... and by now I'm even that much closer to my version 2 code.
Just seems like refs are pointless :-k
Version 2:
After a long time of ignoring them, I'm venturing into RecordRefs and FieldRefs. Unfortunately, they aren't impressing me... I think. Below I have two different versions of the same function. To me, the second version seems better, so why would I want to use RecordRefs/FieldRefs? Is it for when the data is far more ambiguous, rather than me knowing exactly what I want to get at?
Also, you'll notice that when using FIELD(), I just went with the hard-coded field numbers. I can switch to "Sales Invoice Line".FIELDNO(myfield), but then I'd need to declare that table as a variable... and by now I'm even that much closer to my version 2 code.
Just seems like refs are pointless :-k
GetGPSalesDealsAdj(TableID : Integer;DocumentNo : Code[20];LineNo : Integer) : Decimal RR_Sales.OPEN(TableID); FR_DocumentNo := RR_Sales.FIELD(3); FR_LineNo := RR_Sales.FIELD(4); FR_DocumentNo.SETRANGE(DocumentNo); FR_LineNo.SETRANGE(LineNo); IF NOT RR_Sales.FINDFIRST THEN BEGIN RR_Sales.CLOSE; EXIT(0); END; IF TableID = DATABASE::"Posted Document Price Entry" THEN; FR_AmountIncludingVAT := RR_Sales.FIELD(30); FR_LineDealAmount := RR_Sales.FIELD(50025); AmountIncludingVAT := FR_AmountIncludingVAT.VALUE; LineDealAmount := FR_AmountIncludingVAT.VALUE; GPSalesDealsAdj := AmountIncludingVAT + LineDealAmount; WITH PostedDocPriceEntry DO BEGIN SETRANGE("Table ID",TableID); SETRANGE("Document No.",DocumentNo); SETRANGE("Document Line No.",LineNo); SETFILTER("Factor Type",'COST|ELEMENT'); IF FINDSET THEN BEGIN REPEAT GPSalesDealsAdj -= "Calculation Value"; UNTIL NEXT = 0; END; END; RR_Sales.CLOSE; EXIT(GPSalesDealsAdj);
Version 2:
GetGPSalesDealsAdj(TableID : Integer;DocumentNo : Code[20];LineNo : Integer) : Decimal CASE TableID OF DATABASE::"Sales Invoice Line": BEGIN SalesInvLine.GET(DocumentNo,LineNo); GPSalesDealsAdj := SalesInvLine."Amount Including VAT" + SalesInvLine."Line Deal Amount"; END; DATABASE::"Sales Cr.Memo Line": BEGIN SalesCrMemoLine.GET(DocumentNo,LineNo); GPSalesDealsAdj := SalesCrMemoLine."Amount Including VAT" + SalesCrMemoLine."Line Deal Amount"; END; END; WITH PostedDocPriceEntry DO BEGIN SETRANGE("Table ID",TableID); SETRANGE("Document No.",DocumentNo); SETRANGE("Document Line No.",LineNo); SETFILTER("Factor Type",'COST|ELEMENT'); IF FINDSET THEN BEGIN REPEAT GPSalesDealsAdj -= "Calculation Value"; UNTIL NEXT = 0; END; END; EXIT(GPSalesDealsAdj);
Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)
Systems Analyst
NAV 2009 R2 (6.00.34463)
0
Answers
-
It is just question of correct case to use RecordRefs. RecordRefs are good in situation,when you really do not know the structure - like Change Log. When logging the change, you do not know which fields are in the table. Replacing standard Record by RecordRef is really pointless and performance will not be good too.0
-
Recordrefs are too abstract to use them in everyday coding. But, sometimes they are absolutely necessary especially when you building something like import function. I would say, I found recordrefs useful, but very with limited scope of tasks.0
-
Thanks, that confirms my suspicions. :thumbsup:
I was hoping I had discovered a way to cut down some redundancy in my code. I come from an OOP background and I want to create generalized objects all too often :oops:Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)0
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