Before you can begin to work with FML fielded buffers, or use the VIEWS functions that move fields between structures and fielded buffers, certain details must be taken care of, such as:
Introduction
These and related activities are described in this chapter.
This section discusses
Defining Fields
A field identifier ( Field numbers are restricted to be between 1 and 8191, inclusive, for FML, and between 1 and 33,554,431, inclusive, for FML32. Field number 0 and the corresponding field identifier 0 is reserved to indicate a bad field identifier ( The numbering convention adopted by the BEA TUXEDO system is as follows:
Field Names and Identifiers
fieldid
) is defined (typedef
'd) as a FLDID
(FLDID32
for FML32), and is composed of two parts: a field type and a field number (the number uniquely identifies the field).
BADFLDID
). When FML is used with other software that also uses fields, additional restrictions may be imposed on field numbers.
The mappings between field identifiers and field names are contained in either field table files or field header files. Using field table files requires that you convert field name references in C programs with the mapping functions described later in this chapter; field header files allow the C preprocessor ( The functions and programs that access field tables use the environment variables The use of multiple field tables allows you to establish separate directories and/or files for separate groups of fields. Note that field names and field numbers should be unique across all field tables, since such tables are capable of being converted into C header files, and field numbers that occur more than once may cause unpredictable results.
Field table files are created using a standard text editor, such as cpp
(1) in UNIX reference manuals) to resolve name-to-fieldid mappings when a program is compiled.
FLDTBLDIR
and FIELDTBLS
to specify the source directories and field table files, respectively, which are to be used (FLDTBLDIR32
and FIELDTBLS32
are used for FML32). These should be set as described in Chapter 3, "Setup."
Field Table Files
vi
. They have the following format:
#
are ignored.
name rel-number type flag comment
name
is the identifier for the field. It should not exceed the C preprocessor identifier restrictions (that is, it should contain only alphanumeric characters and the underscore character). Internally, the name is truncated to 30 characters, so names must be unique within the first 30 characters.
flag
field is reserved for future use; use a dash (-
) in this field.
comment
is an optional field that can be used for clarifying information.
Note that these entries must be separated by white space (blanks or tabs).
The following is an example field table in which the base shifts from 500 to 700. The first fields in each group will be numbered 501 and 701, respectively.
Field Table Example
Listing 4-1
A UNIX Field Table File
# following are fields for EMPLOYEE service
# employee ID fields are based at 500
*base 500
#name rel-number type flags comment
#---- ---------- ---- ------ -------
EMPNAME 1 string - emp name
EMPID 2 long - emp id
EMPJOB 3 char - job type
SRVCDAY 4 carray - service date
*base 700
# all address fields are now relative to 700
EMPADDR 1 string - street address
EMPCITY 2 string - city
EMPSTATE 3 string - state
EMPZIP 4 long - zip code
Run-time mapping is done by the Fldid
() and Fname
() functions that consult the set of field table files specified by the FLDTBLDIR
and FIELDTBLS
environment variables (Fldid32()
and Fname32()
reference FLDTBLDIR32
and FIELDTBLS32
for FML32).
Fldid
maps its argument, a field name, to a fieldid:
char *name;
extern FLDID Fldid();
FLDID id;
...
id = Fldid(name);
Fname
does the reverse translation by mapping its argument, a fieldid
, to a field name:
extern char *Fname();
name = Fname(id);
. . .
The identifier-to-name mapping is rarely used; that is, it is rare that one has a field identifier and wants to know the corresponding name. One place where the field identifier-to-field name mapping could be used is in a buffer print routine where you want to display, in an intelligible form, the contents of a fielded buffer.
Upon the first call, Fldid()
loads the field table files and performs the required search. Thereafter, the files are kept loaded. Fldid()
returns the field identifier corresponding to its argument on success, and returns BADFLDID
on failure, with Ferror
set to FBADNAME
(Ferror32
is set for FML32).
To recover the data space used by the field tables loaded by Fldid()
, the user may unload all of the files by a call to the Fnmid_unload()
function.
The function Fname()
acts in a fashion similar to Fldid
(), but provides a mapping from a field identifier to a field name. It uses the same environment variable scheme for determining the field tables to be loaded, but constructs a separate set of mapping tables. On success, Fname()
returns a pointer to a character string containing the name corresponding to the fldid
argument. On failure, Fname()
returns NULL.
Note: The pointer is valid only as long as the table remains loaded.
As with Fldid()
, failure includes either the inability to find or open a field table (FFTOPEN
), bad field table syntax (FFTSYNTAX
), or a no-hit condition within the field tables (FBADFLD
). The table space used by the mapping tables created by Fname()
may be recovered by a call to the function Fidnm_unload()
.
Both mapping functions and other FML functions that use run-time mapping require FIELDTBLS
and FLDTBLDIR
to be set properly. Otherwise, default values are used. (See Chapter 3, "Setup," for the defaults.)
The command mkfldhdr
(1) (or mkfldhdr32
) converts field tables, as described above, into header files suitable for processing by the C compiler. Each line of the generated header file is of the following form.
#definefname
fieldid
where fname
is the name of the field, and fieldid
is its field-ID. The field-ID has both the field type and field number encoded in it. The field number is an absolute number, that is, base
plus rel-number
. The resulting file is suitable for inclusion in a C program.
The header file need not be used if the run-time mapping functions are used as described in the next sub-section. The advantage of compile-time mapping of names to identifiers is speed and a decrease of data space requirements. The disadvantage is that changes made to field name/identifier mappings after, for instance, a service routine has been compiled will not be propagated to the service routine (that is, it will use the mappings it has already compiled).
mkfldhdr
(1) translates each field-table specified in the FIELDTBLS
environment variable to a corresponding header file, whose name is formed by concatenating a .h
suffix to the field-table name. The resulting files are created, by default, in the current directory. The user may specify a creation directory to mkfldhdr
(1) by specifying a -d
option followed by the name of the directory in which you want the header files to reside. For example,
FLDTBLDIR=/project/fldtbls
FIELDTBLS=maskftbl,DBftbl,miscftbl
export FLDTBLDIR FIELDTBLS
mkfldhdr
or
FLDTBLDIR32=/project/fldtbls
FIELDTBLS32=maskftbl,DBftbl,miscftbl
export FLDTBLDIR32 FIELDTBLS32
mkfldhdr32
will produce the include files maskftbl.h
, DBftbl.h
and miscftbl.h
in the current directory by processing ${FLDTBLDIR}/maskftbl
, ${FLDTBLDIR}/DBftbl
and ${FLDTBLDIR}/miscftbl
. The command
mkfldhdr -d${FLDTBLDIR}
will process the sample input field-table files and produce the same output files, but will place them in the directory given by ${FLDTBLDIR}
.
You may override the environment variables (or avoid setting them) when using mkfldhdr
by specifying on the command line the names of the field tables to be converted (this does not apply to the run-time mapping functions). In this case, FLDTBLDIR
is assumed to be the current directory and FIELDTBLS
is assumed to be the list of parameters that the user specified on the command line. For example,
mkfldhdr myfields
will convert the field table file myfields
to a field header file myfields.h
, and place it in the current directory.
As mentioned in Chapter 2, "Overview," FML VIEWS is a mechanism that allows the exchange of data between fielded buffers and C structures or COBOL records. This capability is provided since it is usually more efficient to perform lengthy manipulations on C structures with C functions than on fielded buffers with FML functions. It also provides a way for a COBOL program to send and receive messages with a C program that handles FML fielded records.
This section discusses VIEWS and how to use it to provide fielded buffer/structure mappings. The figure below shows the various components of VIEWS and how they relate to one another. Each component is explained in the following sections.
Figure 4-1 Views
Source viewfiles are standard text files (created through any standard text editor, such as vi
) that contain one or more source view descriptions (the actual field-to-structure mappings).
The view compiler produces (among other things) object viewfiles containing the compiled object view descriptions. These object viewfiles can in turn be used as input to the view disassembler (viewdis
or viewdis32
), which translates the object view descriptions back into their source format (for verification or editing).
You create and edit the source view descriptions (or edit the output of viewdis
) only; compiled view descriptions are not readable by an editor.
Besides the actual view description(s), viewfiles can contain comment lines, beginning with #
or $
. Blank lines and lines beginning with #
are ignored by the view compiler, while lines beginning with $
are passed by the view compiler to any header files generated. This lets you pass C comments, what
strings, etc., to C header files produced by the view compiler; they are not passed through to the COBOL copy files.
Each source view description in a source viewfile consists of three parts:
VIEW
(never with a 32
suffix), followed by the name of the view description; the name can have a maximum of 33 alphanumeric characters (including the underscore character); when used with tpalloc
(3c), the maximum number of characters is 16.
The first line of each view description must begin with the keyword Thus, a source view description has the general structure shown in Listing 4-2.
VIEW
followed by the name of the view description. A member description (or mapping entry) is a line with information about a member in the C structure or COBOL record. A line with the keyword END
must be the last line in a view description.
Listing 4-2
Source View Description
VIEW vname
# type cname fbname count flag size null
# ---- ----- ------ ----- ---- ---- ----
--------------member descriptions-------------------
.
.
.
END
In Listing 4-2:
vname
is the name of the view description, and should be a valid C identifier name, since it is also used as the name of a C structure; underscores are mapped automatically to dashes in the COBOL COPY file.
fbname
is the name of the field in the fielded buffer; this name must appear in a field table file.
The following is a list of the options that can be specified as the flag Options
flag
element of a member description in a view description:
C
short
for FML and long
for FML32, and its name is generated as C_
cname
, where cname
is the cname
entry for which the ACM is declared. For example, an ACM for a member named parts
would be declared as follows:
short C_parts;
For the COBOL COPY file, the type is declared to be PIC S9(4) USAGE COMP-5
for FML and PIC S9(9) USAGE COMP-5
for FML32, and its name is generated as C-
cname
.
Note:
It is possible for the generated ACM name to conflict with structure members whose names begin with a C_
prefix. Such conflicts will be reported by the view compiler, and are considered fatal errors by the compiler. For example, if a structure member has the name C_parts
, it would conflict with the name of an ACM generated for the member parts
.
F
-n
command line option is specified.
L
carray
or string
to indicate the number of bytes transferred for these possibly variable length fields. If a string
or carray
field is always used as a fixed length data item, then this option provides no benefit. The L
option generates an associated length member (ALM) for a structure member of type carray
or string
. When transferring data from a fielded buffer to a structure, the ALM is set to the length of the corresponding transferred fields. If the length of a field in the fielded buffer exceeds the space allocated in the mapped structure member, only the allocated number of bytes is transferred. The corresponding ALM is set to the size of the fielded buffer item. Therefore, if the ALM is greater than the dimension of the structure member array, the fielded buffer information was truncated on transfer. When transferring data from a structure member to a field in a fielded buffer, the ALM is used to indicate the number of bytes to transfer to the fielded buffer, if it is a carray
type field. For strings, the ALM is ignored on transfer, but is set afterwards to the number of bytes transferred. Note that since carray
fields may be of zero length, an ALM of 0 indicates that a zero length field should be transferred to the fielded buffer, unless the value in the associated structure member is the null value.
An ALM is defined in the C header file to be an unsigned short for FML and an unsigned long for FML32, and has a generated name of L_
cname
, where cname
is the name of the structure for which the ALM is declared. If the number of occurrences of the member for which the ALM is declared is 1 (or defaults to 1), then the ALM is declared as:
unsigned short L_cname;
whereas if the number of occurrences is greater than 1, say N, the ALM is declared as:
unsigned short L_cname[N];
and is referred to as an ALM Array. In this case, each element in the ALM array refers to a corresponding occurrence of the structure member (or field). For the COBOL COPY file, the type is declared to be PIC 9(4) USAGE COMP-5
for FML and PIC 9(9) USAGE COMP-5
for FML32, and its name is generated as L-
cname
. The COBOL OCCURS clause is used to define multiple occurrences if the member occurs multiple times.
Note:
It is possible for the generated ALM name to conflict with structure members whose names begin with an L_
prefix. Such conflicts will be reported by the view compiler, and are considered fatal errors by the compiler. For example, if a structure member has the name L_parts
, it will conflict with the name of an ALM generated for the member parts
.
N
-n
command line option is specified.
P
-n
command line option is specified.
S
-n
command line option is specified.
Null values are used in VIEWS to indicate empty C structure or COBOL record members. Default null values are provided, and you may also define your own.
The default null value for all numeric types is 0 (0.0 for dec_t
); for char
types, it is "\0"; and for string
and carray
types, it is "".
Escape convention constants can also be used to specify a null value. The view compiler recognizes the following escape constants: \ddd (where d is an octal digit), \0, \n, \t, \v, \b, \r, \f, \\, \', and \".
String
, carray
, and char
null values may be enclosed in double or single quotes. Unescaped quotes within a user-defined null value are not accepted by the view compiler.
Alternatively, an element is null if its value is the same as the null value for that element, except in the following cases:
You can also specify the keyword " The maximum size of default values for string and character array members is 2660 characters.
Note:
Note that for string members, which usually end with a " where If the The By default, all views in The name of the object viewfile is viewfile.
Note:
Users of the BEA TUXEDO system Workstation feature in an MS-DOS environment will notice that the object viewfile is given a Header files created by the view compiler ( produces a C header file that looks like this:
COBOL COPY files created by the view compiler with the Note that the COPY file name is automatically converted to upper case by the view compiler. The COPY file would be included in a COBOL program as follows.
The output in the resulting COPY files is more fully described in the BEA TUXEDO COBOL Guide.
The view disassembler disassembles an object viewfile produced by the view compiler and displays view information in source viewfile format. In addition, it displays the offsets of structure members in the associated structure. It is usually used to verify the correctness of an object view description.
The command line looks like the following.
By default, The output of NONE
" in the null field of a view member description, which means there is no null value for the member.
\0
", a "\0
" is not required as the last character of a user-defined null value.
View Compiler
viewc
is a view compiler program for FML and viewc32
is used for FML32. It takes a source viewfile and produces an object viewfile, which is interpreted at runtime to effect the actual mapping of data. At runtime, a C compiler must be available for viewc
. The command line looks like the following.
viewc [-n] [-d
viewdir
] [-C] viewfile [viewfile ...]viewfile
is the name of a source viewfile containing source view descriptions. You may specify one or more viewfiles
on the command line.
-C
option is specified, then one COBOL COPY file is created for each VIEW defined in the viewfile
. These copy files are created in the current directory.
-n
option can be used when compiling a view description file for a C structure or COBOL record that does not map to an FML
buffer.
viewfile
are compiled and two or more files are created: an object viewfile (suffixed with ".V
"), and a header file (suffixed with ".h
") for each viewfile (see Figure 4-1).
V
. It is created in the current directory. The -d
option can be used to specify an alternate directory. Header files are created in the current directory.
.vv
suffix.
viewc C Header Files
viewc
) can be used in any C application programs to declare a C structure described by views. For example, the following view description
VIEW test
#TYPE CNAME FBNAME COUNT FLAG SIZE NULL
int empid EMPID 1 - - -1
float salary EMPPAY 1 - - 0
long phone EMPPHONE 4 - - 0
string name EMPNAME 1 - 32 "NO NAME"
ENDstruct test {
long empid; /* null=-1 */
float salary; /* null=0.000000 */
long phone[4]; /* null=0 */
char name[32]; /* null="NO NAME" */
}; COBOL COPY Files
-C
option can be used in any COBOL application programs to declare COBOL records described by views. For example, the COBOL COPY file for the previous view description will look like the following in the file TEST.cbl
.
* VIEWFILE: "test.v"
* VIEWNAME: "test"
05 EMPID PIC S9(9) USAGE IS COMP-5.
05 SALARY USAGE IS COMP-1.
05 PHONE OCCURS 4 TIMES PIC S9(9) USAGE IS COMP-5.
05 NAME PIC X(32).01 MYREC COPY TEST.
View Disassembler
viewdis objviewfile...
objviewfile
in the current directory is disassembled. If this file is not found in the current directory, an error message is displayed. You can specify one or more view object files on the command line.
viewdis
looks similar to the original source view description(s), and can be edited and re-input to viewc
. The order of the lines in the output of viewdis
may be different from the order of the original source view description, but this does not affect the correctness of the object file.