简体   繁体   中英

how to apply an aggregation function over a measure dynamically passed to a stored procedure?

I am trying to do spit by dimension on an analytic view within a stored procedure, and I want to pass the measure on which i will apply the aggregation function dynamically. So I did the following:

 create procedure procHO (in  currentMeasure varchar(60))
 language sqlscript as
 begin
 data_tab = select MONTH_NAME as ID, sum(:currentMeasure) from
 _SYS_BIC."schema/analyticView" GROUP BY MONTH_NAME;
 end;

then I call the procedure this way:

call procHO("MARGIN");

but I am getting an error saying :

inconsistent datatype: only numeric type is available for aggregation function: line 5 col 38 (at pos 124) Could not execute 'call procHO("MARGIN")'

I also tried to do this using CE_ functions, here is what i did:

create procedure procHO1(in currentMeasure varchar(60))
language sqlscript as
begin
out1 = CE_OLAP_VIEW("schema/analyticView", ["MONTH_NAME",  
SUM(:currentMeasure)]);
end;

and I call the procedure this way:

call procHO1("MARGIN");

but still, i am getting an error saying:

feature not supported: line 5 col 70 (at pos 157)
Could not execute 'call procHO1("MARGIN")'

by the way, as a workaround, it is possible to create a dynamic SQL query that would resolve the issue, here is an example: create procedure procHO2(in currentMeasure varchar(60)) language sqlscript as begin

exec 'select  MONTH_NAME AS ID, sum('||:currentMeasure||') as SUM_MEASURE from
_SYS_BIC."schema/analyticView" GROUP BY MONTH_NAME';
end;

I call it this way

call procHO2('MARGIN');

but I don't want to create the SQL query dynamically since its not recommended by SAP.

So what to do to pass an aggregated measure dynamically?

this is what the sample code from the documentation:

CREATE PROCEDURE my_proc_caller (IN in_client INT, IN in_currency INT, OUT outtab mytab_t) LANGUAGE SQLSCRIPT
BEGIN
outtab = SELECT * FROM CALC_VIEW (PLACEHOLDER."$$client$$" => :in_client , PLACEHOLDER."$$currency$$" => :in_currency );
END;

of course this works only on the latest release. Which revision are you running on?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM