Adabas ダイレクトコールを使用する VAX-11 C の例です。付録 B で定義された Adabas ファイルが使用されています。
/*
.-------------------------------------------------------.
! !
! C example program for calling ADABAS(OpenVMS) !
! -------------------------------------------- !
! !
! Compile, link and run this program by typing: !
! !
! $ CC EXAMPLE !
! $ LINK EXAMPLE,SYS$LIBRARY:VAXCRTL/LIB !
! $ RUN EXAMPLE !
! !
! Function : !
! !
! Find in the default database all persons !
! named Smith and increase their salary by 10% !
! !
`-------------------------------------------------------'
*/
#include <stdio.h>
#define EXAMPLE_DB 0 /* default database */ #define EMPLOYEES_FILE 11 /* file number */
#define FMTBUF "ASN,4,F." /* salary field as 4 byte integer */ #define FBLEN 8 /* format buffer's length*/
#define VALBUF "SMITH" /* name to search for */ #define VBLEN 5 /* value buffer's length */
#define SEABUF "AE,5." /* search buffer NAME equal to */ #define SBLEN 5 /* search buffer's length */
#define RBLEN 4 /* record buffer's length */ #define IBLEN 4 /* ISN buffer's length */
#define OPENRB "UPD=11." /* record buffer used for OPEN */ #define OPENRBLEN 7 /* record buffer's length */
/* .------------------------.
! ADABAS control block !
`------------------------'
*/
typedef char char2 [2] ;
typedef char char4 [4] ;
typedef char char8 [8] ;
typedef struct control_block
{
char2 filler1 ;
char2 command_code ;
char4 command_id ;
char file_number ;
char db_id ;
short int response_code ;
int isn ;
int isn_ll ;
int isn_quantity ;
short int fmt_buf_lng ;
short int rec_buf_lng ;
short int sea_buf_lng ;
short int val_buf_lng ;
short int isn_buf_lng ;
char cmd_opt_1 ;
char cmd_opt_2 ;
char8 additions_1 ;
char4 additions_2 ;
char8 additions_3 ;
char8 additions_4 ;
char8 additions_5 ;
int command_time ;
char4 user_area ;
} ;
struct control_block cb ;
/* .----------------.
! define buffers !
`----------------'
*/
int isn_buffer; /* ISN buffer */
struct record_buffer /* record buffer */
{
int salary ;
} ;
struct record_buffer rb ;
/*
.------------------.
! define variables !
`------------------'
*/
short int upd =0 ;
int old_salary ;
/* .------------------.
! Main program !
`------------------'
*/
main ()
{
printf ("C example program for calling ADABAS(OpenVMS) ") ;
if ( open_database() != 0 )
response () ;
else
{
if ( find_record () == 0 )
{
printf ("\nFound : %d records ", cb.isn_quantity ) ;
while ( cb.response_code == 0) && (cb.isn_quantity != 0 )
{
old_salary = rb.salary ;
rb.salary += rb.salary/10 ;
if ( update_record () != 0)
cb.isn_quantity == 0 ;
else
{
printf
("\n ISN = %8d old salary = %10d new salary = %10d ",
cb.isn, old_salary, rb.salary) ;
upd++ ;
find_record () ;
}
}
}
if ( cb.response_code != 0 )
{
response () ;
cb.response_code = 0 ;
if ( upd != 0 )
if ( issue_bt () == 0 )
upd = 0 ;
else
response () ;
}
if ( cb.response_code == 0 )
{
if ( close_database () != 0 )
response () ;
}
}
}
/*
.------------------------.
! Open the database for !
! updating the EMPLOYEES !
! file !
`------------------------'
*/
open_database ()
{
cb.command_code[0] = 'O' ;
cb.command_code[1] = 'P' ;
cb.db_id = EXAMPLE_DB ;
cb.rec_buf_lng = OPENRBLEN ;
do adabas ( &cb , 0 , OPENRB ) ;
while (cb.response_code == 9) ;
return (cb.response_code) ;
}
/*
.-------------------------------.
! Close the database !
`-------------------------------'
*/
close_database ()
{
cb.command_code[0] = 'C' ;
cb.command_code[1] = 'L' ;
adabas ( &cb ) ;
return (cb.response_code)
}
/*
.-------------------------.
! Call ADABAS to find all !
! people named SMITH !
`-------------------------'
*/
find_record ()
{
cb.command_code[0] = 'L';
cb.command_code[1] = '4';
if ( cb.isn_quantity == 0 )
{
cb.command_code[0] = 'S' ;
cb.command_code[1] = '4' ;
cb.command_id[0] = 'F' ;
cb.command_id[1] = 'I' ;
cb.command_id[2] = 'N' ;
cb.command_id[3] = 'D' ;
cb.file_number = EMPLOYEES_FILE ;
cb.db_id = EXAMPLE_DB ;
cb.fmt_buf_lng = FBLEN ;
cb.rec_buf_lng = RBLEN ;
cb.sea_buf_lng = SBLEN ;
cb.val_buf_lng = VBLEN ;
cb.isn_buf_lng = IBLEN ;
cb.cmd_opt_2 = 'N' ;
}
adabas ( &cb , FMTBUF , &rb , SEABUF , VALBUF , &isn_buffer ) ;
if (cb.response_code == 3 )
{
cb.response_code = 0 ;
cb.isn_quantity = 0 ;
}
return ( cb.response_code ) ;
}
/*
.----------------------------.
! Change the value of salary !
! and update the record !
`----------------------------'
*/
update_record ()
{
cb.command_code[0] = 'A' ;
cb.command_code[1] = '1' ;
adabas ( &cb , FMTBUF , &rb ) ;
return (cb.response_code) ;
}
/*
.--------------.
! Response !
`--------------'
*/
response ( )
{
printf ("\n** Response code %d from ADABAS for Command %-2.2s ",
cb.response_code , &cb.command_code );
}
/*
.------------------.
! Issue BT command !
`------------------'
*/
issue_bt ()
{
cb.command_code[0] = 'B' ;
cb.command_code[1] = 'T' ;
adabas ( &cb ) ;
return (cb.response_code) ;
} ;