on 2022 Sep 01 2:17 PM
I'm playing arond with the BPC live API of SAC at the moment. I would like to write text + variable values to a popup. So basically this sounds very simple but does not seem to be because typecasting seems to be way more difficult in SAC script than in real programming languages where this is most of the time done automatically in modern languages.
var value1 = Table_1.getDataSource().getVariableValues('ICUPRN_0DISTR_CHAN_VERTRIEBSW1');
//Type Array
console.log(value1);
//should return one single value
var value2 = value1.pop();
console.log(value2);
//The result of pop in console log is: {value: '01', type: 'Single'} - so basically I would like to write the 01 in a text in the popupwindow
//The following command is not possible - Conversion VariableValue in String not possible - my assumption would be that it should not be difficult to cast a value '01' to string
cast(Type.string,value2);
//Write a text which is based on a static part and a variable. This meens 18 schould be dynamic and based on the variable above.
var variable = '18';
//TextArea_1 and Text_2 are belonging to a popup and should be dynamic
TextArea_1.setValue(variable);
Text_2.applyText(variable);
Popup_1.open();
This seems to be a very easy request but turns out to be not so easy. Any ideas on that?
Request clarification before answering.
This one took me to the right direction:
SAP Analytics Cloud - Application Design : Get Variable Value | SAP Community
The following seems to be the solution. Based on the fact that this should be an easy scripting language I have never seen such a bad approach in any progamming language. What your are getting in console log is as mentioned above when using .pop. jie.deng What's the idea of that approach if there is any?
{value: '01', type: 'Single'}
You can access type directly but not value. Based on the output above both should be directly accessible. But there are not.
Value is only available if you do the extra coding part below everytime and for every variable which you would like to access. Why does this not happen automatically in background?! So if SAC is not able to do automatic type casting ok - this is very old fashioned especially for a scripting language, but this is even more worse.
var value = Table_1.getDataSource().getVariableValues("V_Country")[0];
switch (value.type) {
case VariableValueType.Single:
var singleValue = cast(Type.SingleVariableValue, value);
console.log(singleValue.value); // can access the 'value' property now
break;
case VariableValueType.Multiple:
var multiValue = cast(Type.MultipleVariableValue, value);
console.log(multiValue.values); // can access the 'values' property now
break;
case VariableValueType.Range:
var rangeValue = cast(Type.RangeVariableValue, value);
console.log(rangeValue.from); // can access the 'from' property now
console.log(rangeValue.to); // can access the 'to' property now
// further range properties: 'less', 'lessOrEqual', 'greater', 'greaterOrEqual'
break;
default:
break;
}
There is no explanation of this part in the coding or help. // can access the 'value' property now
So why is not accessible without the extra step? If there are 90 types there should be one for for variables which are basically can handle single value (could an array with one value), multiple values (array). From / To could be the same usage than in ERP / BW from is used for single / multiple values an to is filled if it's a range. There is only one type needed for that.
What does SAC programmers do? Invent the wheel new in a realy bad way. This is absolutely not intuitive and time waste. So you have to handle all "range" properties in different ways just for accessing the properties. This is solved way better in ABAP (BW / ERP).
Another question: If I use ctrl + space there is no switch command. But it exists and it's working. So what is ctrl + space for if only some commands are shown it's useless.
Fun fact:
The output of of console.log(value2); "the lower script" and console.log(singleValue); "the upper script" is identical. For both the output is {value: '01', type: 'Single'}. But for the second one .value is existing / accessible, for the first one not. That's absolutely not intuitive so at least that should be visisble in the output in the console as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Torsten,
You can extract the value part of the variable by using the property ".value".
So basically this is how it would look:
var value2 = value1.pop();
and
String final_val = value2.value; (you can try seeing .value comes up or not by putting "." period operator and hitting Ctrl+space on the keyboard)
now you can use final_val which is a string.
Best Regards
Tharun.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Tharun,
I already tried this before posting. There is no ".value". When I use ctrl+space there is only type which I'm able to extract. But .value is not existing according to sac. "value is a not used property"
Best regards,
Torsten
torsten.wirth
SAC follows strict typecasting and is not similar to java script in that aspect. You can use below method of convertutils to convert number to string.
numberToString(value: number): string
Returns a string representation of the number value. If the value is undefined, then the string "undefined" is returned.Parameters
value:number
Returns string
stringToInteger(value: string): integerReturns the integer value represented by the string. If the string can't be parsed to a decimal integer, then NaN is returned.
Parameters
value:string
Returns integer
stringToNumber(value: string): numberReturns the number value represented by the string. If the string can't be parsed to a decimal number, then NaN is returned.Parameters
value:string
Returns number
Please upvote/accept if this helps
Nikhil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Nikhil,
you mean "ConvertUtils.numberToString" ? That does also not work for the abovementioned variable because in this case I'm getting invalid argument VariableValue (I think that's because it's a combination of type and value currently). So there are so many types in SAC. I never seen that in any programming language. If you create a new variable there are more than 90 types and a conversion util for three of them.
Best regards,
Torsten
User | Count |
---|---|
54 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.