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.
0
Answers
With AnyOtherPurchHeaderRecordVar do begin
PurchHeader.SETRANGE("No.","No.");
DefermentBuffer.SETRANGE("Document No.","No.");
end;
Hope it makes more sense now
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.
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...
you obviously still have no clue what SETRANGE does in the first place (or no understanding of the C/AL programming language).
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.