I am trying to call a stored procedure from an automation script in Maximo.
The stored procedure is being called correctly and is running from the script fine, the problem I am running into is when it returns the output value it is setting it as None when it should be a string.
I have tested the stored procedure in SQL Server and I am getting the correct string I want when I call the procedure.
My automation script call looks like this:
storedProcedureWithParameter = '{call dbo.insertdelbkp3(?,?,?)}';
callableStatement = dbConnection.prepareCall(storedProcedureWithParameter);
callableStatement.setString(1, pMon);
callableStatement.setString(2, ArchData);
callableStatement.registerOutParameter(3, Types.VARCHAR);
callableStatement.execute();
output = str(callableStatement.getString(3));
print(output)
Does anyone have a thought on what is going wrong? Thanks.
EDIT****** For more information my stored procedure is archiving old records and should return a string when done. When I call my procedure in this script the records are getting archived but it is not returning my string. If I call the stored procedure inside SQL it archives records and returns the string as it should.
EDIT2****** The automation script is in Maximo being triggered by a cron task if that provides any more insight
EDIT3****** This is the stored procedure I am calling from my script. The stored procedure it calls(dbo.insertintobkp3) is fully functional and working fine.
USE [maxsb76]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[insertdelbkp3]
@mOld varchar(10), @TabList varchar(500), @logMessage VARCHAR(MAX) OUTPUT
as
DECLARE @sp varchar(500),@tp varchar(20)
BEGIN
DECLARE @oldRecToArch VARCHAR(MAX), --inserts into woarchrecords that are ready for arch
@rowcount int, --count for how many values are inserted into WOARCHRECORDS
@inDelMessage VARCHAR(MAX)
SET @sp=@TabList
SET @logMessage = 'List of backup tables are : '+@sp+'\n'
print 'List of backup tables are : '+@sp
if(((Select CAST(@mOld AS INT)) < 60) or (@mOld=NULL))
SET @mOld='60'
--inserts records to be archived into woarchrecords
SET @oldRecToArch = 'insert into dbo.woarchrecords(wonum, siteid) select wonum, siteid from dbo.workorder where status in (''CAN'', ''CLOSE'') and statusdate < dateadd(year,-'+@mOld+'/12,getdate())'
execute(@oldRecToArch)
SELECT @rowcount = @@ROWCOUNT
SET @logMessage = @logMessage + Convert(Varchar(12),@rowCount) +' new archivable records inserted into WOARCHRECORDS \n'
print Convert(Varchar(12),@rowCount) +' new archivable records inserted into WOARCHRECORDS'
DECLARE spcur cursor for select value from string_split(@sp,',')
OPEN spcur
FETCH next from spcur into @tp
WHILE 1=1
BEGIN
--checks that we were given tables to alter then seperates them and passes each table to be updated
IF @@FETCH_STATUS=0
BEGIN
SET @logMessage = @logMessage + 'Currently Archiving Table '+SUBSTRING(@tp,1,LEN(@tp)-3)+'\n'
print 'Currently Archiving Table '+SUBSTRING(@tp,1,LEN(@tp)-3)
if((SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='dbo' AND TABLE_NAME=@tp) is not null)
exec dbo.insertintobkp3 @mOld=@mOld,@TabList=@tp,@insertDeleteMessage=@inDelMessage output
SET @logMessage = @logMessage + @inDelMessage
FETCH next from spcur into @tp
END
IF @@FETCH_STATUS=-1
BREAK
END
print @logMessage
CLOSE spcur
DEALLOCATE spcur
END