open-insight/LSL2/STPROC/NEXT_MESA_WO_LOG_KEY.txt
Infineon\StieberD 7762b129af pre cutover push
2024-09-04 20:33:41 -07:00

73 lines
1.9 KiB
Plaintext

compile function next_mesa_wo_log_key( Operation, Key )
begin condition
pre:
post:
end condition
* this function will return the next available MESA wo_log key number
* It will get a lock and hold it so the calling routine will
* be responsible for unlocking
$insert logical
$insert msg_equates
declare function msg
if Operation = 'NEXT' then
open 'WO_LOG' to WOLogTable else
MsgInfo = ''
MsgInfo<mcol$> = -2
MsgInfo<mrow$> = -2
MsgInfo<mtext$> = 'Unable to open WO_LOG'
Void = msg( '', MsgInfo )
return 0
end
NextRecId = xlate( 'DICT.WO_LOG', '%MESASK%', 1 , 'X' )
Locked = false$
loop
if rowexists( 'WO_LOG', NextRecId ) then
NextRecId += 1
end else
lock WOLogTable, NextRecId then
Locked = true$
end else
NextRecId += 1
end
end
until Locked
repeat
return NextRecId
end else
open 'DICT.WO_LOG' to DictWOLogTable else
MsgInfo = ''
MsgInfo<mcol$> = -2
MsgInfo<mrow$> = -2
MsgInfo<mtext$> = 'Unable to open DICT.WO_LOG...'
Void = msg( '', MsgInfo )
return 0
end
Locked = false$
loop
lock DictWOLogTable, '%MESASK%' then
Locked = true$
end
until Locked
repeat
NewKey = Key+1
write NewKey on DictWOLogTable, '%MESASK%' else
MsgInfo = ''
MsgInfo<mcol$> = -2
MsgInfo<mrow$> = -2
MsgInfo<mtext$> = 'Unable to write ':NewKey:' DICT.WO_LOG %MESASK%...'
Void = msg( '', MsgInfo )
return 0
end
unlock DictWOLogTable, '%MESASK%' else
MsgInfo = ''
MsgInfo<mcol$> = -2
MsgInfo<mrow$> = -2
MsgInfo<mtext$> = 'Unable to unlock DICT.WO_LOG %MESASK%'
Void = msg( '', MsgInfo )
return 0
end
return 0
end