Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

How to do a WHILE DO loop on data from a SQL Calculation View

$
0
0

I would like to do a WHILE DO loop, I am pulling columns from a SQL Calculation View to Do the iteration. I want to start with a value AD = 2 and iterate until a condition is met. In addition to the columns I pull in, I also need to calculate 6 new columns (AT1, AU, AE, X, AV, and V). These columns could be combined into one but I have been keeping them separate to keep the final formula for V shorter.  These values will change as a function of AD until the condition for V is met. I can pull in the columns from my SQL Calculation View, I just am not able to iterate.
My code looks something this (I have simplified the formulas some to make it shorter) but it gives you an idea what I am trying to do.
DECLARE AD DOUBLE := 2;
WHILE :V > 0 DO
SELECT MATNR, WERKS, YEAR1, AVG_QUANTITY, STDDEV_QUANTITY,
AVG_ACTUAL, STDDEV_ACTUAL, STDDEV_YIELD, ZSTCT, LOSFX,
ZSTCC, LGRAD, VERPR, LKOST, ITERATION, DEMAND_TERM, DEMAND_TERM_SQD,
SUPPLY_TERM, SUPPLY_TERM_SQD, YIELD_TERM, YIELD_TERM_SQD,
SUM_OF_SQUARES, STDDEV_DEMAND_LT,
AT1 := ((:AD)/(STDDEV_DEMAND_LT)),
AV := (SQRT(20/POWER( :AT1 ,2))),
AU := ((5.6211054 * :AV) + (-3.883683 * (POWER(:AV,2)))),
AE := (STDDEV_DEMAND_LT)* :AU,
X := :AE/(52*(AVG_QUANTITY)),
V := ((:AD+ITERATION)-:AD)*((1-ZSTCT)+(ZSTCC* :X))
FROM "_SYS_BIC"."sts/SQLEPQ1";
IF :V < 0 THEN
INSERT INTO "_SYS_BIC"."sts/SQLEPQ2" VALUES (:AD);
END IF;
AD := :AD+ITERATION;
END WHILE;
I keep getting an error "Internal deployment of object failed;Repository: Encountered an error in repository runtime extension;Internal Error:Deploy Calculation View: SQL: sql syntax error: incorrect syntax near "DECLARE": line 8 col 1" . I have tried many ways and get errors around the DECLARE or WHILE.
If there is a better way - I am open

Thanks

 


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>