C language application program example

This example shows how you might code this application by using the z/TPFDF C functions.

You must ensure that there is a structure defined for each file that the C language application program will access. The following example (ir00df.h) shows the structure of the member file that is used in this sample application.
 1  /*-------------------------------------------------------------------*
 2   *      Passenger Record Structure Declaration                       *
 3   *-------------------------------------------------------------------*/
 4  #define _IR00DFI        "S0"            /* File ID */
 5
 6  #define _IR00K80        0x80            /* logical record keys */
 7  #define _IR00K90        0x90
 8  #define _IR00KA0        0xA0
 9  #define _IR00KB0        0xB0
10  #define _IR00KC0        0xC0
11  #define _IR00KD0        0xD0
12
13  #define _IR00L80        sizeof(struct ir00psgr) /* passenger name     */
14  #define _IR00L90        sizeof(struct ir00addr) /* passenger address  */
15  #define _IR00LA0        sizeof(struct ir00info) /* meal, seat, pay    */
16  #define _IR00LB0        sizeof(struct ir00stat) /* membership status  */
17  #define _IR00LC0        sizeof(struct ir00rnum) /* reusable number    */
18  #define _IR00LD0        sizeof(struct ir00cnum) /* consecutive number */
19
20  struct ir00df
21 ┌{
22 │  short   ir00siz;                      /* LREC size   */
23 │  dft_pky ir00key;                      /* primary key */
24 │  union
25 │ ┌{
26 │ │  struct ir00psgr
27 │ │ ┌{
28 │ │ │  char  ir00nam[20];                /* surname */
29 │ │ │  char  ir00int[6];                 /* initials */
30 │ │ └} psgr;
31 │ │
32 │ │  struct ir00addr
33 │ │ ┌{
34 │ │ │  char ir00adr[43];                 /* address */
35 │ │ └} addr;
36 │ │
37 │ │  struct ir00info
38 │ │ ┌{
39 │ │ │  char  ir00sp0;                    /* spare for alignment */
40 │ │ │  char  ir00mpr[2];                 /* meal preference     */
41 │ │ │  char  ir00spr[2];                 /* seat preference     */
42 │ │ │  char  ir00pay[2];                 /* payment method      */
43 │ │ └} info;
44 │ │
45 │ │  struct ir00stat
46 │ │ ┌{
47 │ │ │  char  ir00sp1;                    /* spare for alignment    */
48 │ │ │  int   ir00mls;                    /* current mileage credit */
49 │ │ │  short ir00exy;                    /* expiration year        */
50 │ │ │  short ir00exm;                    /* expiration month       */
51 │ │ └} stat;
52 │ │
53 │ │  struct ir00rnum
54 │ │ ┌{
55 │ │ │  char  ir00num[10];                /* reusable member number */
56 │ │ └} rnum;
57 │ │
58 │ │  struct ir00cnum
59 │ │ ┌{
60 │ │ │  char  ir00nuc[10];                /* consecutive member number */
61 │ │ └} cnum;
62 │ └} lrec;
63 └};

The following example (psgr.h) shows how you can redefine z/TPFDF functions so that you can code them more simply in the application program.

Note: This type of header is not required; you can code the z/TPFDF functions directly in your application program if you prefer.
 1  /*--------------------------------------------------------------------*
 2   *       MEMBER FILE DEFINITIONS HEADER                               *
 3   *                                                                    *
 4   *       This file contains definitions to support use of the         *
 5   *       Gold Club Passenger (member) file.                           *
 6   *--------------------------------------------------------------------*/
 7  #include "ir00df.h"
 8
 9  #define HOLD            DFOPN_HOLD
10  #define NOHOLD          DFOPN_NOHOLD
11  #define RELFC           DFCLS_RELFC
12  #define REUSE           DFCLS_REUSE
13
14  #define open_psgr(opts)         dfopn("PSGRFILE",_IR00DFI,opts)
15  #define create_psgr(file,alg)   (void) dfcre_alg(file,0,alg)
16  #define read_psgr(file,alg)     dfred_acc(file,DFRED_ALG,0,alg)
17  #define add_psgr(file,rcd)      (void) dfadd(file,DFADD_NEWLREC,0,rcd)
18  #define replace_psgr(file,rcd)  (void) dfrep(file,DFREP_NEWLREC,rcd)
19  #define modify_psgr(file)       (void) dfmod(file)
20  #define close_psgr(file,opts)   dfcls(file,opts)
21  #define display_psgr(file)      dfdsp_str(file,DFDSP_NOKEY, \
22                                      offsetof(struct ir00df,ir00key))
23  #define open_del_nbr(opts)      dfopn_acc("DELNBRS ",_IR00DFI,DFOPN_ALG, \
24                                             DFOPN_DETAC|opts, \
25                                             "9999999999")
26  #define read_del_nbr(file)      dfred_acc(file,DFRED_ALG,DFRED_NOKEY, \
27                                            "9999999999")
28  #define add_del_nbr(file,rcd)   (void) dfadd(file,DFADD_NEWLREC,0,rcd)
29  #define delete_del_nbr(file)    (void) dfdel(file,0)
30  #define modify_del_nbr(file)    (void) dfmod(file)
31  #define close_del_nbr(file)     dfcls(file,0)
32
33  #define MEM_NUM_SIZE    member_size(struct ir00df,lrec.rnum.ir00num)
34  #define MAX_NAME_SIZE   member_size(struct ir00df,lrec.psgr.ir00nam)
35  #define MAX_ADDR_SIZE   member_size(struct ir00df,lrec.addr.ir00adr)
36  #define MEAL_SIZE       member_size(struct ir00df,lrec.info.ir00mpr)
37  #define SEAT_SIZE       member_size(struct ir00df,lrec.info.ir00spr)
38  #define PMNT_SIZE       member_size(struct ir00df,lrec.info.ir00pay)
The member file requires the following types of processing:
  • File maintenance, which consists of adding, deleting, changing, and displaying information related to a member.
  • Departure control interface, which updates the member file with the number of miles flown after each departure and adjusts the membership expiration date.
  • Monthly maintenance, which deletes records that have expired and adds the membership number to a subfile for reallocation.