sort order in a table.

karuchua
Member Posts: 151
how can get the first record in a table or the last for a set of records.
for example in the purchase line table,i want for every document number,just get the first line.
the code below only gives the first record for all the records in the table.
setcurrentkey(Document Type,Document No.,Line No.);
setrange(document type,document type::order);
setrange(document no,document no);
if "purchase line" .findfirst then begin
GitemNo=purchase line.No.
end
for example in the purchase line table,i want for every document number,just get the first line.
the code below only gives the first record for all the records in the table.
setcurrentkey(Document Type,Document No.,Line No.);
setrange(document type,document type::order);
setrange(document no,document no);
if "purchase line" .findfirst then begin
GitemNo=purchase line.No.
end
0
Comments
-
So your code uses FINDFIRST. There is also FIND, FINDLAST & FINDSET:
details here:
FINDFIRST: http://msdn.microsoft.com/en-us/library/dd338835.aspx
FINDLAST: http://msdn.microsoft.com/en-us/library/dd338877.aspx
FINDSET: http://msdn.microsoft.com/en-us/library/dd301434.aspx
FIND: http://msdn.microsoft.com/en-us/library/dd301096.aspx
Are you saying the code is working for you but it's not doing it for each new doc number?
what exactly is the issue?0 -
Now, if you want find the first item number of each PO then I would use the Purchase Header Table as your dataitem. That way on each OnAfterGetRecord it gives you a new PO. Then you can use that data to filter your purchase Line table. Here's a sample report....
OBJECT Report 50023 Test Report { OBJECT-PROPERTIES { Date=10/24/12; Time=12:16:03 PM; Modified=Yes; Version List=MIBUSO Sample; } PROPERTIES { } DATAITEMS { { PROPERTIES { DataItemTable=Table38; OnAfterGetRecord=BEGIN PurchLine.SETRANGE("Document Type","Document Type"); PurchLine.SETRANGE("Document No.","No."); PurchLine.SETRANGE(Type,PurchLine.Type::Item); IF PurchLine.FIND('-') THEN BEGIN PL_DocNo := PurchLine."Document No."; PL_ItemNo := PurchLine."No."; END ELSE BEGIN CurrReport.SKIP; END; END; } SECTIONS { { PROPERTIES { SectionType=Header; PrintOnEveryPage=Yes; SectionWidth=18150; SectionHeight=1269; } CONTROLS { { 1000000002;TextBox;15000;0 ;3150 ;423 ;HorzAlign=Right; SourceExpr=FORMAT(TODAY,0,4) } { 1000000003;TextBox;0 ;0 ;7500 ;423 ;SourceExpr=COMPANYNAME } { 1000000004;TextBox;17700;423 ;450 ;423 ;CaptionML=ENU=Page; SourceExpr=CurrReport.PAGENO } { 1000000005;Label ;16950;423 ;750 ;423 ;ParentControl=1000000004 } { 1000000006;TextBox;15900;846 ;2250 ;423 ;HorzAlign=Right; SourceExpr=USERID } } } { PROPERTIES { SectionType=Body; SectionWidth=18150; SectionHeight=423; } CONTROLS { { 1000000000;TextBox;150 ;0 ;3600 ;423 ;SourceExpr=PL_DocNo } { 1000000001;TextBox;4350 ;0 ;3450 ;423 ;SourceExpr=PL_ItemNo } } } } } } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { VAR PurchLine@1000000000 : Record 39; PL_DocNo@1000000001 : Code[20]; PL_ItemNo@1000000002 : Code[20]; BEGIN END. } }
It finds the first line and the report shows the doc no & item no.
Adjust it to show whatever fields you need.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