Including Externally Described Multiple Record Formats in a Logical File

To include multiple formats in a logical file, specify more than one record format name or (*ALL) on the #pragma mapinc directive. If you specify multiple formats, a header description and type definition is created for each format. If you specify a union- type-name, a union type definition is created.

C++ language onlyC++ users must use the GENCSRC utility to create type definitions from an external file.

C language onlyC users can use either the GENCSRC utility or the #pragma mapinc directive to create type definitions from an external file.

Note: For more information on the differences between the GENCSRC utility and the #pragma mapinc directive, see The GENCSRC Utility and the #pragma mapinc Directive.

The typedef union contains structure definitions created for each format. Structure definitions that are created for key fields when the key option is specified are not included in the union definition. The name of the union definition is union-type-name_t. The name you provide for the union-type-name is not folded to uppercase.

The following shows the type definitions created for a logical file with two record formats with the BOTH and KEY options specified. A typedef union with the tag buffer_t is also generated. C language only
#pragma mapinc("pay","lib1/pay(fmt1 fmt2)","both key","","buffer","Pay")
#include "pay"
Figure 1. Structure Definition for Multiple Formats

/* --------------------------------------------------------*/
/* LOGICAL FILE: PAY                                       */
/* FILE CREATION DATE: 93/09/01                            */
/* RECORD FORMAT: FMT1                                     */
/* FORMAT LEVEL IDENTIFIER: 371E00A681EA7                  */
/* --------------------------------------------------------*/
 typedef struct {
         .
         .
         .
 }Pay_FMT1_both_t;

 typedef struct {
         .
         .
         .
 }Pay_FMT1_key_t;

/* --------------------------------------------------------*/
/* LOGICAL FILE: PAY                                       */
/* FILE CREATION DATE: 93/09/01                            */
/* RECORD FORMAT: FMT2                                     */
/* FORMAT LEVEL IDENTIFIER: 371E00A681EA7                  */
/* --------------------------------------------------------*/
 typedef struct {
         .
         .
         .
 }Pay_FMT2_both_t;

 typedef struct {
         .
         .
         .
 }Pay_FMT2_key_t;

 typedef union {
    Pay_FMT1_both_t;                Pay_FMT1_both;
    Pay_FMT2_both_t;                Pay_FMT2_both;
 }buffer_t;
Note: A typedef union is not created for the key fields.

If you specify *ALL, or more than one record format on the format-name parameter, structure definitions for multiple formats are created.

If you specify multiple formats, and the input, or output option, one structure is created for each format. The following shows the structure definitions that are created when you include the following statements in your program. The device file TESTLIB⁄FILE contains two record formats, FMT1, and FMT2. Each record format has fields defined as OUTPUT in its file description. C language only
#pragma mapinc("example","testlib/file(fmt1 fmt2)","output","z","unionex")
#include "example"
Figure 2. Structure Definitions for a Device File

/* ------------------------------------------------------------------ */
/* DEVICE FILE: TESTLIB/FILE                                          */
/* FILE CREATION DATE: 93/09/01                                       */
/* RECORD FORMAT: FMT1                                                */
/* FORMAT LEVEL IDENTIFIER: 371E00A681EA7                             */
/* ------------------------------------------------------------------ */
   typedef struct {
           .
           .
           .
   }TESTLIB_FILE_FMT1_o_t;

/* ------------------------------------------------------------------ */
/* DEVICE FILE: TESTLIB/FILE                                          */
/* CREATION DATE: 93/09/01                                            */
/* RECORD FORMAT: FMT2                                                */
/* FORMAT LEVEL IDENTIFIER: 371E00A681EA8                             */
/* ------------------------------------------------------------------ */
   typedef struct {
           .
           .
           .
   }TESTLIB_FILE_FMT2_o_t;

   typedef union {
      TESTLIB_FILE_FMT1_o_t      TESTLIB_FILE_FMT1_o;
      TESTLIB_FILE_FMT2_o_t      TESTLIB_FILE_FMT2_o;
   }unionex_t;
When both are specified as an option, two structure definitions are created for each format. The following shows the structure definitions created when you include two formats, FMT1 and FMT2, for the device file EXAMPLE⁄TEST and specify the both option: C language only
#pragma mapinc("test","example/test(fmt1 fmt2)","both","z","unionex")
#include "test"
If all the fields are defined as BOTH and there are to be no indicators in the typedef struct, only one typedef struct is generated for each format specified. The following shows a separate typedef structure for input and output fields.
Figure 3. Structure Definitions for BOTH Option
/* ------------------------------------------------------------------ */
/* DEVICE FILE: EXAMPLE/TEST                                          */
/* CREATION DATE: 93/09/01                                            */
/* RECORD FORMAT: FMT1                                                */
/* FORMAT LEVEL IDENTIFIER: 371E00A681EA7                             */
/* ------------------------------------------------------------------ */
   typedef struct {
           .
           .
           .
   }EXAMPLE_TEST_FMT1_i_t;
   typedef struct {
           .
           .
           .
   }EXAMPLE_TEST_FMT1_o_t;
/* ------------------------------------------------------------------ */
/* DEVICE FILE: EXAMPLE/TEST                                          */
/* CREATION DATE: 93/09/01                                            */
/* RECORD FORMAT: FMT2                                                */
/* FORMAT LEVEL IDENTIFIER: 371E00A681EA8                             */
/* ------------------------------------------------------------------ */
   typedef struct {
           .
           .
           .
   }EXAMPLE_TEST_FMT2_i_t;
   typedef struct {
           .
           .
           .
   }EXAMPLE_TEST_FMT2_o_t;
   typedef union{
      EXAMPLE_TEST_FMT1_i_t      EXAMPLE_TEST_FMT1_i;
      EXAMPLE_TEST_FMT1_o_t      EXAMPLE_TEST_FMT1_o;
      EXAMPLE_TEST_FMT2_i_t      EXAMPLE_TEST_FMT2_i;
      EXAMPLE_TEST_FMT2_o_t      EXAMPLE_TEST_FMT2_o;
   }unionex_t;