on 11-06-2013 9:31 AM
Hello,
I'm trying to create a stored procedure that calls a StoredProcedure-view.
Question 1:
They can explain to me how I can call StoredProcedure-view using variables?
EXAMPLE:
--this works
EXEC 'INSERT INTO #TMP_GSP__MNOITT
SELECT * FROM GSP_PROC_MNOITT_VIEW
WITH PARAMETERS(
''placeholder'' = (''$$itemcode$$'',''' || :itemcode || '''),
''PLACEHOLDER'' = (''$$_level$$'',''0''),
''PLACEHOLDER'' = (''$$parent$$'',''-1''),
''PLACEHOLDER'' = (''$$parentqty$$'',''0''))';
--this NOT works
INSERT INTO #TMP_GSP_RECURS_MNOITT
SELECT * FROM GSP_PROC_MNOITT_VIEW
WITH PARAMETERS(
PLACEHOLDER."$$itemcode$$" => :itemcode ,
PLACEHOLDER."$$parent$$" => :parent,
PLACEHOLDER."$$parentqty$$" => :parentqty);
Question 2:
I can pass a NULL value to a nvarchar parameter?
In this example the parameter 'level' is integer and NULL received correctly, however the parameter 'parent' is nvarchar (5000) and receives an alphanumeric value 'null'.
SELECT * FROM GSP_PROC_MNOITT_VIEW WITH PARAMETERS(
'PLACEHOLDER' = ('$$itemcode$$', '02005300186401002116'),
'PLACEHOLDER' = ('$$_level$$', 'null'),
'PLACEHOLDER' = ('$$parent$$','null'),
'PLACEHOLDER' = ('$$parentqty$$','1'));
--this NOT works
SELECT * FROM GSP_PROC_MNOITT_VIEW WITH PARAMETERS(
'PLACEHOLDER' = ('$$itemcode$$', '02005300186401002116'),
'PLACEHOLDER' = ('$$_level$$', 'null'),
'PLACEHOLDER' = ('$$parent$$',null),
'PLACEHOLDER' = ('$$parentqty$$','1'));
I'm working with HANA PLATFORM Rev. 53.
Thank you very much.
You should judge the null value in the procedure.
insert into ldl_test values (1, 'abc');
insert into ldl_test values (2, 'xyz');
insert into ldl_test values (3, null);
create procedure proc_test(p1 integer, p2 nvarchar(100), out o1 ldl_test)
LANGUAGE SQLSCRIPT
READS SQL DATA
WITH RESULT VIEW ProcView
AS
begin
if p2 != 'null' then -- the 'null' parameter
o1 = SELECT * FROM ldl_test where x = :p1 and y = :p2;
else
o1 = SELECT * FROM ldl_test where x = :p1 and y is null;
end if;
end;
--query the common value
select * from ProcView WITH PARAMETERS('placeholder' = ('$$p1$$', '1'), 'placeholder' = ('$$p2$$', 'abc'))
--query the null value
select * from ProcView WITH PARAMETERS('placeholder' = ('$$p1$$', '3'), 'placeholder' = ('$$p2$$', 'null'))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adria,
--query the common value
select
* from ProcView WITH PARAMETERS('placeholder' = ('$$p1$$', '1'), 'placeholder' = ('$$p2$$', 'abc'))
You already tried it?
Your line with EXEC and the one wihout are quite different. In the case the sample here bellow doesn't answer your problem please share a sample where the EXEC line and the direct one are equal.
Regards,
Trinidad.
Hello,
I attach a simple example to understand my problem.
Thank you very much.
DROP TYPE TYPE_TEST;
CREATE TYPE TYPE_TEST AS TABLE ("ItemName" nvarchar(100));
DROP PROCEDURE TEST_CALL;
CREATE PROCEDURE TEST_CALL(in ItemCode nvarchar(20), out t_out TYPE_TEST)
LANGUAGE SQLSCRIPT READS SQL DATA WITH RESULT VIEW TEST_CALL_VIEW AS
BEGIN
t_out = SELECT "ItemName" FROM OITM WHERE "ItemCode" = :ItemCode;
END;
DROP PROCEDURE TEST_CALL0;
CREATE PROCEDURE TEST_CALL0 (in ItemCode nvarchar(20))
LANGUAGE SQLSCRIPT AS
BEGIN
--THIS WORKS
EXEC 'select * from TEST_CALL_VIEW WITH PARAMETERS(''placeholder'' = (''$$itemcode$$'', ''' || ItemCode || '''))';
--THIS NOT WORKS
--select * from TEST_CALL_VIEW WITH PARAMETERS(PLACEHOLDER."$$itemcode$$" => :itemcode);
END;
CALL TEST_CALL0('.');
Hello,
I found the solution to my incidence, first syntax was wrong this is the correct Syntax:
--THIS NOT WORKS
--select * from TEST_CALL_VIEW WITH PARAMETERS(PLACEHOLDER."$$itemcode$$" => :itemcode);
--THIS WORKS
select * from TEST_CALL_VIEW (PLACEHOLDER."$$itemcode$$" => :itemcode);
I found the information in this discussion: http://scn.sap.com/message/14392669
Thanks very much.
Adria:
Try adding a double quote for table name: i.e: "#TMP_GSP_RECURS_MNOITT".
On the null value - yes you can pass a null value to the column with data type nvarchar .
hope this helps.
Regarsds,
Rama
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Rama Shankar wrote:Try adding a double quote for table name: i.e: "#TMP_GSP_RECURS_MNOITT".
I'll return the following error (view last reply plis)
Rama Shankar wrote:On the null value - yes you can pass a null value to the column with data type nvarchar .
I appreciate your response, but I have specified that way I can pass a null value to a parameter nvarchar.
I test the following:
SELECT * FROM GSP_PROC_MNOITT_ITT1_VIEW
WITH PARAMETERS(
'placeholder' = ('$$returnalloittversions$$','N'),
'placeholder' = ('$$itemcode$$','02005300186401002188'),
'PLACEHOLDER' = ('$$_level$$','0'),
'PLACEHOLDER' = ('$$parent$$',null),
'PLACEHOLDER' = ('$$parentqty$$','0'))
I'll return the following error:
Could not execute 'SELECT * FROM GSP_PROC_MNOITT_ITT1_VIEW WITH PARAMETERS( 'placeholder' = ...' in 1 ms 949 µs .
SAP DBTech JDBC: [257] (at 238): sql syntax error: incorrect syntax near "null": line 6 col 32 (at pos 238)
That way I can define a nvarchar parameter as NULL?
Thanks very much.
Hi,
If I do not specify parameter '$$parent$$' this is the error message:
Could not execute 'SELECT * FROM GSP_PROC_MNOITT_ITT1_VIEW WITH PARAMETERS( 'placeholder' = ...' in 2 ms 147 µs .
SAP DBTech JDBC: [2048]: column store error: search table error: [34092] search on calculation model requires parameters;Required variable $$parent$$ is not set.
Thanks.
Hi,
Which the error messages are you getting?
Best regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.