Comparing two record variables

BeliasBelias Member Posts: 2,998
I don't know if it's risky, or if it's a known habit of you guys, but sometimes i want to compare two record varibales and see if they're the same (i mean, through code). i also noticed that FORMAT function works with record variables.
Is there something wrong (or is there a better way to do it) in doing this?
IF FORMAT(mytablevariable1) = FORMAT(mytablevariable2) then
  //record variables are pointing exactly to the same record
else
  //one or more field values are different
i think it is self documenting and smart, but i'm probably missing something...is it possible that nav does not have a function to compare two record variables? :-k
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog

Answers

  • jlandeenjlandeen Member Posts: 524
    I've thought of several ways to code that type of request and I haven't seen anything like a single function that compares all values in the fields.

    One thing I've seen done in the past is to use record ref variable and lookup the fields that are in the record and compare them. I think that's another way of comparing the records together....althought the format(recorda) = format(recordb) is probably just a good.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • kinekine Member Posts: 12,562
    It is good idea until the record is not too big to have more than 1000 chars when converted into text... ;-) Of course, using the recordref and fieldref to compare all fields is the clearest way.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jlandeenjlandeen Member Posts: 524
    gah....I always forget about the size limits of the text datatype in NAV!!! Although I guess 1024 is better than the 250 or whatever it used to be!
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • BeliasBelias Member Posts: 2,998
    yeah, the message text limit...it's something you know but you never think about :whistle: thanks!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • jlandeenjlandeen Member Posts: 524
    Yeah that only thing that has more room than a large text variable is a BLOB or BigText datatype and those wouldn't really be useful in this situation.

    If only we could have access to the 2Gb string data type like in C#/VS.Net!
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • DmytroYDmytroY Member Posts: 2
    Where did you get 1024 limitation? For Text variable 'no limits'
    "If no length is specified for text variables, the length is unlimited."
    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-object-specifications-limitations

    FORMAT(Rec) limitation : If, when the system formats Value, the result is a value larger than the maximum length MAXSTRLEN method (Code, Text) of String, a run-time error occurs.
    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-format-joker-integer-string-method

    But MAXSTRLEN(TextVariable) = 2,147,483,647.

    So, I compared:
    if Format(Rec) <> Format(xRec) then

    And it works on BC 16, OnPrem, AL extension.
  • TallyHoTallyHo Member Posts: 416
    @DmytroY
    You are addressing a 14 year old post.. a lot has changed.

Sign In or Register to comment.