cancel
Showing results for 
Search instead for 
Did you mean: 

HANA Calculation view random number

Former Member
0 Kudos

Hi there,

Basically, I'm trying to generate a random number for use in a CE_CALC function in my calculation view script.

This is my code:

     mc_proj = CE_PROJECTION(:mc_prac, ["LEADS_MIN", "LEADS_MAX",

     CE_CALC('"LEADS_MIN" + :rnd * ("LEADS_MAX" - "LEADS_MIN")', double)

     as "R_LEADS", "COST_MIN", "COST_MAX", "RATE_MIN", "RATE_MAX",

     "PROFIT_MIN", "PROFIT_MAX", "OVERHEAD"]);

rnd is supposed to be the variable that will hold my random number.

What's the best way to go about this?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Aakash,

I think that you can use RAND() function to generate random number, the RAND() will generate 0 to 1.0 number, but you only can use SQL statement to output, for example

create procedure RANDOM_NUMBER(out rand_num double) language sqlscript as

BEGIN

          select rand() into rand_num from dummy;

END

So you can update your procedure SQL without CE engine.

Hope this can help you.

Regards

Jerry

Former Member
0 Kudos

Hi Jerry, thanks for the reply.

I see what you mean. But I then need to use that generated number in my calculation view script. How do I call the procedure in my CV script and place the result into a variable that I can then use in my projection code above?

Sorry I've only just started using HANA so I may be asking stupid questions.

Former Member
0 Kudos

Hi Aakash,

I am not sure why you need to do this, however you can do it base on below script definition.

var_out = select

  "CUSTOMERID",

  "CUSTOMERNAME",

  "REGIONNAME",

  "CITYNAME",rand()*10000 as "SALESPRICE",

  rand()*1000 as "RANDOMNUMONE",

  rand()*1000 as "RANDOMNUMTWO"

  from "your schema"."table name";

Regarding as table structure and CV, please refer to below figure.

You can define yourself formula for random number.

Hope this can help you.

Regards,
Jerry

Answers (0)