Enscribe Programmer's Guide
CALL ENDTRANSACTION; ! End the transaction
RETURN Error <> 0;
END;
Example 3: Dequeuing a Record
This TAL example dequeues the first record from a queue file. Note that the queue file must be
opened before calling this procedure.
INT QF^Num; ! Queue File number
STRING .QF^Name[0:33] := "$spool.lkp.qfile"; ! File name
LITERAL QF^NameLength = 16; ! Length in bytes of file name
INT QF^NameLen;
LITERAL Key^Length = 8; ! Key length (must be >= 8)
INT Key^Len;
STRING .Key[0:Key^Length - 8]; ! Application key
LITERAL Rec^Len = 100; ! Record length
INT Byte^Count; ! Number of bytes read/written
INT Error; ! Returned error code
FIXED Trans^Tag; ! Transaction identifier
STRING .Buffer[0:Rec^Len-1]; ! Record buffer
STRING .Data[0:Rec^Len - Key^Length - 1];
! Data being dequeued
?SOURCE $SYSTEM.SYSTEM.EXTDECS0 (KEYPOSITION,
? ABORTTRANSACTION,
? BEGINTRANSACTION,
? ENDTRANSACTION,
? FILEINFO,
? READUPDATELOCK)
!
! Dequeue the first record from a Queue File
!
INT PROC DEQUEUE(Error); ! Returns # bytes in queue
! entry, or
INT .Error; ! returned error code (or zero)
BEGIN ! -1 if an error occurred.
Error := 0; ! Clear error code
! Position to beginning of file
CALL KEYPOSITION(
QF^Num, ! filenum
Key, ! key-value (not used)
, ! key-specifier (not needed)
0, ! length-word = zero (position to start)
0); ! positioning-mode = approximate
DO
BEGIN
Error := BEGINTRANSACTION(Trans^Tag); ! Start trans.
CALL READUPDATELOCK(QF^Num, Buffer, Rec^Len, Byte^Count);
! Read the first record
IF = THEN ! Check for errors
BEGIN ! No error occurred
Data[0] ':=' Buffer[Key^Len] FOR Byte^Count - Key^Len;
RETURN Byte^Count; ! Extract data and return
! Note: An ENDTRANSACTION call should be executed when
! the current queue record has been processed.
END;
!
! Process READUPDATELOCK error
!
! Determine which error occurred
status := FILE_GETINFO_ (QF^Num, Error);
IF Error = 162 then ! Timeout occurred
BEGIN
status := ENDTRANSACTION; ! Release this transaction
Accessing Queue Files 119