|
I'm just starting my day and not really awake but ... it seems to me this is not a valid approach Dan.
By doing this you are including the two byte binary length of the varchar in the string to be hashed. So if you compared the hash value of (say) 'ABC' with the hashed value of 'ABC' made on another platform (or in the IBM i by a different piece of code) they will not match because including the count would not be normal practice.
Perhaps even more importantly you are not passing the correct length unless you are adding 2 to the %Len of the varchar. As a result the hash of '123' would be the same as the hash of '199' because what you are actually hashing by using a length of three is X'0003F1' whereas you should be hashing X'F1F2F3' and X'F1F9F9'.
To use a varchar with this API probably the best approach is probably to change the proto to use a pointer passed by value for the hash string and then pass %Addr(varchar: *Data).
As I say it is early in the day and I haven't tested this so ....
P.S. I would not recommend using Const to fix this as it will cause a copy of the data to be made and with such a large variable that will be slow if a lot of calls are made.
Jon Paris
www.partner400.com
www.SystemiDeveloper.com
On Mar 30, 2018, at 1:28 AM, Dan<dan27649@xxxxxxxxx> wrote:
Thanks Mark!
I changed the first parm in the prototype to varchar and now it works like
a charm.
On the inputlen statement, I simply got rid of the %trim altogether, since
DateToHash is varchar.
- Dan
On Fri, Mar 30, 2018 at 12:56 AM, mlazarus<mlazarus@xxxxxxxxxxxx> wrote:
Dan,
You're passing a varying character field to a fixed length parm, as
defined in the prototype. Options(*varsize) allows you to pass differently
sized variables of the same type, in this case it would be a fixed length
field, without the compiler complaining. An easy fix would be to add Const
to the prototype. Then the compiler would adjust it for you. Or make the
parm in the prototype varying (varchar).
Just a note on the other part of the code. This statement:
inputlen = %len(%trim( DataToHash));
gets the length of the fully trimmed variable, yet you're passing an
untrimmed version:
hash( DataToHash: inputlen );
So if you have leading blanks you'll get the hash based on a value with
leading blanks, but ignoring the trailing characters, for the number of
leading blanks. You're probably looking for %TrimR() instead of %Trim().
-mark
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.