Previous Topic: &NDBGET

Next Topic: &NDBOPEN


&NDBINFO

Retrieves information about an NDB database.

&NDBINFO dbname { DB | [ FIELD ] { NAME=fieldname | NUMBER=n } }
                [ FORMAT=formatname [ FSCOPE={ PROCESS | GLOBAL } ] ]
                [ FULL | SHORT ]

The &NDBINFO verb allows an NCL procedure to obtain information about an NDB, including information about the database itself, and information about the fields defined in it.

The information is returned in NCL variables.

Operands:

dbname

Specifies the name of the NDB that you wish to retrieve information about, and is a mandatory operand. The NDB must have been previously opened by an &NDBOPEN statement.

DB

Indicates that information about the database itself is to be returned. The information is returned in the following NCL variables:

[ FIELD ] NAME=fieldname

Indicates that information about the named field is to be returned. If the named field does not exist in the nominated NDB, then &NDBRC is set to 3. The information returned is listed below.

[ FIELD ] NUMBER=n

Specifies that information about relative field number n is to be returned. This number must be from 1 to the value returned by an &NDBINFO DB request in &NDBDBNFLDS. The information returned on the field requests is set into NCL variables as shown:

FORMAT=formatname [ FSCOPE={ PROCESS | GLOBAL } ]

FORMAT=formatname indicates that the format formatname, defined on the &NDBFMT statement, is to be used. The nominated format must exist in the nominated scope. PROCESS is the default, and indicates a format defined by the current NCL process. GLOBAL indicates that a format is to be found in the global format pool for the NDB.

If the format does not exist, a response code of 20 is returned. If the format exists, a set of variables is returned, as follows:

&NDBFMTUSAGE

Contains the value INPUT if this is an input format (that is, usable on an &NDBGET statement), or the value OUTPUT if this is an output format (for use with &NDBADD or &NDBUPD verbs).

&NDBFMT0

Contains the number of &NDBFMTn NCL variables returned.

&NDBFMT1 to &NDBFMTn

Contain strings of blank-separated values that describe either an individual field entry or a link to another record.

If the format is for input use, and the variable describes a return field, it is in the following format:

a b c d e f g h i

where:

  • a is the return NCL variable name.
  • b is the return format. If no editing was applied (justify, pad, and so on), this is the same as the database variable format (d). If editing was done, it is CHAR.
  • c is the name of the NDB field that the data is coming from.
  • d is the format of the NDB field: CHAR, NUM, HEX, DATE or FLOAT.
  • e is the format length requested. It is zero if not specified.
  • f is the format pad character. If not specified, or blank, or if the format length (e) is zero, the return value is a single dash character (-). Otherwise, it is the pad character quoted (for example, a per cent sign). If the pad character is a single quote, it is quoted using double quote characters.
  • g is the justify option—LEFT, CENTER, or RIGHT. If the format length (e) is zero, g is returned as a single dash (-).
  • h is the NULLFIELD return option—DELETE, NULLVAL, PAD, or NORETURN.
  • i is a single dash (-) at present (reserved for a possible date format option).

If the format is for input use, and the variable describes a link to another record, it is in the following format:

a b c d e f

where:

  • a is the literal .LINK, which is an invalid variable name, thus distinguishing this information from a variable description.
  • b is the ID value assigned to this link, or a single dash (-) if none was specified.
  • c is the from-ID value for this link, or a single dash if none was specified-meaning the from record is the primary retrieval record.
  • d is the from NDB field name.
  • e is the to NDB field name—it must be keyed.
  • f is the no find option—it is the word IGNORE or a number from 10 to 19.

If the format is for output use, it is in the following format:

a b c d

where:

  • a is the source NCL variable name from which data will be extracted.
  • b is the target NDB field name that will be set.
  • c is the target NDB field format (CHAR, and so on).
  • d is additional information—currently, *TEMP is always a dash.

The order of returned information in these variables agrees with the original format definition in that field for a specific record or link definition. However, the order of field description entries is not necessarily the same as the original format, as generic or range field specifications are expanded out and all fields are returned in internal ID order within a record or link.

FULL | SHORT

The FULL option requests that all information about the field be returned. The SHORT option requests that the only information that is obtained without reading the NDB be returned. The following fields are not returned:

Examples: &NDBINFO

The following example returns information about the NDB called MYNDB in NCL variables &NDBDB... (as described previously).

&NDBINFO MYNDB DB

The next example returns information about the field called 'SURNAME' in MYNDB. The returned information is in NCL variables &NDBFLD... (as described previously).

&NDBINFO MYNDB NAME=SURNAME

The following example returns information about all the fields defined in MYNDB.

&NDBINFO MYNDB DB
&I = 1
&DOWHILE &I LE &NDBDBNFLDS
   &NDBINFO MYNDB NUMBER=&I
   ... process field definition
   &I = &I + 1
&DOEND

Notes:

Errors encountered whilst processing the &NDBINFO statement may cause the procedure to terminate, or may just be reflected in the &NDBRC system variable, depending on the setting of &NDBCTL ERROR option.

The nominated NCL variables are not updated if a nonzero response is returned in &NDBRC (for example, named field not found).

The &NDBINFO statement makes it easy to write generalized NCL procedures to manipulate NDBs. The procedures can open any NDB and, by using &NDBINFO statements, build tables of control information for further processing.

In a similar way, a generalized database unload/reload utility is constructed.

Note: See also the NDB CREATE command description in the Online Help.

More information:

&NDBDEF