Previous Next

CREATE ALIAS statement
Creates an alias for a database. Once an alias is created, it can be used in place of the database’s logical name.
Note:
Syntax 
 
CREATE ALIAS alias-string | value ( expression )
  FOR DATABASE logical-name-string | value ( expression )
  [ NO-ERROR ]
alias-string | value ( expression )
An unquoted string, quoted string, or CHARACTER expression that represents an alias for the database.
FOR DATABASE logical-name-string | value ( expression )
An unquoted string, quoted string, or CHARACTER expression that represents the logical name of the database.
Note:
NO-ERROR
Tells the AVM to allow the alias to be created even if the database is not connected.
If you CREATE ALIAS for a database that is not connected and omit NO-ERROR, the AVM reports a run-time error.
Note:
Example 
This procedure creates the alias myalias for database mydb:
 
CREATE ALIAS myalias FOR DATABASE mydb NO-ERROR
Notes 
*
*
The first database connected that has an _menu file automatically receives the alias FTDB. You can reassign the FTDB alias to any other FAST TRACK database.
*
*
If there is an existing alias equal to alias, the existing alias is replaced by the new alias.
*
*
*
*
In a later session, when you want to use the precompiled program, you can connect to your database with the same logical name (MYNAME), or you can connect with a different logical name and set up an alias with the statement CREATE ALIAS “MYNAME” FOR DATABASE logical-name.
*
However, any file reference that is qualified with an alias (as opposed to a logical name) generates a new instance of the file for the compilation. This new instance causes the r‑code to have the alias reference and not the logical database name reference. Subsequent unqualified references to that same file within the same block, or nested blocks, will resolve to the new alias instance following the usual rules for qualifying. Unqualified references to different files in the same database do not get the alias name, but get the logical name. Anonymous references to a file, previously referenced using the alias qualifier, in a different, non‑nested block get the logical name instead of the alias name.
It is simpler to just connect to a database with the desired logical name, leave all references unqualified, not create an alias, and then compile the application. However, sometimes you cannot precompile. In those cases, if you want to compile a procedure so that only the alias gets into the r‑code file, then explicitly qualify all file references using the alias. You might want only the alias to get into the r‑code file, so you can compile and distribute procedures that will run against any database whose logical name has been assigned the alias contained in the r‑code file.
*
Changes made to an alias do not take effect within the current procedure. In the following example, alias1.p fails to compile when it reaches the FOR EACH statement, because alias myalias has been created during the compilation:
 
/* alias1.p */
/* NOTE: this code does NOT work */
CREATE ALIAS myalias FOR DATABASE sports2000.
 
FOR EACH myalias.Customer NO-LOCK:
  DISPLAY Customer.Name.
END.
To solve this problem, split r-alias1.p into two procedures. For example:
 
FOR EACH myalias.Customer NO-LOCK:
  DISPLAY Customer.Name.
END.
 
CREATE ALIAS myalias FOR DATABASE sports2000.
RUN r-dispnm.p.
CREATE ALIAS affects only subsequent compilations; currently executing procedures are not affected.
*
Once procedure r-main.p is run, it calls r-makebf.p, which calls r-disp6.p. The alias myalias is created in r-main.p, with reference to database sports2000. In r-makebf.p, the shared buffer mybuf is defined for myalias.customer. Then, in the next line, myalias is changed, so that it now refers to database sports2. When an attempt is made to reference shared buffer mybuf in procedure r-disp6.p, a run‑time error occurs, with the message: “r-disp6.p Unable to find shared buffer for mybuf.”
 
CREATE ALIAS myalias FOR DATABASE sports2000.
RUN r-makebf.p.
 
DEFINE NEW SHARED BUFFER mybuf FOR myalias.Customer.
 
CREATE ALIAS myalias FOR DATABASE sports2.
RUN r-disp6.p 
 
DEFINE SHARED BUFFER mybuf FOR myalias.Customer.
 
FOR EACH mybuf NO-LOCK:
  DISPLAY mybuf.
END.
*
See also 
ALIAS function, CONNECT statement, CONNECTED function, CREATE CALL statement, DATASERVERS function, DBCODEPAGE function, DBCOLLATION function, DBRESTRICTIONS function, DBTYPE function, DBVERSION function, DELETE ALIAS statement, DISCONNECT statement, DYNAMIC-CURRENT-VALUE function, DYNAMIC-NEXT-VALUE function, ERROR-STATUS system handle, FRAME-DB function, LDBNAME function, NUM-DBS function, PDBNAME function, SDBNAME function

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.