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 = -2 MsgInfo = -2 MsgInfo = '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 = -2 MsgInfo = -2 MsgInfo = '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 = -2 MsgInfo = -2 MsgInfo = 'Unable to write ':NewKey:' DICT.WO_LOG %MESASK%...' Void = msg( '', MsgInfo ) return 0 end unlock DictWOLogTable, '%MESASK%' else MsgInfo = '' MsgInfo = -2 MsgInfo = -2 MsgInfo = 'Unable to unlock DICT.WO_LOG %MESASK%' Void = msg( '', MsgInfo ) return 0 end return 0 end