use of setrange ?

mdsr
Member Posts: 163
Hi all, i am very confuse by seeing use of SETRANGE
1)PurchHeader.SETRANGE("No.","No.");//same field of record variable twice.
2)DefermentBuffer.SETRANGE("Document No.","No.");//different field one from record variable and one from purchase header table which is source table for page
why so what happening in two cases
any suggession apriciated.
1)PurchHeader.SETRANGE("No.","No.");//same field of record variable twice.
2)DefermentBuffer.SETRANGE("Document No.","No.");//different field one from record variable and one from purchase header table which is source table for page
why so what happening in two cases
any suggession apriciated.
0
Answers
-
Hi look at it this way:
With AnyOtherPurchHeaderRecordVar do begin
PurchHeader.SETRANGE("No.","No.");
DefermentBuffer.SETRANGE("Document No.","No.");
end;
Hope it makes more sense now0 -
The first parameter to SETRANGE is a reference to the field you want to filter, The second parameter is a value, giving the start (lower bound) of the range. The third parameter is a value giving the upper bound.
If the third parameter is missing, this sets the filter Field=Value. If even the second parameter is missing, the statement removes any filter from the field.0 -
The first parameter of SETRANGE defines which field you want to filter on.
The second one defines the value.
In both your examples the variabel scope is everything. Either the lines are within a WITH block like TallyHo suggests or a "main" table is already specified (that can be done as a global property on i.e. CodeUnits or if the code is on a table, the table is the "main" table.
So if the code you are looking at have - let's say Customer as either the "main" table or defined in a WITH block, this is actually the code being executed (not that this example makes a lot of sense :-), this is just to make it easier for you to understand ):
1)PurchHeader.SETRANGE(PurchHeader."No.",Customer."No.");
2)DefermentBuffer.SETRANGE(DefermentBuffer."Document No.",Customer."No.")
Hope this makes more sense for you...0 -
when to use same field and when to use different field if only two parameter are there in setrange?
0 -
Hi mdsr,
you obviously still have no clue what SETRANGE does in the first place (or no understanding of the C/AL programming language).- Have you read my explanation above? What did you not understand?
- Have you read lynge's explanation above? What did you not understand?
- Have you read the official help topic? What did you not understand?
The answer to your question is: When the value you want to filter with is stored in a field with the same name as the field you want to set the filter to.
Note that in the example PurchHeader.SETRANGE("No.","No."), the first parameter is a field in record PurchHeader. The second parameter might be a variable or might be a field of some (probably different) record, depending on the context, in which the statement stands.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