Static Class Static Variable Bug?

KMoody

Member
I want to make a constant available throughout my code, so I created a static customer_util class containing a static property.

Code:
USING Progress.Lang.*.

CLASS customer_util:

    DEFINE STATIC TEMP-TABLE tt_FAKE_CUSTOMER_NUM no-undo
        FIELD cust-num LIKE CUSTOMER.CUST-NUM.  

    DEFINE PUBLIC STATIC PROPERTY PROSPECT_CODE AS CHARACTER INITIAL 'HP' NO-UNDO
        GET.
    

    /*------------------------------------------------------------------------------
            Purpose:                                                                       
            Notes:                                                                       
    ------------------------------------------------------------------------------*/
       
    CONSTRUCTOR STATIC customer_util (  ):
       
        DEF VAR i AS INTEGER FORMAT "99" INIT 0.
       
        FIND FIRST tt_FAKE_CUSTOMER_NUM NO-LOCK NO-ERROR.
        IF NOT AVAILABLE tt_FAKE_CUSTOMER_NUM THEN
        DO:
            DO i = 1 TO 99:
                CREATE tt_FAKE_CUSTOMER_NUM.
                IF i < 10 THEN
                    tt_FAKE_CUSTOMER_NUM.cust-num = "    0" + STRING(i).
                ELSE
                    tt_FAKE_CUSTOMER_NUM.cust-num = "    " + STRING(i).
                /*            MESSAGE tt_FAKE_CUSTOMER_NUM.cust-num .*/
                RELEASE tt_FAKE_CUSTOMER_NUM.
            END.
        END.
       
    END CONSTRUCTOR.


END CLASS.

However, when I invoke PROSPECT_CODE in a FIND or FOR loop, I never find anything - even though I know I have records that meet my condition. Instead of a static property, I have to use a hard-coded value.

For example, this fails:
Code:
  FIND customer WHERE CUSTOMER.ACCT-STATUS ne customer_util:PROSPECT_CODE
            AND customer.cust-num = cust NO-LOCK NO-ERROR.
This does not:
Code:
  FIND customer WHERE CUSTOMER.ACCT-STATUS ne 'HP'
            AND customer.cust-num = cust NO-LOCK NO-ERROR.

Is there some static class subtlety that I'm missing? Is this a known bug?
 
Classes and user defined function references in WHERE clauses have a host of issues. Mostly related to only firing for the first record and/or firing in weird ways. PSC added startup parameters in OE10 and OE11 to force compiler errors when UDFs or classes are used in WHERE clauses because it just doesn't work like people think it should.

I don't know of an exact KB that explains your example but there are a few similar ones. Have you displayed customer_util:PROSPECT_CODE to make sure it is set when you think it is?
 
Yes, customer_util:pROSPECT_CODE displays as HP.

Why would using classes and functions in WHERE clauses cause problems?

Edit: Found my answer here. Still, I don't see why the Progress compiler should treat static variables differently than any other.
 
Last edited:
Okay, thanks for the links.

Do you know where I need to set the -noroutineinwhere and -noudfinwhere start-up parameters in Eclipse?
 
Not really an Eclipse fan but I assume it would be where you set the other client startup parameters. Maybe somebody else can chime in that actually uses Eclipse.
 
Setting startup parameters in Eclipse should be simple.
Just open properties of your project and there you can set properties for OpenEdge, including startup parameters.
 
I tried that, but I got an error saying "The -n parameter requires a numeric argument." I don't have a -n parameter. Is Eclipse misreading -noroutineinwhere and -noudfinwhere?
 
10.2B07. Sorry, I should have mentioned that before.

-noroutineinwhere was introduced in 11.0, so I think that was the source of my problem. I can use -noudfinwhere, though.
 
Back
Top