cancel
Showing results for 
Search instead for 
Did you mean: 

Type cast error for char to int in HANA model

Former Member
0 Kudos

Dear Experts,

I am facing an issue while trying to convert a string to int and then casting it back to string.

My requirement is - User is providing an input parameter based on column of datatype VARCHAR. So here FiscalMonth = 2016-M05.

Now I am taking left 4 char of this to return 2016 as string. To calculate previous year I converted this to Int and substracted 1. and finally I casted

this to string and storing in calculated variable of data type VARCHAR.

Its showing me following error

I searched this issue on SCN but many of the posts are referring this to typecast using CE function/ I am trying to create a variable on graphical calculation model and need this to dynamically calculate previous year so that I can compare this previous year with transactional date's year (taken 4 chars of year from string of date)

Could you please guide me for its root cause fix.

Thanks & Regards,

Jiten

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

If you are still facing the issue,

You can break the formulas as below, and try in last formula, i know no point in elaborating the formulas but some times it works..

Create Int conversion seperate,

Create String conversion seperate. and Create leftstr seperate formulas, and in final try your desired requirement formula you can consider the (fiscalmonth -1...

I have faced such issue in SP 1.8, but the above way breaking the formula worked for me...

Dont know exact reasons behind it...

Hope it helps.

Cheers..

Answers (3)

Answers (3)

Former Member
0 Kudos

@Florian/Shireesha/Lajwanth - Thank you all for your suggestions. Appreciate it.

@Florian - We can do this by using Year and Month separately but user prefer to see the values in YYYY-MM format while selecting in Input_parameter.

@Shireesha - a. Removing single quote from input parameter throws 'mismatch error between input parameter and it data type'. b. User want to select/enter year-month to calculate specific month's comparision with previous month.

@Lajwanth - Yes, it works by doing separate conversion of Int, String. I used the same as workaround but wanted to know if I was missing something while conversion. As of now I am good to go with you suggestion !

With Regards,

Jiten

Former Member
0 Kudos

Hi Jiten,

Yes as Florian said the error messaged can be ignored, meanwhile you try this

1. Remove quotes of input parameter and validate

string(int(leftstr($$ip$$,4))-1)

2. Or any ways as you are calculating on a column's values, why can't you provide the column directly in expression as below

string(int(leftstr("FiscalMonth",4))-1)

Regards,

Shireesha

pfefferf
Active Contributor
0 Kudos

Hello Jiten,

although the validation expression functionality reports that error, the expression is working. Can you ignore the message, activate your view and test it.

Of course you will still get a "runtime" error if the first four characters cannot be converted to an integer. Is it an option for you to split the parameter into two parameters (one for the fiscal year and one for the fiscal month, typed to the right types to be type safe)?

Regards,

Florian