On 02 Nov 2012 15:54, Darryl Freinkel wrote:
I have not used this in a while and need to be able to create a SQL
alias on the fly.
I have a RPG SQL program that reads a file which contains the
library, file and member which I need to use and create a SQL ALIAS
with so that I can read this file.
Can someone help with how to do this in RPG?
If the information is known before the SQL [RPG or otherwise], an
OVRDBF request is much "lighter" than the "heavier" CREATE ALIAS; i.e.
the former is merely an entry added to an [effective] index that will
already exist for every job whereas the latter creates an external
object and a similar [effective] index entry for SQL tracking for QTEMP
or an entry as a database row for the catalog entry if not in QTEMP.
Because the SQL ALIAS is implemented as a permanent object
[irrespective of library], the request is /expensive/ when utilized in
an ad hoc "on the fly" manner. An ALIAS is best created [like most
other "objects"] to persist, to be utilized repeatedly rather than
created anew each time, thus incurring the costs of creation, assignment
of ownership and authority, and then deletion. Using QTEMP may be used
to delay the latter costs until the CLRLIB QTEMP for job termination,
but can neither delay nor avoid the former costs.
Then for example, instead of the statement referring to the ALIAS
name, have the statement refer to the "FILE" name that is overridden.
The two scenarios with a SELECT for example, showing how the statement
can remain [near] identical for both:
create alias myAlias for myLib/myDBF (myDBFmbr)
select ... FROM myAlias
/* myAlias library-qualified in either or both of the above */
/* drop alias; perhaps */
ovrdbf myOvrName tofile(myLib/MyDBF) mbr(myDBFmbr)
select ... FROM myOvrName
/* dltovr; perhaps */