Re: Setting database at runtime with 4GL
Posted in 1995
> Subject: Setting database at runtime with 4GL > Date: Fri, 20 Jan 1995 17:34:29 +0000 > From: simonb@misslink.demon.co.uk (Simon Bunce) > Organization: Missing Link Systems > > Is it possible to choose which database to use from within a 4gl program? > > All our source files have a 'DATABASE abc' at the top. So, if we want to > use the same set of source on a different database, we need to change every > occurence of 'abc' to 'xyz' and recompile. Essentially, what we're looking > for is a way of choosing the database at run time. Is it possible? > [snip] > > Any advice gratefully received... > > =================================================== > Simon Bunce simonb@misslink.demon.co.uk > =================================================== Simon, My advice differs somewhat from the answers that you have received from other folks. First some background: A DATABASE statement at the top of a 4GL source is a declarative statement. A DATABASE statement *after* a MAIN or FUNCTION statement is an executable statement. The executable version may contain the dbname in a variable, but the declarative version may not. A declarative DB statement in a MAIN module automatically creates an implied executable statement. This is why you need to close your 'abc' database before opening your 'xyz' database, as reported by other posters. Now the advice: You only need the declarative DATABASE statement in your 4GL source if you use the syntax "DEFINE program_something LIKE db_something". If you do not use this form of DEFINE, then you do not need the declarative DATABASE statement. I write 98+% of my 4GL code without using declarative DATABASE statements. In general, I recommend against using the declarative form. Either the command line or environment variable method for specifying the database name, as described by other posters, may be used to provide the value of the variable used in the executable DATABASE statement. Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, SLS | / \\ alan@den.mmc.com | P.O. Box 179, M/S 3810 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\