DB2 10.5 for Linux, UNIX, and Windows

sqldcol data structure

This structure is used to pass variable column information to the db2Export, db2Import, and db2Load APIs.

Table 1. Fields in the SQLDCOL Structure
Field Name Data Type Description
DCOLMETH SMALLINT A character indicating the method to be used to select columns within the data file.
DCOLNUM SMALLINT The number of columns specified in the array DCOLNAME .
DCOLNAME Array An array of DCOLNUM sqldcoln structures.
The valid values for DCOLMETH (defined in sqlutil) are:
SQL_METH_N
Names. When importing or loading, use the column names provided via this structure to identify the data to import or load from the external file. The case of these column names must match the case of the corresponding names in the system catalogs. When exporting, use the column names provided via this structure as the column names in the output file.

The dcolnptr pointer of each element of the dcolname array points to an array of characters, of length dcolnlen bytes, that make up the name of a column to be imported or loaded. The dcolnum field, which must be positive, indicates the number of elements in the dcolname array.

This method is invalid if the external file does not contain column names (DEL or ASC format files, for example).

SQL_METH_P
Positions. When importing or loading, use starting column positions provided via this structure to identify the data to import or load from the external file. This method is not valid when exporting data.

The dcolnptr pointer of each element of the dcolname array is ignored, while the dcolnlen field contains a column position in the external file. The dcolnum field, which must be positive, indicates the number of elements in the dcolname array.

The lowest valid column position value is 1 (indicating the first column), and the highest valid value depends on the external file type. Positional selection is not valid for import of ASC files.

SQL_METH_L
Locations. When importing or loading, use starting and ending column positions provided via this structure to identify the data to import or load from the external file. This method is not valid when exporting data.

The dcolnptr field of the first element of the dcolname array points to an sqlloctab structure, which consists of an array of sqllocpair structures. The number of elements in this array is determined by the dcolnum field of the sqldcol structure, which must be positive. Each element in the array is a pair of 2-byte integers that indicate where the column begins and ends. The first element of each location pair is the byte within the file where the column begins, and the second element is the byte where the column ends. The first byte position within a row in the file is considered byte position 1. The columns can overlap.

SQL_METH_D
Default. When importing or loading DEL and IXF files, the first column of the file is loaded or imported into the first column of the table, and so on. When exporting, the default names are used for the columns in the external file.

The dcolnum and dcolname fields of the sqldcol structure are both ignored, and the columns from the external file are taken in their natural order.

A column from the external file can be used in the array more than once. It is not necessary to use every column from the external file.

Table 2. Fields in the SQLDCOLN Structure
Field Name Data Type Description
DCOLNLEN SMALLINT Length of the data pointed to by DCOLNPTR.
DCOLNPTR Pointer Pointer to a data element determined by DCOLMETH.
Note: The DCOLNLEN and DCOLNPTR fields are repeated for each column specified.
Table 3. Fields in the SQLLOCTAB Structure
Field Name Data Type Description
LOCPAIR Array An array of sqllocpair structures.
Table 4. Fields in the SQLLOCPAIR Structure
Field Name Data Type Description
BEGIN_LOC SMALLINT Starting position of the column data in the external file.
END_LOC SMALLINT Ending position of the column data in the external file.

API and data structure syntax

SQL_STRUCTURE sqldcol
{
   short dcolmeth;
   short dcolnum;
   struct sqldcoln dcolname[1];
};

SQL_STRUCTURE sqldcoln
{
   short dcolnlen;
   char *dcolnptr;
};

SQL_STRUCTURE sqlloctab
{
   struct sqllocpair locpair[1];
};

SQL_STRUCTURE sqllocpair
{
   short begin_loc;
   short end_loc;
};

COBOL Structure

* File: sqlutil.cbl
01 SQL-DCOLDATA.
    05 SQL-DCOLMETH           PIC S9(4) COMP-5.
    05 SQL-DCOLNUM            PIC S9(4) COMP-5.
    05 SQLDCOLN OCCURS 0 TO 255 TIMES DEPENDING ON SQL-DCOLNUM.
        10 SQL-DCOLNLEN       PIC S9(4) COMP-5.
        10 FILLER             PIC X(2).
        10 SQL-DCOLN-PTR      USAGE IS POINTER.
* 


* File: sqlutil.cbl
01 SQL-LOCTAB.
    05 SQL-LOC-PAIR OCCURS 1 TIMES.
        10 SQL-BEGIN-LOC      PIC S9(4) COMP-5.
        10 SQL-END-LOC        PIC S9(4) COMP-5.
*