Top
NetCOBOL V11.0 COBOL File Access RoutinesUser's Guide
FUJITSU Software

4.1.1 struct fa_keydesc

For the cobfa_rdkey() function and cobfa_stkey() function, arbitrary record key selection can be specified by using the struct fa_keydesc type. With the cobfa_indexinfo() function, the arbitrary record key in the indexed file that has been opened can be determined.

The values to set for the struct fa_keydesc type members that provide the record key are explained below.

#define  FA_NPARTS    254u                    /* max number of key parts */
struct  fa_keydesc  {
  long   k_flags;                             /* flags (duplicatable or not) */
  long   k_nparts;                            /* number of parts in key */
  struct fa_keypart  k_part  [FA_NPARTS];     /* each key part */
};

Key part code system type

For indexed files handled by COBOL applications whose operating mode is Unicode, specify FA_UCS2KPCODE if the key part is a national item of UCS-2(little-endian) or specify FA_UTF32KPCODE if the key part is a national item of UTF-32(little-endian). If the key part is not a national item of UCS-2(little-endian)/UTF-32(little-endian) or the operating mode is not Unicode, specify FA_ANYKPCODE.

To reference kp_flags when obtaining the record key organization (cobfa_indexinfo() function), use the mask value FA_KPCODEMASK to fetch the code system type of the key part.

Example

FA_KPCODEMASK use example

#include "f4agfcfa.h"
#define GET_PRIM_KEY  1
struct fa_keydesc keydesc1;
  :
ret = cobfa_indexinfo ( fd, &keydesc1, GET_PRIM_KEY);
for (i = 0; i < keydesc1.k_nparts; i ++) {
    :
  switch ( keydesc1.k_part[i].kp_flags & FA_KPCODEMASK ) {
    case FA_UCS2KPCODE:
       :
      break;
    case FA_ANYKPCODE:
       :
      break;
  }
    :
}

Practical examples

Example

Example 1

  • The primary record key can be duplicated. The number of key parts is 2.

  • The first part is at the fifth byte counted from the first byte and its length is 3.

  • The second part is at the eleventh byte counted from the first byte and its length is 5.

    Byte:  | 1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16
    Offset:|0--|1--|2--|3--|4--|5--|6--|7--|8--|9--|10-|11-|12-|13-|14-|15-|
           |============================================================....
                           |---+---+---|           |---+---+---+---+---|
                           first part              second part

COBOL program

001000 environment division.
001100 configuration section.
001200 input-output section.
001300 file-control.
001400     select FILENAME-1 assign to SYS006
001500     organization is indexed
001600     record key is part-1 part-2 with duplicates.
   :
002000 data division.
002100 file section.
002200 fd FILENAME-1.
002300   01 record-1.
002400     02 filler pic x(4).
002500     02 part-1 pic x(3).
002400     02 filler pic x(3).
002500     02 part-2 pic x(5).
002600     02 filler pix x(...

C program

#include "f3bifcfa.h"

struct fa_keydesc keydesc1;

keydesc1.k_flags  = FA_DUPS;
keydesc1.k_nparts = 2;                       /* number of key parts: 2 */
keydesc1.k_part[0].kp_start =  4;            /* part_1:  5 - 1 ==  4   */
keydesc1.k_part[0].kp_leng  =  3;
keydesc1.k_part[0].kp_flags = FA_ANYKPCODE;
keydesc1.k_part[1].kp_start = 10;            /* part_2: 11 - 1 == 10   */
keydesc1.k_part[1].kp_leng  =  5;
keydesc1.k_part[1].kp_flags = FA_ANYKPCODE;

Example 2

  • The primary record key does not permit duplication. The number of key parts is~3.

  • The first part is at the first byte and its length is 3.

  • The second part is at the ninth byte counted from the first byte and its length is~2.

  • The third part is at the fifth byte counted from the first byte and its length is 4.

    Byte:  | 1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16
    Offset:|0--|1--|2--|3--|4--|5--|6--|7--|8--|9--|10-|11-|12-|13-|14-|15-|
           |============================================================....
           |---+---+---|   |---+---+---+---|---+---|
           first part      third part      second part

COBOL program

001000 environment division.
001100 configuration section.
001200 input-output section.
001300 file-control.
001400     select FILENAME-1 assign to SYS006
001500     organization is indexed
001600     record key is part-1 part-2 part-3.
   :
002000 data division.
002100 file section.
002200 fd FILENAME-1.
002300   01 record-1.
002400     02 part-1 pic x(3).
002500     02 filler pic x(1).
002400     02 part-3 pic x(4).
002500     02 part-2 pic x(2).
002600     02 filler pix x(...

C program

#include "f3bifcfa.h"

struct fa_keydesc keydesc2;

keydesc2.k_flags  = FA_NODUPS;
keydesc2.k_nparts = 3;                       /* number of key parts: 3 */
keydesc2.k_part[0].kp_start =  0;            /* part_1:  1 - 1 ==  0   */
keydesc2.k_part[0].kp_leng  =  3;
keydesc2.k_part[0].kp_flags = FA_ANYKPCODE;
keydesc2.k_part[1].kp_start =  8;            /* part_2:  9 - 1 ==  8   */
keydesc2.k_part[1].kp_leng  =  2;
keydesc2.k_part[1].kp_flags = FA_ANYKPCODE;
keydesc2.k_part[2].kp_start =  4;            /* part_3:  5 - 1 ==  4   */
keydesc2.k_part[2].kp_leng  =  4;
keydesc2.k_part[2].kp_flags = FA_ANYKPCODE;