I have very HANA/SQLScript specified problem. I need to create a history view for each day in form of scripted calculation view based on table with dates gaps?
I tried every cross joins with "_SYS_BI"."M_TIME_DIMENSION" and just use Functions.
In my experience cross joins are ideal fro cumulative sum but not for showing single value.
HANA dont allow to use columns as a input parameters to table functions.
Scalar functions cannot be used in calculation view too. I can activate that view but i cannot read data from it. Even if function standalone works fine:
Business Partner Discount Table:
CREATE COLUMN TABLE "BP_DISCOUNT" ("BP_CODE" VARCHAR(50) NOT NULL ,
"DATE" DATE L ,
"DISCOUNT" DECIMAL(21,6);
insert into "BP_DISCOUNT" values('abc','20190101','0');
insert into "BP_DISCOUNT" values('abc','20190105','5');
insert into "BP_DISCOUNT" values('abc','20190110','10');
My function that i wanted to use in place of:
CREATE FUNCTION bp_discountF (BP_Code varchar(50), Date_D date)
RETURNS discount decimal(21,6)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
select "DISCOUNT" into DISCOUNT
from "BP_DISCOUNT" d
where
:BP_CODE = d."BP_CODE" and d."DATE"<= :DATE_D order by d."DATE" desc limit 1;
END;
My goal is to create a view that shows discount values for every possible day based on most recent value. It must be in form of scripted calculation view to join it to more complex sales report views.
Expected result is to join it on BP and document date:
...
'abc', '20190101', 0;
'abc', '20190102', 0;
'abc', '20190103', 0;
'abc', '20190104', 0;
'abc', '20190105', 5;
'abc', '20190106', 5;
'abc', '20190107', 5;
'abc', '20190108', 5;
'abc', '20190109', 5;
'abc', '20190110', 10;
'abc', '20190111', 10;
..