use of setrange ?

mdsrmdsr 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.

Answers

  • TallyHoTallyHo Member Posts: 417
    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 now
  • vaprogvaprog Member Posts: 1,144
    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.
  • lyngelynge Member Posts: 85
    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...
  • mdsrmdsr Member Posts: 163
    when to use same field and when to use different field if only two parameter are there in setrange?
  • vaprogvaprog Member Posts: 1,144
    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.
Sign In or Register to comment.