cancel
Showing results for 
Search instead for 
Did you mean: 

Error handling inside procedure

patrickbachmann
Active Contributor
0 Kudos

Hi folks,

I have a piece of code that is performing a value lookup for a single string in my procedure, and it's working great;

select fieldValue INTO tempVariable from myTable;

Then I use the results of tempVariable further down in my procedure.  The problem is that occasionally no value is found and then the entire procedure stops executing.  How can I add an error handler for this?  It's not like I can evaluate the value returned in tempVariable after this line executes because the line fails to complete.  I'm not finding anything in SQL guide but I'm in a rush so maybe i'm not looking in right place.

Thanks,

-Patrick

Accepted Solutions (1)

Accepted Solutions (1)

former_member182302
Active Contributor
0 Kudos

Hi Patrick,

In such cases, I initially used to get the COUNT first and keep it in a variable.

Then IF COUNT > 0 then i would allow other statements to follow else we can SIGNAL the exception.

Hope this helps.

Regards,

Krishna Tangudu

patrickbachmann
Active Contributor
0 Kudos

Khrishna,

This would not have worked yesterday as I could not step past the select statement without getting the null error.  Today i'm able to step past the select and so I added the logic similar to yours and is working fine.  I think the server was behaving eraticly yesterday and we have several problems with the indexserver in the past with it hanging and having to restart HANA.  Strangely this issue and another I just posted yesterday (fetch row error) are working this morning without me changing any code and without the server being restarted so I'm baffled!  So for now, thanks to you guys and I'm crossing my fingers we don't have more issues with this server.

Thanks,

-Patrick

Answers (1)

Answers (1)

sagarjoshi
Advisor
Advisor
0 Kudos

Hi Patrick,

Not sure what you would like to do after catching SQL Exception in this case. May be you give an example.

In general there are various ways to handle SQL Exception and is described in SQL Script guide.

http://help.sap.com/hana/SAP_HANA_SQL_Script_Reference_en.pdf

Please check chapter 7.6

Thanks,

Sagar