6
U U s s i i n n g g A A l l i i a a s s e e s s f f o o r r M M u u l l t t i i p p l l e e M M e e m m b b e e r r F F i i l l e e s s Craig Pelkie Bits & Bytes Programming, Inc. [email protected]

Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

Embed Size (px)

Citation preview

Page 1: Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

UUssiinngg AAlliiaasseess ffoorr MMuullttiippllee MMeemmbbeerr FFiilleess

Craig Pelkie Bits & Bytes Programming, Inc. [email protected]

Page 2: Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

Using Aliases for Multiple Member Files Edition ALIASES_20020219

Published by

Bits & Bytes Programming, Inc. Valley Center, CA 92082 [email protected]

Copyright © 2002, Craig Pelkie. All Rights Reserved

You are allowed to print copies of this document for your own personal use and for the use of others in your company or organization. Otherwise, no part of this document or any accompanying computer source code may be reproduced or distributed in any form or by any means, or stored in a database or data retrieval system, without the prior written permission of Craig Pelkie, who is the author of the document and the computer source code.

All computer source code distributed with this document, either on diskettes, CD-ROM, or available for downloading from sources such as the Internet is Copyright © 2002 Craig Pelkie, All Rights Reserved. The source code is for use in computer programs that you develop for internal use within your company, or for use within programs that you develop for the use of your clients. No part of the computer source code distributed with this document shall be reproduced in source code format, either printed or in electronic format, by you or by others who you allow to have access to the source code. You shall not cause the source code to be stored on any information retrieval system, such as the Internet. You shall not develop any written articles, books, seminar materials, or other presentations that include the source code provided on the diskettes accompanying this document or within the document itself.

For any questions regarding your rights and responsibilities using the computer source code distributed with this document, contact Craig Pelkie, Bits & Bytes Programming, Inc., who is the owner of the source code.

LIMITATION OF LIABILITY AND DISCLAIMER OF WARRANTY

No representation is made that any of the techniques, programs, computer source code, commands, or configurations described and depicted in this document and on the computer source code accompanying this document are error-free and suitable for any application that you may develop. Craig Pelkie makes no warranty of any kind, expressed or implied, including the warranties of merchantability or fitness for a particular purpose, with regard to the information, examples, and computer source code presented in this document and on the accompanying diskettes. Everything provided in this document and on the accompanying computer source code, if any, is provided “as is”. Craig Pelkie shall not be liable in any event for incidental or consequential damages or any other claims, pursuant to your use of any of the techniques presented in this document, or your use of the computer source code, even if Craig Pelkie has been advised of the possibility of such damages.

You are responsible for testing any and all programs, configurations, commands, and procedures described in this document prior to using the programs, configurations, commands, and procedures with important user data. You must ensure that adequate and sufficient backup of important user data is available, in the event that recovery of the important user data is required.

Page 3: Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

Using Aliases for Multiple Member Files

Copyright © 2002, Craig Pelkie, ALL RIGHTS RESERVED

1

Using Aliases for Multiple Member Files One of the problems of legacy AS/400 database applications is that database files frequently contain multiple members. For traditional application programs run on the AS/400, accessing a specific member is no great problem, since you can use the Override with Data Base File (OVRDBF) to point to the required member.

However, many new applications use SQL statements to access database files. For example, client/server applications may use ODBC, and Web applications may be created with Net.Data or JDBC, which use SQL statements to query data. SQL statements do not provide any options to access a specific database file member. Although there are some programming work-arounds that let you access a specific member, the techniques involved are usually cumbersome to implement.

If you have the DB2 Query Manager and SQL Developer’s Kit for AS/400 (Licensed Program Product 5769-ST1) installed on your AS/400, you can use the CREATE ALIAS SQL statement to create an alias to the database file for a particular member. You can then refer to the alias name in your SQL statements, rather than the name of the database file itself. Any queries are then performed against the specific member.

No SQL Developer’s Kit? If you don’t have the SQL Developer’s Kit, you can use a feature in AS/400 Operations Navigator to create aliases for your multiple member database files. To use this technique, navigate to the Database branch, then Libraries, then select the name of the library that contains the database file you need to work with (see Figure 1). The list of libraries displayed in Operations Navigator includes your current library and libraries in the user portion of the library list. If you need access to another library, right-click the Libraries branch, click the Select Libraries to Display item from the pop-up menu, then add the library to the list shown in Operations Navigator.

ALIAS01

Figure 1: Select the Create Alias item from the pop-up menu to start creating an alias to a database file member.

Page 4: Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

Using Aliases for Multiple Member Files

Copyright © 2002, Craig Pelkie, ALL RIGHTS RESERVED

2

Once in the library, follow these steps:

1. Navigate to the multiple member database file on the right side of the Operations Navigator.

2. Right-click the database file name and click Create Alias from the pop-up menu, as shown in Figure 1. Operations Navigator displays the Create Alias dialog (Figure 2).

3. Enter an alias name up to 118 characters long and the name of the library where the alias will reside. The Description is used as the text description for the object.

ALIAS02

Figure 2: Enter the name of the alias and the library where it will be located on the Create Alias dialog.

4. Click the Advanced button to go to the Create Alias – Advanced dialog, shown in Figure 3.

5. Select the option to create an alias for a member, then select the member name from the list of members.

6. Click the OK button twice to close the dialogs and return to Operations Navigator.

ALIAS03

Figure 3: Specify the member name that is used by the alias on the Advanced dialog.

Page 5: Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

Using Aliases for Multiple Member Files

Copyright © 2002, Craig Pelkie, ALL RIGHTS RESERVED

3

When done, the alias is displayed in the Operations Navigator (see the right frame of Figure 4, first item listed). If you assign an alias name greater than 10 characters, OS/400 assigns a 10 character object name to the alias. For example, the actual object name assigned to the alias in this example is QCUST00001.

How aliases are implemented on the AS/400 is not important. What is important is that you can now use the alias in an SQL statement. For example, you can now run the SQL statement

SELECT * FROM QCUSTCDT_MBR2 to process member MBR2 in file QCUSTCDT.

ALIAS04

Figure 4: The new alias is now displayed in AS/400 Operations Navigator.

Page 6: Using Aliases for Multiple Member Files - · PDF fileUsing Aliases for Multiple Member Files Edition ALIASES_20020219 Published by ... you can use the CREATE ALIAS SQL statement to

Using Aliases for Multiple Member Files

Copyright © 2002, Craig Pelkie, ALL RIGHTS RESERVED

4