Using the #pragma mapinc Directive for Level Checking

C language only
The #pragma mapinc directive provides the opportunity to convert DDS files to include files directly.
If you specify the LVLCHK option on the #pragma mapinc directive, the following are generated:
  • An array of structures of type _LVLCHK_T
  • A variable of type _LVLCHK_T
The array is initialized so that each array element contains the level check information for the corresponding formats specified on the #pragma mapinc directive. The last two array elements are always empty strings, one for each field of the structure.

The name of the variable is LIBRARY_FILE_INCLUDE_lvlchk, where LIBRARY, FILE, and INCLUDE are the library_name, file_name and include_name, respectively.

If you specify the lvlchk keyword on the _Ropen varparm parameter and the composition of the file is changed, the file pointer on the _Ropen returns NULL and the CPF4131 message is issued.

Note: For more information about using the LVLCHK option of the #pragma mapinc directive, see the ILE C/C++ Compiler Reference.

The following figure shows the #pragma mapinc directive and the LVLCHK option to perform a level check on a file when it is opened.

Figure 1. ILE C Source Using the #pragma mapinc lvlchk Option
/* This program illustrates how to use level check information.       */
/* This example uses ILE C record I/O. See the ILE C                  */
/* Programmer's Reference for descriptions of the record I/O          */
/* functions.                                                         */
#include <stdio.h>
#include <stdlib.h>
#include <recio.h>
#pragma mapinc("DD3FILE","MYLIB/T1520DD3(purchase)","key lvlchk","_P")
#include "DD3FILE"
int main(void)
{
    _RFILE   *in;
    char     new_purchase[21] = "PEAR      1002022244";
/* Open the file for processing in keyed sequence. File is created    */
/* with the default access path.                                      */
    if ( (in = _Ropen("MYLIB/T1520DD3", "rr+ varparm = (lvlchk)",
          &amp;MYLIB_T1520DD3_DD3FILE_lvlchk)) == NULL)
    {
        printf("Open failed\n");
        exit(1);
    }

/* Update the first record in the keyed sequence.  The function       */
/* _Rlocate locks the record.                                         */
    _Rlocate(in, NULL, 0, __FIRST);
    _Rupdate(in, new_purchase, 20);
/* Force the end of data.                                             */
    _Rfeod(in);
    _Rclose(in);
}
The following example contains the DDS in the file T1520DD3 in the library MYLIB.
Figure 2. T1520DD3 — DDS Source for Program
     A          R PURCHASE
     A            ITEMNAME      10
     A            SERIALNUM     10
     A          K SERIALNUM
The DDS part of the program listing is as follows:
Figure 3. Ouput Listing from the Program
/* ------------------------------------------------------------------------*/
/* PHYSICAL FILE: MYLIB/T1520DD3                                           */
/* FILE CREATION DATE: 93/09/02                                            */
/* RECORD FORMAT: PURCHASE                                                 */
/* FORMAT LEVEL IDENTIFIER: 322C4B361172D                                  */
/* ------------------------------------------------------------------------*/
typedef _Packed struct {
   char SERIALNUM[10];
                                        /*  DDS - ASCENDING*/
                                        /*  STRING KEY FIELD*/
}MYLIB_T1520DD3_PURCHASE_key_t;
typedef _Packed struct {
   unsigned char format_name[10];
   unsigned char sequence_no[13];
} _LVLCHK_T[];
_LVLCHK_T MYLIB_T1520DD3_DD3FILE_lvlchk = {
   "PURCHASE  ", "322C4B361172D",
   "", "" };