TechTip: Easier DB2 for i Data Transfers with New Technology Refresh

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Using three-part names, Insert statements can now reference objects from more than one IBM i system.


The GA version of the DB2 for i 7.1 release simplified access to DB2 objects on remote systems by eliminating the need for explicit remote connections with the new three-part name support. Instead of developers having to use an extra CONNECT or SET CONNECTION statement to explicitly connect statement, they can now simply run an SQL statement like the following to retrieve data from a table on a different system or partition.

 

 

SELECT lastname, address, city FROM rmtsystem.datalib.customer

WHERE state='IA'

 

The SELECT statement in this example accesses a remote table with a three-part name value of rmtsystem.rmtschema.customers. The first part of the name is the remote database server name: rmtsystem. This value must correspond to an entry in the IBM i relational database directory entry that was added with the Add Relational Database Directory Entry (ADDRDBDIRE) command. The second component is the schema name, datalib, on the remote server. The final part of the three-part name is the name of the DB2 object, customer, on the remote server. Whenever an SQL statement references an object with a three-part name that resides on a different system, DB2 starts an implicit Distributed Relational Database Architecture (DRDA) connection to enable the DB2 object on the remote server to be accessed.

 

This initial support in 7.1 also included the ability to create an alias that points to a remote DB2 object. This provides functionality quite similar to a Distributed Data Management (DDM) file. The following set of SQL statements creates an alias and then uses the alias to retrieve data from the same remote customer table that was accessed in the previous example.

 

CREATE ALIAS datalib.customer FOR rmtsystem.datalib.customer

SELECT lastname, phone FROM datalib.customer

 

While this new 7.1 support was a great improvement, the functionality was limited by the fact that an SQL statement could only reference objects from a single IBM i system. The latest IBM i Technology Refresh for the 7.1 release lifts this restriction for INSERT statements to simplify data transfer operations involving three-part names. This new capability makes it easy for a table on your local system to be populated with data from another system, as the following INSERT statement demonstrates.

 

               INSERT INTO locallib.customers

SELECT lastname, address, city

       FROM rmtsystem.datalib.customer WHERE state='IA'

 

The embedded SELECT statement uses a three-part name to reference data on a remote system, and the result of that SELECT statement is inserted into the customer table on the local system. The SELECT statement also could reference an alias that points a remote DB2 object. This ability to transfer data directly into a table eliminates the need to first copy the data into some type of temporary staging area like a data structure or array.

 

Only IBM i 7.1 systems that have Level #14 of the Database Group PTF installed can run an INSERT statement that references DB2 objects from more than one system. The embedded SELECT statement can reference DB2 objects on IBM i systems that are running one of the following operating system versions: V5R4, 6.1, or 7.1.

Kent Milligan
Kent Milligan is a Senior Db2 for i Consultant in the IBM Lab Services Power Systems Delivery Practice.  Kent has over 25 years of experience as a Db2 for IBM i consultant and developer working out of the IBM Rochester lab. Prior to re-joining the DB2 for i Lab Services practice in 2020, Kent spent 5 years working on healthcare solutions powered by IBM Watson technologies. Kent is a sought-after speaker and author on Db2 for i & SQL topics.
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: