Search code examples
openedgeprogress-4glpreprocessor-directive

How to conditionally compile in case of an existing table?


I'm working with Progress-4GL, release 11.6, appBuilder and procedure editor.

I have just created a table, called "table_X", and I'm using it inside the code, something like:

FIND table_X ...

However, my program is general, but the table is custom-based (some customers have this table, but some don't).

So, I'd like to add a "preprocessor", something like:

&IFDEF table_X
&THEN FIND table_X ...
&END

Where the &IFDEF means: "Only compile this piece of code if that table exists in DB".

Is this possible in Progress-4GL, release 11.6?


Solution

  • If you are using static queries you will need to add a define in an environment include used when compiling. In your standard directory:

    // env.i
    
    // nothing (yet)
    

    And in your customer directory:

    // env.i
    
    &global define table_x
    

    Which you can then use at compile time with your propath, if your propath starts with the customer directory then the definition is picked up, otherwise env.i is taken from your standard directory and table_x is not defined:

    { env.i }
    
    &if defined( table_x ) &then
       find table_x no-lock.
    &endif
    

    If you can replace static use of this table with dynamic use, then you do not need the definitions and you can:

    def var hb as handle no-undo.
    
    create buffer hb for table "table_x" no-error.
    if valid-handle( hb ) then do:
       hb:find-unique( no-lock ).
    end.
    

    While this could be attractive, it does mean that you are burdening all your customers with potentially irrelevant run-time checks.