RE: Allow only one batch job to insert into a table at one time in multiple batch job scenario.
That what I am doing, please look into it:
select * from Batch where Batch.ClassNumber == classNum(myBatchClass) && Batch.Status == BatchStatus::Executing;
//select count (RecId) from Batch where Batch.ClassNumber == classNum(myBatchClass) && Batch.Status == BatchStatus::Executing;
//countRec = Batch.RecId;
select firstonly batchStatusLogTable where batchStatusLogTable.Status == BatchStatus::Executing;
try
{
if (!batchStatusLogTable.RecId)
{
insert_recordset batchStatusLogTable (BatchJobId,Caption,Status)
select BatchJobId, Caption, Status from Batch
where Batch.ClassNumber == classNum(myBatchClass)
&& Batch.Status == BatchStatus::Executing
&& Batch.BatchJobId == batchId;
//insert data into report table
this.selectFromQuery(batchDate);
//update the batch status table to ended
ttsbegin;
While select forupdate * from batchStatusLogTable where batchStatusLogTable.Status == BatchStatus::Executing
{
batchStatusLogTable.Status = BatchStatus::Finished;
batchStatusLogTable.update();
}
ttscommit;
}
else
{
Error('another batch running');
}
Before the first batch inserts the record into batchStatusLogTable, the other batch also enters the if block. Please help!