Transaction - Examples

TRANSACTION WITHDRAWAL (x, withdrawal_amount)
Begin transaction
	IF X exist then
		READ X.balance
		IF X.balance > withdrawal_amount THEN
			SUBTRACT withdrawal_amount
			WRITE X.balance
			COMMIT
		ELSE
			DISPLAY “TRANSACTION CAN NOT BE PROCESSED”
	ELSE
	DISPLAY “ACCOUNT X DOES NOT EXIST”
End transaction;

TRANSACTION TRANSFER (x, y, transfer_amount)
Begin transaction
	IF x AND y exist then
		READ x.balance
		IF x.balance > transfer_amount THEN
			x.balance = x.balance – transfer_amount
			write x.balance
			READ y.balance
			y.balance = y.balance + transfer_amount
			write y.balance
			COMMIT
		ELSE
			DISPLAY “BALANCE IN X NOT OK”
			ROLLBACK
	ELSE
	DISPLAY “ACCOUNT x OR y DOES NOT EXIST”
End transaction;