AcuODBC User's Guide
6.3.7 NAME Directive
The NAME directive assigns a database field name to the data item defined on the next line. You can use the NAME directive to prevent duplicate field names.
or*(( XFD NAME=fieldname ))
This directive has several uses, as shown in the following examples.
Example 1 - duplicate names for data items in a single record
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:10 last_visit. 15 mm pic 99. 15 dd pic 99. 15 yy pic 99. 10 last_payment. 15 mm pic 99. 15 dd pic 99. 15 yy pic 99.
It is not, however, acceptable for a database to have a table with two columns with the same name. In fact, you will not be able to compile and generate a data dictionary with this source code in your program.
You need not change the field names in your COBOL program to make them accessible to your Windows application through ODBC. Instead, you use the NAME directive to provide unique names for the fields.
Although this is not included in the sample code, here is an example of using the NAME directive when you have duplicate field names:10 last_visit. 15 mm pic 99. 15 dd pic 99. 15 yy pic 99. 10 last_payment. $XFD NAME=MONTH_PD 15 mm pic 99. $XFD NAME=DAY_PD 15 dd pic 99. $XFD NAME=YEAR_PD 15 yy pic 99.
The "dates" portion of the "virtual" database table will look like this:
Example 2 - assigning shorter names
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:FILE SECTION. FD qa-file. $XFD COMMENT This is a sample file demonstrating directives. 01 qa-record. 03 animal-info. *(( XFD NAME=PATIENT )) 05 patient-id pic x(5). 05 atype pic x. 05 ctype redefines atype pic x. 05 dtype redefines atype pic x. 05 otype redefines atype pic x. 03 owner-info. 05 phone pic x(8). 05 owner pic x(30). 03 financial. 05 acct_no. 10 year pic x(2). 10 seq_no pic x(4). *(( XFD DATE=mmddyyyy, USE GROUP )) 05 last_visit. 10 mm pic 9(2). 10 dd pic 9(2). 10 yyyy pic 9(4). $XFD HIDDEN 05 fee pic s9(5)v99.
This directive causes the data dictionary to map PATIENT-ID to PATIENT in the database.
Here are some other places where you may consider using the NAME directive. In all of these instances, note that your COBOL data does not change. The new name appears only in the "virtual" database and in any tables that result from your COBOL code.
- If your COBOL data contains field names that are identical within the first 18 characters. Each time you compile your program and specify "-Fx" to create data dictionaries, any field names longer than 18 characters are checked for uniqueness within the first 18. 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.
- If you map COBOL data items to Windows applications. If a column 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.
- If a field name in your COBOL data begins with a numeric character. Because a Windows application communicates using SQL, the program typically generates a syntax error when it encounters a column name that begins with a numeric character. 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.
Voice: (800) 262-6585 (U.S.A. and Canada)
Voice: (858) 689-4500
Fax: (858) 689-4550
Please share your comments on this manual
or on any Acucorp documentation with the
Acucorp Communications Department.
|© 1988-2003 Acucorp, Inc.|
All rights reserved.