Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

need to use an unix environment variable in my DATABASE statement

need to use an unix environment variable in my DATABASE statement

need to use an unix environment variable in my DATABASE statement

Can I use an environment variable, such as DBASE1, as my database name in a 4gl program?  I can get the environment variable with fgl_getenv (let dbase = fgl_getenv("DBASE")), but cannot seem to use it.  I tried to prepare it in a variable like db_stmt = "DATABASE ",dbase CLIPPED, but cannot execute it because it is not a cursor.  Any ideas?

I would also need to do this for .per forms that are used by the 4gl program (at least I think I would have to)

RE: need to use an unix environment variable in my DATABASE statement

Most Informix 4GL programs and screen forms have the database name hard coded as the first executable statement.  (Yes, Informix 4GL is old technology and it's brain dead).  However, you can close the database and reopen it early in your MAIN function:


DATABASE standard


  DEFINE db_stmt CHAR(80)

  LET db_stmt = fgl_getenv("DBASE")
  DATABASE db_stmt
  IF sqlca.sqlcode <>  0
      DISPLAY "can not open database: ", db_stmt



In the above code, the program executes by getting the new database name, closing standard db, and opening the new database.  Now, the program can go about it's business with the new database.

In production, the standard database only has to exist and be readable.  It could be completely empty.

When I made a living as a 4GL programmer selling apps to other customers, my shop would develop in the standard database, and then name our customer's database something else using exactly this technique.  Of course, the customer's database had to be a copy of standard or the programs would fail.

On the customer's unix box, we always had a null copy of standard.

Screen forms were a different matter.  You really can not change the database name.  At the time, this wasn't a hard ship because we knew what the customer's database name.

What you can do is define the database as formonly:

database formonly

Of course, this would limit the form's functionality.  This forces you to define the variables with the form such as this:

f01    = formonly.jet_filter type char;

I can probably scare up an example of a screen form using database formonly.

Let me know if you have any questions.

RE: need to use an unix environment variable in my DATABASE statement

I tried the DATABASE db_name syntax before and it failed, but now it works.  I think it was because I did not close the initial database.  As for forms, yeah, I knew the formonly way, but that means altering allot of code.  I was hoping for an easier solution.  If the closed database and the new database are the same (I am using one for production and the other for testing) then the forms should be ok if I leave them alone.

Thanks for the help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close