As a general rule, you should not compile procedures while using aliases. This potentially leads to confusion about what database name ends up in the r-code. For example, the OpenEdge dictionary programs which contain DICTDB as a qualifier must be compiled in a session where the database concerned has the logical name DICTDB. That way, when the dictionary r-code is run, it can run for any database name as long as the database uses the DICTDB alias. In summary, logical names are useful for compiling, aliases are useful at runtime.
However, you can still compile procedures using aliases. Suppose you have three databases called eastdb, centraldb, and westdb, all of which contain Customer tables with identical structure and time stamps or CRC values. Your application requires a general report procedure that can run against any of these Customer tables. To begin developing your general report procedure, start OpenEdge and connect to the eastdb, centraldb, or westdb database using the logical name myalias. Develop and compile the customer report procedure using myalias to prefix table and field references as shown in the previous procedure i-dispcust.p. All unqualified table and field references in the report procedure i-dispcust.p resolve to the myalias logical name at compilation time. When you finish compiling your procedure, disconnect from the database represented by the myalias logical database name.
You must assign an alias to the logical database name of a connected database prior to running any procedure that uses that alias as a database reference. Therefore, you need to develop a procedure that uses the CREATE ALIAS statement to assign the myalias alias to a logical database name and run the report procedure (i-dispcust.p) as a subprocedure. See the i-alias2.p procedure above.
Although it is not recommended because of the possible confusion it can cause, you may need to compile a procedure with an alias. To do this, you must know how OpenEdge places database references in the r-code of the procedure at compilation time. Remember, you must assign the alias to a logical database name prior to compiling the procedure. In general, use only the alias as a database prefix for all table and field references in the general-purpose procedures, and always fully qualify every database reference within such a procedure. Use the following syntax:
Syntax
alias.table-name alias.table-name.field-name
If you use this syntax for every table or field reference in your procedure, only the alias will be represented as the database reference in the procedure's r-code after compilation. Note that this is the only exception to the rule that you should never compile using aliases.
Unqualified table and field references within procedures may cause both the alias and the logical database name for a particular physical database to be represented in the r-code for the procedure at compilation time.