ILE C/C++ Programmer's Guide

Example: Returning Indicators to the File Buffer

The following example shows how to specify an indicator in a record that is read by program T1520ID1. The indicator is placed in the file buffer of an externally described file. The DDS for the externally described file contains one character indicator field.

Instructions

  1. To create the display file T1520DD9, enter:

    CRTDSPF FILE(MYLIB/T1520DD9) SRCFILE(QCPPLE/QADDSSRC)
    Figure 139 shows the DDS source.
  2. To create the program T1520ID1 using the program source shown in Figure 140, enter:

    CRTBNDC PGM(MYLIB/T1520ID1) SRCFILE(QCPPLE/QACSRC)
  3. To run the program T1520ID1, enter:

    CALL PGM(MYLIB/T1520ID1)

    The output is as follows:

    +--------------------------------------------------------------------------------+
    |                                  PHONE BOOK                                    |
    |                           Name:                                                |
    |                        Address:                                                |
    |                        Phone #:                                                |
    |                                 F3 - EXIT                                      |
    +--------------------------------------------------------------------------------+

Code Samples

Figure 139. T1520DD9 -- DDS Source for a Phone Book Display




A R PHONE
A CF03(03 'EXIT')
A 1 35'PHONE BOOK'
A DSPATR(HI)
A 7 28'Name:'
A NAME 11A I 7 34
A 9 25'Address:'
A ADDRESS 20A I 9 34
A 11 25'Phone #:'
A PHONE_NUM 8A I 11 34
A 23 34'F3 - EXIT'
A DSPATR(HI)

Figure 140. T1520ID1 -- ILE C Source to Specify Indicators as Part of the File Buffer




/* This program uses a response indicator to inform the program */
/* that F3 was pressed by a user. The response indicator is returned */
/* in part of the file buffer. */
#include <stdio.h>
#include <recio.h>
#include <stdlib.h>
 
typedef struct{
char in03;
char name[11];
char address[20];
char phone_num[8];
}info;
 
#define IND_ON '1'


int main(void)
{
_RFILE *fp;
_RIOFB_T *rfb;
info phone_list;
 
if (( fp = _Ropen ( "*LIBL/T1520DD9", "ar+" )) == NULL )
{
printf ( "display file open failed\n" );
exit ( 1 );
}
 
_Rformat ( fp, "PHONE" );
rfb = _Rwrite ( fp, "", 0);
rfb = _Rreadn ( fp, &phone_list, sizeof(phone_list), __DFT );
if ( phone_list.in03 == IND_ON )
{
printf ( "user pressed F3\n" );
}
_Rclose ( fp );
}
Note:
This program uses a response indicator IND_ON '1' to inform the ILE C program T1520ID1 that a user pressed F3.


[ Top of Page | Previous Page | Next Page | Table of Contents ]