473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Return status from a stored pros in a OS script

Is there a way to check the return status from a stored procedure when
called from a OS (Windows) script?

I have a stored procedure that does some checking in the database, and the
return status is set to 0 or -1 if 'OK' or 'not OK' respectively.

When I call the from CLP I get something like this:

Value of output parameters
--------------------------
Parameter Name : P_SQLSTATE
Parameter Value : 00000

Parameter Name : P_MESSAGE
Parameter Value :

Return Status = 0

I want to do this in my script:
db2 call proc(?, ?)
if RC= 0 then do something
else then do something else

If I run this script from the Task Center, is there a way to 'force' the
task to fail if the return status is not 0 ?

Regards
Odd B Andersen
ErgoGroup AS, Oslo, Norway
May 24 '07 #1
3 5177
Odd Bjørn Andersen wrote:
Is there a way to check the return status from a stored procedure when
called from a OS (Windows) script?

I have a stored procedure that does some checking in the database, and the
return status is set to 0 or -1 if 'OK' or 'not OK' respectively.

When I call the from CLP I get something like this:

Value of output parameters
--------------------------
Parameter Name : P_SQLSTATE
Parameter Value : 00000

Parameter Name : P_MESSAGE
Parameter Value :

Return Status = 0

I want to do this in my script:
db2 call proc(?, ?)
if RC= 0 then do something
else then do something else
I don't think that the exit status from the CLP is related to the return
status of a stored procedure. Therefore, you will have to parse the output
and act on the parsed result. Alternatively, you can write a small program
that invokes your procedure and uses the return status of the CALL as its
own exit status.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
May 25 '07 #2
On May 24, 9:53 am, "Odd Bjørn Andersen" <oba...@online.nowrote:
Is there a way to check the return status from a stored procedure when
called from a OS (Windows) script?

I have a stored procedure that does some checking in the database, and the
return status is set to 0 or -1 if 'OK' or 'not OK' respectively.

When I call the from CLP I get something like this:

Value of output parameters
--------------------------
Parameter Name : P_SQLSTATE
Parameter Value : 00000

Parameter Name : P_MESSAGE
Parameter Value :

Return Status = 0

I want to do this in my script:
db2 call proc(?, ?)
if RC= 0 then do something
else then do something else

If I run this script from the Task Center, is there a way to 'force' the
task to fail if the return status is not 0 ?

Regards
Odd B Andersen
ErgoGroup AS, Oslo, Norway

It depends on the scripting language that you use on Windows.

You must parse the output of the CLP invokation "db2 call ..." to
search for "Return Status = 0".

With scripting tools like Perl or *nix-like shells (like Ksh or Bash)
under Cygwin - you have more power to parse text.

If your only tool is basic CMD.EXE script language, then something
like this hack will work on Win/XP.

....
db2 "CALL your_procedure(...)" 2>&1 1>spcall.log
@rem the find command returns 0 when the string is found
find "Return Status = 0" spcall.log null
@if ERRORLEVEL 1 goto :nonzero_status
:success_status
....whatever

:nonzero_status
....whatever

May 25 '07 #3
>"mike" <_l*****@yahoo.comwrote in message
news:11**********************@k79g2000hse.googleg roups.com...
On May 24, 9:53 am, "Odd Bjørn Andersen" <oba...@online.nowrote:
>Is there a way to check the return status from a stored procedure when
called from a OS (Windows) script?

I have a stored procedure that does some checking in the database, and the
return status is set to 0 or -1 if 'OK' or 'not OK' respectively.

When I call the from CLP I get something like this:

Value of output parameters
--------------------------
Z Parameter Name : P_SQLSTATE
Parameter Value : 00000

Parameter Name : P_MESSAGE
Parameter Value :

Return Status = 0

I want to do this in my script:
db2 call proc(?, ?)
if RC= 0 then do something
else then do something else

If I run this script from the Task Center, is there a way to 'force' the
task to fail if the return status is not 0 ?

Regards
Odd B Andersen
ErgoGroup AS, Oslo, Norway


It depends on the scripting language that you use on Windows.

You must parse the output of the CLP invokation "db2 call ..." to
search for "Return Status = 0".

With scripting tools like Perl or *nix-like shells (like Ksh or Bash)
under Cygwin - you have more power to parse text.

If your only tool is basic CMD.EXE script language, then something
like this hack will work on Win/XP.

...
db2 "CALL your_procedure(...)" 2>&1 1>spcall.log
@rem the find command returns 0 when the string is found
find "Return Status = 0" spcall.log null
@if ERRORLEVEL 1 goto :nonzero_status
:success_status
...whatever

:nonzero_status
...whatever
Yes, that worked just fine!

Thank you very much.

Regards
Odd B
May 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eugene | last post by:
Hi Is it possible to use Visual Source Safe with SQL Server in order to keep track of all modifications done to stored procedures? What are the pros and cons ? Thanks, Eugene
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
9
by: Ronald S. Cook | last post by:
What do you guys think of abandoning stored procedures and writhing the SQL in code? I'm a little new to the debate and not sure I totally understand. From my command object, I can just select...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
12
by: Dooza | last post by:
I have a stored procedure that takes a number of inputs, does a bulk insert, and then outputs a recordset. When I run the stored procedure in Server Management Studio I also get a return value from...
4
by: jleeie | last post by:
Can someone help me, I'm going round in circles with this and my head is cabbaged ! I am using visual studio 2005 & VB & MS SQL 2005 I am trying to execute a stored procedure from within a...
3
by: devi thapa | last post by:
Hi, I am running one service in the python script eg like "service httpd status". If I execute this command in normal shell kernel, the return code is 3. But in the python script its return...
3
by: tvnaidu | last post by:
This is my build script, I calls this script from main build script, in case of SUCCESS, everything is ok, but in failure, I do "return 1", so that main build can cheque "$?" and based on that it...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.