PROGRAM Rufexample ! ! This program demonstrates the calls necessary for recovery unit journaling. ! It is meant as an example of use in BASIC, it does not implement complete ! error checking. ! EXTERNAL INTEGER FUNCTION SYS$START_RU, SYS$END_RU ! ! Record structure used for the checking and savings account. ! MAP (checking_account) STRING checking_account_number = 9%, & INTEGER checking_account_balance, & STRING fill = 5% MAP (savings_account) STRING savings_account_number = 9%, & INTEGER savings_account_balance, & STRING filler = 5% ! ! Open the checking and savings account files. ! OPEN "RUF$CHECKING.DAT" FOR INPUT AS FILE 1%, & ORGANIZATION INDEXED, & MAP checking_account OPEN "RUF$SAVINGS.DAT" FOR INPUT AS FILE 2%, & ORGANIZATION INDEXED, & MAP savings_account ! ! 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 BY REF) IF ((Sys_stat% and 1% ) = 0%) THEN PRINT " Cannot start initialization recovery unit " CALL LIB$SIGNAL (Sys_stat%,0,0) END IF ! ! Put $100 dollars in the checking account of "000001234" ! checking_account_number = "000001234" checking_account_balance= 100% WHEN ERROR IN PUT #1 USE PRINT "Checking account already exists " END WHEN ! ! Put $100 dollars in the savings account of "000001234" ! Savings_account_number = "000001234" Savings_account_balance= 100% WHEN ERROR IN PUT #2 USE PRINT "Savings account already exists " END WHEN ! ! End the recovery unit to initialize the checking and savings account ! Sys_stat% = SYS$END_RU (Recovery_unit_handle BY REF) IF (Sys_stat% and 1% ) = 0% THEN PRINT " Cannot end initialization recovery unit " CALL LIB$SIGNAL (Sys_stat%, 0, 0) END IF ! ! 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 BY REF) IF (Sys_stat% and 1% ) = 0% THEN PRINT " Cannot start transfer recovery unit " CALL LIB$STOP (Sys_stat%) END IF ! ! Read the checking account record for "000001234". Abort recovery unit ! if the operation is not successful. ! WHEN ERROR IN GET #1, KEY #0% EQ Checking_account_number USE PRINT "Could not find checking account " CALL SYS$ABORT_RU (Recovery_unit_handle BY REF) END WHEN ! ! 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. ! WHEN ERROR IN UPDATE #1 USE PRINT " Cannot update checking account " CALL SYS$ABORT_RU (Recovery_unit_handle BY REF) END WHEN PRINT 'Pausing for 5 seconds.' CALL LIB$WAIT (5) ! ! Read the savings account record for "000001234". Abort recovery unit ! if the operation is not successful. ! WHEN ERROR IN GET #2, KEY #0% EQ Savings_account_number USE PRINT " Could not find savings account " CALL SYS$ABORT_RU (Recovery_unit_handle BY REF) END WHEN ! ! 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. ! WHEN ERROR IN UPDATE #2 USE PRINT " Cannot update savings account " CALL SYS$ABORT_RU (Recovery_unit_handle BY REF) END WHEN ! ! End the recovery unit. ! Sys_stat% = SYS$END_RU (Recovery_unit_handle BY REF) IF (Sys_stat% and 1% ) = 0% THEN PRINT " Cannot end transfer recovery unit " CALL LIB$STOP (Sys_stat%) END IF ! ! Display the new balances. ! PRINT "The new checking account balance is $", checking_account_balance PRINT "The new savings account balance is $", Savings_account_balance ! ! Close the checking and savings account files. ! CLOSE #1 CLOSE #2 END PROGRAM