contents.gifindex.gifprev1.gifnext1.gif

7.3.6 Name Directive

The NAME directive assigns a database field name to the field defined on the next line.

Syntax

$XFD NAME=fieldname

or
*(( XFD NAME=fieldname ))

This directive has several uses, as shown in the following examples.

Example 1

Within AcuODBC's "virtual" database file, all field names must be unique. (Multiple database tables may include the same field name, but duplicates may not exist within a single table.) Unique field names are not required in COBOL, because names can be qualified by group items. For example, this is acceptable in COBOL:

01 employee-record.
 03 date-hired.
  05 yy pic 99.
  05 mm pic 99.
  05 dd pic 99.
 03 date-last-paid.
  05 yy pic 99.
  05 mm pic 99.
  05 dd pic 99.
You need not change the field names in your COBOL program to make them accessible by SQL. Instead, you use the NAME directive to provide unique names for the fields. For example:

 01 employee-record.
 03 date-hired.
  05 yy pic 99.
  05 mm pic 99.
  05 dd pic 99.
 03 date-last-paid.
*(( xfd  name=year-paid ))
  05 yy pic 99.
$xfd  name=month-paid
  05 mm pic 99.
$xfd  name=day-paid
  05 dd pic 99.
The "dates" portion of the "virtual" database table will look like this:

yy
mm
dd
year_paid
month_paid
day_paid
88
02
15
94
04
30

Example 2

If you have names that are identical within the first 18 characters, or that would not be meaningful if shortened to the first 18 characters, use the NAME directive to assign them different database field names. Suppose you had:

01 acme-employee-record.
 03 acme-employee-record-date-hired

pic x(6). 03 acme-employee-record-date-last-paid
pic x(6).
You could add two NAME directives to differentiate the two item names by making them meaningful within 18 characters:

01 acme-employee-record.
$xfd name=date-hired
03 acme-employee-record-date-hired
pic x(6).
$xfd name=date-last-paid
03 acme-employee-record-date-last-paid
pic x(6).

Note that your COBOL names have not changed. The new names are used only for the "virtual" database fields.

Each time you compile your program and specify "-Fx" to create data dictionaries, any field names longer than 18 characters will be checked for uniqueness within the first 18. If any field names are identical for the first 18 characters, a compiler error message will be issued. An error of this type does not prevent the program from compiling, but does prevent the data dictionary from being generated for the file with the duplicate names.

Example 3

You may want to use the NAME directive to assign shorter names than those used in your COBOL programs. This makes the formation of interactive SQL queries easier and quicker. For example:

*(( XFD  NAME=EMPNO ))
 03 employee-number pic x(8).
This directive causes the data dictionary to map EMPLOYEE-NUMBER to EMPNO in the database.

Example 4

If a field name in your Windows application does not match the name used in your COBOL FD, you can use a NAME directive to associate the two names. For example:

$xfd  name=employee-no
 03 employee-number pic x(8).
This directive causes the data dictionary to map EMPLOYEE-NUMBER in the COBOL program to EMPLOYEE-NO in the Windows application.

Example 5

If your COBOL program uses field names that begin with a numeric character, use the NAME directive to assign a different name for use with your Windows applications. SQL will typically generate a syntax error when it encounters a column name that begins with a numeric character. For example:

03 12-months-sales  pic
  9(5)V99.
could be renamed this way:

$xfd  name=twelve-months-sales
 03 12-months-sales  pic 9(5)V99.