cancel
Showing results for 
Search instead for 
Did you mean: 

Write variable values as text in popup

torsten_wirth
Participant
0 Kudos
2,857

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?

View Entire Topic
torsten_wirth
Participant

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.