Database files and functions

When you create Unicode database applications, you need to consider the implications for creating physical files, creating logical files, and for database input/output.

Creating physical files

Unicode graphic fields can be created in physical files. This is done by specifying a G data type and a Unicode CCSID for the CCSID keyword.

The following example shows the DDS for a physical file containing four fields, and the command for creating the file:

A          R FMT1
A            EMPNO          6A
A            NAME          30G         CCSID(1200)
A            DESCR1       500G         CCSID(1200) VARLEN
A            DESCR2       500A
 
CRTPF FILE(UNICODEPF) SRCFILE(CLR/QDDSSRC)

In the example:

  • The first field, EMPNO, is a character field of length 6. The CCSID of the EMPNO field is the SBCS CCSID of the job. The decision was made to use a character field because the EMPNO field contains only numerics and Unicode support is not needed.
  • The NAME and DESCR1 fields are both Unicode fields. Both of these fields may need to contain data from more than one EBCDIC code page so the decision was made to make these fields Unicode graphic.
  • The DESCR2 field is the SBCS CCSID of the job. This field is used as illustration of mapping to a logical field in Creating logical files.

You can specify the default (DFT) keyword for Unicode graphic fields. The default value can be specified as SBCS, bracketed-DBCS, or bracketed-DBCS-graphic character strings. If you do not specify the DFT keyword, the default value for fixed-length Unicode fields is the Unicode blank (hexadecimal 0020). For varying-length Unicode fields, the default is the empty string.

Creating logical files

You can use logical files to map Unicode data to and from character, DBCS-open, or DBCS-graphic. This allows Unicode graphic data to be manipulated in a character based form.

The following example shows the DDS for a logical file containing 4 character fields. The Unicode graphic data is converted to character data when reading from the logical file, and character data is converted to Unicode graphic data when writing to the file.

R FMT1                      PFILE(UNICODEPF1)
A            EMPNO
A            NAME            A         CCSID(37)
A            DESCR1          A         CCSID(37)
A            DESCR2          G         CCSID(1200)

Database input/output

Whenever reading or writing data from or to a field tagged with a Unicode CCSID to the job physical files, the data is passed as Unicode data without any conversions occurring. Regardless of the job CCSID, data is passed as Unicode data. When writing data to a logical file, the from CCSID is the job CCSID; however, if the job CCSID is 65535, the from CCSID is the CCSID of the field in the logical file.

Here are some scenarios from the previous physical and logical files. For the scenarios, the job CCSID is 297.

Scenario 1. When reading the data from the physical file:

  • EMPNO is converted from its CCSID to 297.
  • NAME is not converted but is left as Unicode data.
  • DESCR1 is not converted but is left as Unicode data.
  • DESCR2 is converted from its CCSID to 297.

Scenario 2. When writing the data to the physical file:

  • EMPNO is converted from 297 to its CCSID.
  • NAME is not converted but is left as Unicode data.
  • DESCR1 is not converted but is left as Unicode data.
  • DESCR2 is converted from 297 to its CCSID.

Scenario 3. When reading the data from the logical file:

  • EMPNO is converted from its CCSID to 297.
  • NAME is converted from Unicode data to character data with a CCSID of 297.
  • DESCR1 is converted from Unicode data to character data with a CCSID of 297.
  • DESCR2 is converted from character data to Unicode data and not converted to the job CCSID.

Scenario 4. When writing the data to the logical file:

  • EMPNO is converted from 297 to its CCSID.
  • NAME is converted from 297 to Unicode data.
  • DESCR1 is converted from 297 to Unicode data.
  • DESCR2 is converted from Unicodeto its CCSID in the physical file.

Scenario 5. If the job was 65535, the conversions for the previous fields are:

  • EMPNO is not converted.
  • NAME is converted from 37 to Unicode data.
  • DESCR1 is converted from 37 to Unicode data.
  • DESCR2 is converted from Unicode to its CCSID in the physical file.