exists

whwar9739

Member
I am wondering if there is a simple way, in a preprocessor directive, to tell if a specific table exists or not.
Does anyone here have any ideas. Below is my initial thought.

Code:
&IF CAN-FIND(_file where _file._file-name = "xxx")
&THEN
    /* insert code here */
&ENDIF
 

whwar9739

Member
Tested my code above, this does not work. Turns out that can-find is not a valid function that can be used with a preprocessor directive.
Still looking for other options.
 

Stefan

Well-Known Member
The simple answer is no.

What you could do is generate an include file containing preprocessor definitions for all tables in the database. You would then only need to adjust the propath to point to the correct include.

Code:
OUTPUT TO "config1/tables.i".
FOR EACH _file WHERE _hidden = FALSE NO-LOCK:
   PUT UNFORMATTED "&GLOBAL-DEFINE DB-HAS-TABLE-" + _file._file-name SKIP.
END.
OUTPUT CLOSE.

You then add the correct config to your propath:

Code:
PROPATH = PROPATH + ",config1". /* or config2 or whatever */

You then include the file in your .p and check if the preprocessor is defined:

Code:
{ tables.i }
&IF DEFINED( DB-HAS-TABLE-XXX ) &THEN
   /* insert code here */
&ENDIF

Add the correct config to your propath before compiling for that config.

Another alternative could be to have an additional dummy database that does contain the table definitions missing from the main database but without data.

The real alternative is to use dynamic stuff.

Code:
DEF VAR hb AS HANDLE.

CREATE BUFFER hb FOR TABLE "xxx" NO-ERROR.
IF VALID-HANDLE( hb ) THEN DO:
   /* insert [B]dynamic[/B] code here */
END.
 
Top