Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Chapter 9 Understanding the Transfer process [Table of Contents] Chapter 11 Using
Destination-Template Transfer

Access Service User's Guide DirectConnect for AS/400

[-] Chapter 10 Using Bulk Copy Transfer

Chapter 10

Using Bulk Copy Transfer

This chapter describes the bulk copy transfer statement and covers the following topics:

All references to Adaptive Server 12.0 apply to SQL Server 11.1 and later, unless otherwise indicated.

General description of Bulk Copy Transfer

The bulk copy transfer process initiates a direct transfer of data between two databases from the client application. Bulk copy transfer allows you to:

When you use a bulk copy transfer statement, the following restrictions apply:

Syntax for Bulk Copy transfer statements

The required syntax for a bulk copy transfer statement is:

transfer [with report]
{to | from} 'secondaryname
userid password';
with {insert | replace | truncate} into tablename;
sourceselectstatement

where:

Examples

This section contains some examples of bulk copy transfer statement syntax that are submitted through ISQL. The following table shows the database and user information used in the examples.

Information used for bulk copy transfer examples

Transfer Components

Primary Database

Secondary Database

Database

AS/400

Adaptive Server

User ID

as4user

ssuser

Password

as4pass

sspass

Service Name

as4

ss

Table Names

as4table1, as4table2, as4table3

sstable1, sstable2,sstable3

Column Names

as4col1, as4col2, as4col3,...

sscol1, sscol2, sscol3,...

The following examples assume that the source and target databases are datatype-compatible.

Example #1

Task: Transfer data from the AS/400 to append to an Adaptive Server table.

c:>isql -Sas4 - Uas4user -Pas4pass
1>transfer to 'ss ssuser sspass' ;
2>with insert into sstable1 ;
3>select * from as4table3 ;
4>go

Result: Data from the AS/400 table named as4table3 is appended to the Adaptive Server table sstable1

Example #2

Task: Transfer data from Adaptive Server to replace data in the AS/400.

c:>isql -Sas4 -Uas4user -Pas4pass
1>transfer from 'ss ssuser sspass' ;
2>with replace into as4table1 ;
3>select * from sstable3 ;
4>go

Result: Data from the Adaptive Server table named sstable3 replaces the data in the AS/400 table as4table1.

Example #3

Task: Transfer data from two tables in the AS/400 to a single Adaptive Server table.

c:>isql -Sas4 -Uas4user -Pas4pass
1>transfer to 'ss ssuser sspass' ;
2>with insert into sstable1 ;
3>select a.ssno, a.name2, b.empid
4>from as4table1 a, as4table2 b
5>where a.ssno=b.ssno ;
6>go

Result: A social security number (ssno), a name (name2), and an ID (empid) are selected from two AS/400 tables, based on a join of social security numbers. The information is appended to the Adaptive Server table called sstable1.

How Bulk Copy transfer statements are processed

Bulk copy transfer processing occurs in the following sequence:

Guidelines for processing Bulk Copy values

To avoid errors in the bulk copy transfer process, review the following guidelines that apply to values.

Character datatypes

Character datatypes (CHAR, VARCHAR, TEXT) can be converted to any other datatype. Conversely, every datatype can be converted to character data. However, you must be sure the character string is convertible to the target datatype. For example, the character string "450" can be converted to a numeric datatype such as INTEGER or DECIMAL, but the character string "Hello" causes a value error going to a numeric datatype.

Numeric datatypes

Numeric datatypes can be converted to other numeric datatypes or to character datatypes. However, they cannot be converted to binary or date datatypes.

Additional guidelines are:

Date datatypes

Date datatypes can be converted to other date datatypes or to character strings. However, they cannot be converted to numeric or binary datatypes.

Binary datatypes

Binary datatypes can be converted to other binary datatypes and to character strings. However, they cannot be converted to numeric or date datatypes.

ASCII to EBCDIC translation does not occur if the source column, the destination column, or both are BINARY datatypes.

Datatype conversion for transfer from statements

Use transfer from when you want to transfer data from a secondary database, either Adaptive Server or another database through another access service, to the primary database. The primary database, the AS/400, is the target and is implied in the transfer statement; the secondary and source database is specified in the transfer statement.

The following figure shows the data flow of one of the preceding transfer from examples, which transfers data from sstable3 in Adaptive Server to replace data in the AS/400 table named as4table1.

Figure 10-1: AS/400 bulk copy transfer from statementraster

The access service performs datatype conversions for bulk copy transfer from statements. These conversions are defined within the access service and are not affected by the settings of the datatype conversion configuration properties. The access service converts these datatypes into the actual datatypes of the target columns. If the access service cannot convert the columns, an error occurs. For information about errors, see "Transfer errors and error handling" and "Errors from data values" .

The following table shows the acceptable Open Server datatypes that the access service can convert into corresponding AS/400 datatypes. To save space, the CS_ prefix is removed from Open Server datatypes, and similar AS/400 datatypes are combined.

Open Server to AS/400 datatype conversions for transfer processing

From Open Server Datatypes (below)

To AS/400 Datatypes (across)

CHAR,

VARCHAR

INT,

SMALLINT

DECIMAL,

FLOAT,

REAL

DATE,

TIME,

TIMESTAMP

CHAR FOR BIT, DATA,

VARCHAR FOR BIT DATA

CHARACTER DATATYPES

CHAR

X

X

X

X

X

VARCHAR

X

X

X

X

X

TEXT

X

X

X

X

X

BINARY DATATYPES

BINARY

X

X

VARBINARY

X

X

IMAGE

X

X

NUMERIC DATATYPES

BIT

X

X

X

SMALLINT

X

X

X

INTEGER

X

X

X

DECIMAL

X

X

X

MONEY

X

X

X

MONEY4

X

X

X

REAL

X

X

X

FLOAT

X

X

X

DATE DATATYPES

DATETIME

X

X

DATETIME4

X

X

Datatype conversion for transfer to statements

Use the transfer to statement when you want to move data to a secondary database from the primary database. When you execute a bulk copy transfer using transfer to, the secondary database is the target, and the primary database is the source. You can use another access service, an MDI Database Gateway, Open Server, or OmniConnect as the secondary database.

The following figure shows the data flow of one of the preceding transfer to examples, in which a social security number (ssno), a name (name2), and an ID (empid) are selected from two AS/400 tables. The information is appended to the Adaptive Server table called sstable1. The transfer is based on a join of social security numbers.

Figure 10-2: Data conversion for transfer to statementsraster

The access service performs datatype conversions for bulk copy transfer to statements. These conversions are defined within the access service and are not affected by the settings of the datatype conversion configuration properties. The access service converts these datatypes into the datatypes of the target Open Server columns. If a column does not match, the access service ends the transfer with an error.

The following table shows the AS/400 datatypes that the access service can convert into corresponding Open Server datatypes. To save space, theCS_ prefix is removed from the Open Server datatypes, and Open Server datatypes with the same results are combined.

AS/400 to Open Server datatype conversion for transfer processing

From AS/400 Datatype (below)

To Open Server Datatypes (across)

CHAR,

VARCHAR,

TEXT

BINARY,

VARBINARY

IMAGE

,

SMALLINT

INTEGER

DECIMAL

MONEY,

MONEY4

REAL,

FLOAT

DATE TIME,

DATETIME4

CHARACTER DATATYPES

CHAR

X

X

X

X

X

X

X

VARCHAR

X

X

X

X

X

X

X

NUMERIC DATATYPES

SMALLINT

X

X

X

X

X

INTEGER

X

X

X

X

X

DECIMAL

X

X

X

X

X

FLOAT

X

X

X

X

X

REAL

X

X

X

X

X

DATE DATATYPES

DATE

X

X

TIME

X

X

TIME STAMP

X

X

BINARY DATATYPES

CHAR FOR BIT DATA

X

X

VARCHAR FOR BIT DATA

X

X

Authorization for transfer to an Adaptive Server

When you execute a transfer to an Adaptive Server, you must have create procedure authorization on the tempdb database on Adaptive Server; otherwise, you receive the following error message:

create procedure permission denied, database tempdb, owner dbo

Because tempdb is the Adaptive Server standard temporary database where CT-Library implements dynamic prepare and execute, the System Administrator must grant create procedure authorization so users can execute transfer to statements to an Adaptive Server.

To grant create procedure permission to public:

Errors from data values

The following four tables show the values that cause errors for the access service during bulk copy transfer. These tables are divided into the four major groups of input datatypes:

Each table shows the output datatype and the kind of error that can occur.

Character datatype errors

This table uses the following as the source character datatypes:

The following table shows the errors that can occur when the access service converts the preceding character datatypes to those listed in the Open Server and AS/400 Output Datatype column.

In the Output Datatype column of the following four tables, the CS_ prefix is attached to the Open Server datatypes to distinguish them from AS/400 datatypes.

Conversion errors: character to output datatypes

Open Server and AS/400 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CS_TEXT CS_BINARY CS_VARBINARY CHAR VARCHAR

The source data is longer than the destination column.

CS_BIT

The source value cannot be converted to a number, or the resulting value does not equal 0 or 1.

CS_TINYINT

The source value cannot be converted to a number, or the resulting value is not between 0 and 255.

CS_SMALLINT SMALLINT

The source value cannot be converted to a number, or the resulting value is not between -32,768 and +32,767.

CS_INTEGER INTEGER

The source value cannot be converted to a number, or the resulting value is not between -2,147,483,648 and +2,147,483,647.

CS_DECIMAL DECIMAL

The source value cannot be converted to a number, or the number of digits to the left of the decimal point in the source exceeds the destination decimal's precision minus scale. Digits to the right of the decimal point that exceed the decimal's scale are truncated without error.

REAL FLOAT

The source value cannot be converted to a number, or the resulting value is one of the following:

  • Greater than 7.2E+75

  • Less than -7.2E+75

  • Greater than 0 and less than 5.4E-79

  • Less than 0 and greater than -5.4E-79

CS_REAL CS_FLOAT

The source value cannot be converted to a number, or it is out of range. Because the value range is machine-dependent, see the Adaptive Server documentation for your environment.

CS_MONEY

The source value cannot be converted to a number, or the resulting value is not between -922,337,203,685,477.5807 and +922,337,203,685,477.5807.

CS_MONEY4

The source value cannot be converted to a number, or the resulting value is not between -214,748.3647 and +214,748.3647.

CS_DATE

The source value is not an ISO format (YYYY-MM-DD) date or a valid Adaptive Server date/time string, or the resulting date has a year prior to 1753.

CS_DATETIME4

The source value is not an ISO format (YYYY-MM-DD) date or a valid Adaptive Server date/time string, or the resulting date is not between January 1, 1900, and June 6, 2079.

DATE TIME TIMESTAMP

The source value is not an ISO format date, time or timestamp, or a valid Adaptive Server date/time string.

Numeric datatype errors

This section uses the following as source numeric datatypes:

The following table shows the errors that can occur when the access service converts the preceding source numeric datatypes to those listed in the Open Server and AS/400 Output Datatype column.

Conversion errors: numeric types to output datatypes

Open Server and AS/400 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CHAR VARCHAR

The destination column is too small to hold the character string to express the value. For example, the source value is 102, and the destination column is CS_CHAR(2).

CS_BIT

The value does not equal 0 or 1.

CS_TINYINT

The value is not between 0 and 255.

CS_SMALLINT SMALLINT

The value is not between -32,768 and +32,767.

CS_INTEGER INTEGER

The value is not between -2,147,483,648 and +2,147,483,647.

CS_DECIMAL DECIMAL

The number of digits to the left of the decimal point in the source exceeds the precision minus scale of the destination decimal. Digits to the right of the decimal point that exceed the decimal's scale are truncated without error.

REAL FLOAT

The source value is one of the following:

  • Greater than 7.2E+75

  • Less than -7.2E+75

  • Greater than 0 and less than 5.4E-79

  • Less than 0 and greater than -5.4E-79

CS_REAL CS_FLOAT

The source value is out of range. Because the value range is machine-dependent, see the Adaptive Server documentation for your environment.

CS_MONEY

The value is not between -922,337,203,685,477.5807 and +922,337,203,685,477.5807.

Because the accuracy of a FLOAT value is 15 digits, a FLOAT value converted to CS_MONEY is accurate only to the nearest dollar.

Because the highest precision of a REAL value is 7 digits, a REAL value converted to CS_MONEY is accurate only to the nearest hundred million dollars.

CS_MONEY4

The value is not between -214,748.3647 and +214,748.3647.

Date datatype errors

This section uses the following as source date datatypes:

The following table shows the errors that can occur when the access service converts the preceding source date datatypes to those listed in the Open Server and AS/400 Output Datatype column.

Conversion errors: date types to output datatypes

Open Server and AS/400 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CS_TEXT CHAR VARCHAR

When converted into a character string, the date or time value is too long to fit into the destination column.

CS_DATE

The date has a year prior to 1753.

CS_DATETIME4

The date is not between January 1, 1900, and June 6, 2079.

Binary datatype errors

This section uses the following as source binary datatypes:

The following table shows the errors that can occur when the access service converts the preceding source binary datatypes to those listed in the Open Server and AS/400 Output Datatype column.

Conversion errors: binary to output datatypes

Open Server and AS/400 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CS_TEXT CS_BINARY CS_VARBINARY CS_IMAGE CHAR VARCHAR

The source data is longer than the destination column.


Chapter 9 Understanding the Transfer process [Table of Contents] Chapter 11 Using
Destination-Template Transfer