By Barry Milam
A frequently asked question by AVR programmers is how to perform runtime overrides (ala OVRDBF). This is a very easy operation to perform with AVR. You can override the file or its member and you can even override the entire database name. This article takes a look at both operations.
To perform overrides, both the DclDB and DclDIskFile objects have properties that can be changed at runtime. To understand how these overrides work, let’s first consider the basic code skeleton shown below in Figure 1. The code below declares a DB connection and a disk file. Notice that the file is declared with ImpOpen(*NO)—the program will need to explicitly open the file. This is an important requirement for using file overrides; you can’t perform file overrides on a file opened implicitly.
Note also that the DclDiskFile object’s File() keyword must be a literal. Remember that file overrides occur at runtime. At compile time, the library and file name provided with the File() key must be provided as a literal. By default, the program stub below expects to connect to the file CMastNewL2 in the Examples library.
Figure 1. Basic program skeleton
0001 DclDB pgmDB DBName( "*Public/DG Net Local" ) 0002 0003 DclDiskFile Cust + 0004 Type( *Input ) + 0005 Org( *Indexed ) + 0006 Prefix( Cust_ ) + 0007 File( "Examples/CMastNewL2" ) + 0008 DB( pgmDB ) + 0009 ImpOpen( *No ) 0010 0011 BegSr Form1_Load Access(*Private) + 0012 Event(*This.Load) 0013 DclSrParm sender *Object 0014 DclSrParm e System.EventArgs 0015 0016 Connect pgmDB 0017 Open Cust 0018 EndSr 0019 0020 BegSr Form1_FormClosing Access(*Private) + 0021 Event(*This.FormClosing) 0022 DclSrParm sender Type(*Object) 0023 DclSrParm e Type(FormClosingEventArgs) 0024 0025 Close Cust 0026 Disconnect pgmDB 0027 EndSr
To perform a runtime file override with AVR, you provide the library and file to which you’re overriding with the DclDiskFile’s FilePath property. It’s very important to set this property before you open the file. The code below in Figure 2 shows the FilePath property being changed.
Figure 2. Overriding
the library and file.
0001 BegSr Form1_Load Access(*Private) + 0002 Event(*This.Load) 0003 DclSrParm sender *Object 0004 DclSrParm e System.EventArgs 0005 0006 Connect pgmDB 0007 0008 Cust.FilePath = "Prod/Myfile" 0009 Open Cust 0010 EndSr
By default, a file is opened using its first member. If a file has multiple members, you can override the DclDiskFile’s MemberName property has shown below in Figure 3. This code changes the active member to be “SL2000” when the file is opened.
Figure 3. Overriding a file member
0001 BegSr Form1_Load Access(*Private) + 0002 Event(*This.Load) 0003 DclSrParm sender *Object 0004 DclSrParm e System.EventArgs 0005 0006 Connect pgmDB 0007 0008 Cust.MemberName = "SL2000" 0009 Open Cust 0010 EndSr
Just like when overriding the library and file, overriding the member name, the file must be opened after you’ve set the MemberName property. You can use the FilePath and Member properties together to change both the file and its member.
You can also override the DB name. This would redirect your application to a different database name at runtime. The code below in Figure 4 shows a DB override:
0001 BegSr Form1_Load Access(*Private) + 0002 Event(*This.Load) 0003 DclSrParm sender *Object 0004 DclSrParm e System.EventArgs 0005 0006 pgmDB.DBName = "*Public/MyDBName" 0007 Connect pgmDB 0008 0009 Open Cust 0010 EndSr
This code causes the program to connect to the database name “*Public/MyDBName.” You can (and probably would) also provide file-level overrides in this situation. If you didn’t, the program would expect to find the same libraries and files in the overridden database name as existed in the original database name.

Comments