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



Hello,

    D ValFldNum       PI             1N
    D FldNme                          14A   CONST
    D FldVal                            20A   Options(*Varsize)
[SNIP]
    D FldIsNum        PR             1N
    D  String                            20A   Options(*Varsize)
[SNIP]
I expected that the field used by the FldIsNum procedure would contain
just the 5 bytes, but when I debug it, I actually get the 20 bytes
starting from the start of the HDR_KSAID field.

Yes, that's what options(*VARSIZE) does. IT disables the compiler's normal validity checking. Normally the compiler wouldn't let you pass a 5A field in place of a 20A field because when a parameter is passed by reference, all you really get is the address of the field. And the address tells the position of the computer's RAM where the field starts -- it doesn't tell the data type or length or anything else like that. So, if you have the field defined as 20A and it's in the same spot of memory as a 5A field, what happens? The first 5 bytes are valid. Everything else is what just happens to be in memory after those 5 bytes.

That's why the compiler stops you from passing it, because you'd otherwise be able to corrupt memory. Options(*VARSIZE) does nothing but disable that check.

In this case, I don't see why you'd need to be able to change the value of this field. It should be input only, since you're checking it for validity, you're not changing it. So, the parameter should be CONST.

If you want it to vary, I'd make it VARYING CONST. Granted, VARYING is a different data type, but since you specify CONST, the compiler will help you by converting it to the VARYING data type as needed. One of the nice things about converting fixed-length to VARYING in this manner is that the compiler will set the length of the VARYING field to be the same as the fixed-length field that you passed in.

Granted, it's slightly less efficient than using a fixed length field with options(*VARSIZE), but think about it.... it's 20 bytes. The speed it takes to copy 20 bytes is insignificant. In the lifetime of the program, I doubt that the total time you spend copying it will add up to the amount of time it took me to write this paragraph!

So, I guess this is what I'm suggesting you use for your prototypes:

     D ValFldNum       PI             1N
     D FldNme                        14A   CONST
     D FldVal                        20A   VARYING CONST

     D FldIsNum        PR             1N
     D  String                       20A   VARYING CONST

Then, you can get the length by doing %len(String) or %len(FldVal).

Tip: When a field doesn't need to be changed in a subprocedure, you should ALWAYS make it either CONST or VALUE. That helps make the subprocedure self-documenting, it makes it more flexible since the compiler will do field conversions for you, and allows expressions. It makes it easier to maintain because you know that the field won't be affected...


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.