* * This program demonstrates the calls necessary for recovery unit journaling. * It is meant as an example of use in FORTRAN, it does not implement complete * error checking. * IMPLICIT INTEGER*4 (A-Z) INCLUDE '($FORIOSDEF)' INCLUDE '($SYSSRVNAM)' * * Structure used for the checking and savings account files. * STRUCTURE /ACCOUNT_RECORD/ CHARACTER*9 NUMBER INTEGER*4 BALANCE CHARACTER*5 FILLER END STRUCTURE RECORD /ACCOUNT_RECORD/ CHECKING_ACCOUNT RECORD /ACCOUNT_RECORD/ SAVINGS_ACCOUNT * * Open the checking and savings account files. * OPEN (UNIT=10, FILE= 'RUF$CHECKING.DAT', STATUS = 'OLD', 1 ORGANIZATION = 'INDEXED', ACCESS = 'KEYED') OPEN (UNIT=11, FILE= 'RUF$SAVINGS.DAT', STATUS = 'OLD', 1 ORGANIZATION = 'INDEXED', ACCESS = 'KEYED') * * Recovery unit to initialize savings and checking account files. * Note that any I/O errors in this recovery unit will be ignored. * The checking and savings account will be initialized to $100 * for account "000001234". * Sys_stat = SYS$START_RU (Recovery_unit_handle) IF (.NOT. Sys_stat) THEN TYPE *, 'Cannot start recovery unit.' CALL LIB$SIGNAL (%VAL(Sys_stat)) ENDIF * * Put $100 dollars in the checking account of "000001234" * CHECKING_ACCOUNT.NUMBER = '000001234' CHECKING_ACCOUNT.BALANCE = 100 WRITE (UNIT=10,IOSTAT=IOS) CHECKING_ACCOUNT IF (IOS .NE. 0) THEN TYPE *, 'Checking account already exits' ENDIF * * Put $100 dollars in the savings account of "000001234" * Savings_account.number = '000001234' Savings_account.balance = 100 WRITE (UNIT=11,IOSTAT=IOS) Savings_account IF (IOS .NE. 0) THEN TYPE *, 'Savings account already exits' ENDIF * * End the recovery unit to initialize the checking and savings account * Sys_stat = SYS$END_RU (Recovery_unit_handle) IF (.NOT. Sys_stat) THEN TYPE *, ' Cannot end recovery unit to initialize accounts.' CALL LIB$SIGNAL(Sys_stat) ENDIF * * Transfer $10.00 from checking to savings using a recovery unit. * Note that the recovery unit is aborted if any I/O errors are * encountered. * Sys_stat = SYS$START_RU (Recovery_unit_handle) IF (.NOT. Sys_stat) THEN TYPE *, 'Cannot start recovery unit to transfer funds' CALL LIB$SIGNAL (Sys_stat) ENDIF * * Read the checking account record for "000001234". Abort recovery unit * if the operation is not successful. * Checking_account.number = '000001234' READ (UNIT=10, IOSTAT=IOS, 1 KEYEQ = Checking_account.number,ERR = 9992) 2 Checking_account * * Subtract $10 from the checking account balance. * Checking_account.balance = Checking_account.balance - 10 * * Update the checking account file reflecting the new balance. Abort the * recovery unit if the update is not successful. * REWRITE (UNIT=10, IOSTAT=IOS, ERR = 9993) Checking_account TYPE *, 'Pausing for 5 seconds' CALL LIB$WAIT (5) * * Read the savings account record for "000001234". Abort recovery unit * if the operation is not successful. * Savings_account.number = '000001234' READ (UNIT=11, IOSTAT=IOS, 1 KEYEQ = Savings_account.number,ERR = 9994) Savings_account * * Add $10 to the savings account. * Savings_account.balance = Savings_account.balance + 10 * * Update the savings account file reflecting the new balance. Abort the * recovery unit if the update is not successful. * REWRITE (UNIT=11, IOSTAT=IOS, ERR = 9995) Savings_account * * End the recovery unit. * Sys_stat = SYS$END_RU (Recovery_unit_handle) IF (.NOT. Sys_stat) THEN TYPE *, ' Cannot end recovery unit to initialize accounts' CALL LIB$SIGNAL (Sys_stat) ENDIF * * Display the new balances. * PRINT *,'The new checking account balance is... ', 1 Checking_account.balance PRINT *,'The new savings account balance is... ', 1 Savings_account.balance * * Close the checking and savings account files. * CLOSE (10) CLOSE (11) STOP 9992 TYPE *, 'Cannot read checking account balance' CALL SYS$ABORT_RU (Recovery_unit_handle) STOP 9993 TYPE *, 'Cannot update checking account balance' CALL SYS$ABORT_RU (Recovery_unit_handle) STOP 9994 TYPE *, 'Cannot read savings account balance' CALL SYS$ABORT_RU (Recovery_unit_handle) STOP 9995 TYPE *, 'Cannot update savings account balance' CALL SYS$ABORT_RU (Recovery_unit_handle) STOP END