Next Record

sabzam
Member Posts: 1,149
Dear All,
Let say we have the Gen. Journal line table with Document No. as current key and I would like to read the first record of every document No. What should I do?
For ex. let say we have three records 111 and two records 222. The current key is document No. I would like to read the first document 111 and after that the first document of 222. Can this be done?
Let say we have the Gen. Journal line table with Document No. as current key and I would like to read the first record of every document No. What should I do?
For ex. let say we have three records 111 and two records 222. The current key is document No. I would like to read the first document 111 and after that the first document of 222. Can this be done?
0
Comments
-
yes, you crate a variable called perviousDocNo
while you are looping you check
if (perviousDocNo <> '') and (perviousDocNo <> "Document No.") then begin
perviousDocNo := "Document No.";
end;0 -
You can also use a tempJournal variable
repeat tempJournal.setrange("Document No.","Document No."); if tempJournal.isempty then begin tempJournal := JournalLine; tempJournal.insert; end; until
0 -
Isn't there anything cleaner; sort of next primary key?0
-
The Temp record variable is very clean.
I don't think there is something cleaner (I'm guessing you mean something simpler)0 -
For SQL you could make a new View, and a new linked table in NAV. Then the C/AL code will be very simple, but maintaining different databases could be quite troublesome and you quickly end up having hundreds of different views. Unless you really need to optimize it for speed I wont use this method.
For Native you could optimize it like this:xx.SETCURRENTKEY("Document No."); IF xx.FIND('-') THEN REPEAT <insert your code here> xx.setrange("Document No.",xx."Document No."); xx.find('+'); xx.setrange("Document No."); UNTIL xx.NEXT = 0;
But never do this on SQL :-)Regards
Peter0 -
For Native you could optimize it like this:
xx.SETCURRENTKEY("Document No."); IF xx.FIND('-') THEN REPEAT <insert your code here> xx.setrange("Document No.",xx."Document No."); xx.find('+'); xx.setrange("Document No."); UNTIL xx.NEXT = 0;
But never do this on SQL :-)
1. Would there be any side-effect if you use just one xx instead of xx & xx2xx2.COPY(xx)
then applyxx2.SETRANGE("Document No.")
2. Would applying SETRANGE multiple times slow the iteration down a little? At least slower than looping through the filtered records once like what ara2n suggested?
Scott0 -
sabzam wrote:Isn't there anything cleaner; sort of next primary key?
Scott0 -
gumboots wrote:1. Would there be any side-effect if you use just one xx instead of xx & xx2gumboots wrote:2. Would applying SETRANGE multiple times slow the iteration down a little? At least slower than looping through the filtered records once like what ara2n suggested?
But I guess you are using SQL, but please confirm.
For SQL you should go for the suggestion by ara2n. Otherwise the SQL server has to make a new execution plan for each Next, which would kill the performance.Regards
Peter0 -
But I guess you are using SQL, but please confirm.
We actually use Native DB.0 -
gumboots wrote:We actually use Native DB.
I don't quite understand your suggestion about using two variables. Please try modifying my code and show it.Regards
Peter0 -
pdj wrote:
xx.SETCURRENTKEY("Document No."); IF xx.FIND('-') THEN REPEAT <insert your code here> xx.setrange("Document No.",xx."Document No."); xx.find('+'); xx.setrange("Document No."); UNTIL xx.NEXT = 0;
<insert your code here> :?: :?:
what is exactly my code ?
example i have 4 records EEEE 5 records FFFF and 3 records GGGG the result in the form must be 1 eeee 1 ffff and 1 GGGG ?0 -
valkatamake wrote:what is exactly my code ?
But since you need to read a table and "group" it by one or more fields I would guess you would like to do something with each of these "groups". So whatever you would like to do with the "group" should be put in this section.
But I have to repeat: Do never do like this on a SQL server...Regards
Peter0 -
Sorttemp.SETCURRENTKEY(Code);
IF FIND('-') THEN REPEAT //i'm using temp table
Sorttemp.INIT;
Sorttemp.COPY(Rec);
Sorttemp.INSERT;
UNTIL NEXT=0;
Sorttemp.SETFILTER(Code, :?: :?: :?: :?: ); //what i need to put there to filter one of a kind0 -
valkatamake wrote:Sorttemp.SETFILTER(Code, :?: :?: :?: :?: ); //what i need to put there to filter one of a kind0
-
DenSter wrote:You can't, there is no way in NAV to do what SQL Server calls 'SELECT DISTINCT'. The only way to do something lilke it is to loop through the table, keep track of unique ones and copy those into a temporary variable. Read back to Ara3n's first reply, and try it.Regards
Peter0 -
0
-
valkatamake wrote:check this please :roll:
Then you will have to store the records in a Temp table, and then show the temp table on the form. If you are using NAV5 or later you can use the SourceTableTemporary property. For older versions you could override the OnFind and OnNext triggers like form 344.
My suggestion would be something like this:OnOpenForm() xx.SETCURRENTKEY(Code); IF xx.FIND('-') THEN REPEAT TempXx := xx; TempXx.insert; xx.setrange(Code,xx.Code); xx.find('+'); xx.setrange(Code); UNTIL xx.NEXT = 0;
But never do this on SQL :-)Regards
Peter0 -
pdj wrote:DenSter wrote:You can't, there is no way in NAV to do what SQL Server calls 'SELECT DISTINCT'. The only way to do something lilke it is to loop through the table, keep track of unique ones and copy those into a temporary variable. Read back to Ara3n's first reply, and try it.0
-
I get a little bit concerned by threads like this one. Actually I started writing a rather long blog about it, but it all got too complex.
Writing code is not always the solution to a problem. Many times I fix problems simply by removing code.
In most cases where you need to find a complex code solution to a problem, maybe you need to take a step back and redesign the logic of what you are doing.
most likely you are just doing this all wrong. Maybe you need a Header table and consider your existing table as a lines table.
Either way, I don't think that this is a programming problem.David Singleton0 -
Check this out
xxtemp.SETCURRENTKEY(Code); IF FIND('-') THEN REPEAT xxtemp.RESET; xxtemp.SETRANGE(Code,Code); IF NOT Sorttemp.FIND('-') THEN BEGIN xxtemp.INIT; xxtemp.COPY(Rec); xxtemp.INSERT; END; UNTIL NEXT=0;
can you help me do this without temp table0 -
valkatamake wrote:Check this out ...
can you help me do this without temp table
Did you read my reply, or just chose to ignore it?David Singleton0 -
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