Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
pallab_haldar
Active Participant
0 Kudos
863
In last session I have discussed about the normal exception handing using EXIT HANDLER .

In today's session I will discuss about the explicit creation of exception handling using Signal and Condition.

Using our HANA procedure we will check for valid Email ID. If email id is not valid we will signal an exception using condition.

1. Create the below procedures :

Crated a procedure in which first define the signal as condition and declare a exception handler using signal and the validate the email ID -
CREATE PROCEDURE "SE_DEV"."DEMO_WITH_SIGNAL_EXCEPTION" (
IN emai_id nvarchar(50),
OUT display_message nvarchar(300) )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER /* you can set it as DEFINER */
AS
BEGIN
/* Declaration of Exit Handler */

DECLARE SIG_HANDLER CONDITION FOR SQL_ERROR_CODE 12001;
DECLARE EXIT HANDLER FOR SIG_HANDLER
BEGIN
display_message := 'Error Code ' || ::SQL_ERROR_CODE || ' ' || ::SQL_ERROR_MESSAGE;
END;

/* Declaration End */

IF :emai_id <> '' AND :emai_id NOT LIKE '_%@__%.__%' THEN

SIGNAL SIG_HANDLER SET MESSAGE_TEXT = 'Not an Email id';
END if;

display_message := 'Vaild Email Id';

END;

 

2. Call the procedure using a Valid email ID -

CALL "SE_DEV"."DEMO_WITH_SIGNAL_EXCEPTION"('pallab.demo@gmail.com', ?);


3.  Call the procedure using a Invalid email ID  throw the explicit exception and produce the following output -

Calling code - CALL "SE_DEV"."DEMO_WITH_SIGNAL_EXCEPTION"('demo123gmailcom', ?);

Result -


 
Labels in this area