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



Hi Don,

VARYING means that the variable will start with two bytes that indicate the current length of data, followed by X number of bytes containing the actual data in the string.

Just to make sure the concept is clear, consider this code:

D MyString s 100a varying

Under the covers, the preceding line of code will have the EXACT SAME layout in the computer's memory as the following data structure:

D MyString ds
D len 5u 0
D data 100a

I.e., both of them are 102 bytes of memory, both of them start with a 2 byte length, and are followed by a fixed-length 100 character chunk of memory containing the data of the string. VARYING does *NOT* mean that the total amount of memory used is variable. A VARYING field always uses the same amount of memory. In my example, 102 bytes.

VARYING is equivalent to SQL's VARCHAR data type, or DDS's VARLEN.

So what's wrong with your code? Well, frankly, a lot of things. First of all, DON'T USE A POINTER THIS WAY. This is just asking for trouble. You pass a pointer by reference, then force it to always point to a 1A VARYING. What's the point? Are you allocating the memory for this pointer in the procedure? That's the only reason I can come up with why you'd want to do this.... but it doesn't appear that you do (if you do, you omitted that portion of the code.)

Instead, you pass a pointer by reference (which means your procedure can change the memory it points to) and then you do nothing with it but treat it as a 1A VARYING field. Just pass the 1A VARYING to begin with if that's what you really want.

But the most important thing is this: When you point the 1A VARYING at a spot in memory, you have to make DARNED sure that the spot in memory contains a 1A VARYING variable. Remember, 1A VARYING occupies THREE bytes of memory (not one) and the first two bytes contain the current length of the data. Since your variable is 1A, that means the first teo bytes MUST contain hex x'00000000' or x'00000001'. (Length of zero or one.) If it contains anything else you'll have a big problem because your field can ONLY store a length of one or zero, since it's a 1A field.

You state in your message that you sometimes get "Length of variable is out of range". That's the reason. Because those first two bytes MUST have hex values of zero or one. If they have anything else, you're going to have problems.

I'd recommend an alternative, but frankly I have no clue of what you're trying to accomplish here. This code doesn't make any sense that I can fathom... it makes no sense whatsoever.

I've read your other messages in this thread (as of 2:30pm CST) and I still can't make heads or tails of what you're trying to do.


Don Wereschuk wrote:
P FillArrayAll B
D FillArrayAll PI
D FieldToCheck *
D CheckValue 50A
D ArrayValue 50A
D*
DCheckField S 1A based(FieldToCheck) VARYING
[snip]

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.