× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jon,

1) If the field is Varying, contents are 12 long, and Const is used does the entire length get copied or just the 12 (+2 for the length) ?

2) In this case, since there is no expression being passed, wouldn't it just pass the pointer to the original variable and not make a copy? I know it's not guranteed, since the compiler can choose what it wants to do for Const, but I'm curious if that would be true here.

3) Dan - since DataToHash is Varying, there is no need for the second parm at all, since the Varying variable already contains the length, which is passed to your procedure.

-mark

On 3/30/2018 10:45 AM, Jon Paris wrote:
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 thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.