cancel
Showing results for 
Search instead for 
Did you mean: 

CALCULATIONS ON TAGS WITH DYNAMIC FORMULAE

former_member1231563
Participant
0 Kudos

Hi SAPians,

I am using SAP 12.2 and my requirement is to perform calculations on TAGS according to some dynamically changing formulae.

For eg if we have three tags T1,T2 and T3 then the formulae can be (T1+T2)/T3 and calculation has to be done according to this formulae.

If  Tag T4 comes then the formulae can be (T1+T2+t3)/T4 or any other possible expression.

Is it possible to develop a generalised solution for calculating any dynamic expression(Like above) comming to SAP MII in the form of a string or some variable??

Any help would be highly appreciated.

Thanks

Praveen

Accepted Solutions (1)

Accepted Solutions (1)

austin_jacob
Explorer
0 Kudos

Hi Praveen,

You can use Calculated Columns action in the transaction to add a new column with any expression you want like ( (T1+T2+t3)/T4 ). This will be an extra column in the xml in addition to the original tags.

Regards,

Austin

Former Member
0 Kudos

Hi Praveen,

I am not sure what exactly you want to say by

"Is it possible to develop a generalised solution for calculating any dynamic expression(Like above) comming to SAP MII in the form of a string or some variable??"

But, just to add one pointer, may be it can help you, you can give the dynamic expression between #, e.g #(T1+T2)*T3/T4# to calculate its value dynamically.

Warm Regards,

Anuj

former_member1231563
Participant
0 Kudos

Hi Austin,

Thanks a lot for your response.

Can you please eloborate more with an example if its possible.

Thanks,

Praveen.

former_member1231563
Participant
0 Kudos

Hi Anuj,

Thanks a lot for your response!

What i meant by that was i need to extract all the tags for eg T1,T2 etc according to the dynamic varying formulae.So i want to have a generalised method by which i can extract any number of tags separtely into separate variables regardless of the formulae.

This tags will then be sent to SCADA database where a quantity and a UOM corresponding to these tags will be fetched and based on the value of the Quantity the formulae will be calculated(i.e.by replacing T1,T2 etc by the corresponding Quantity fetched) and the final value will be sent further.

I hope i have made the requirement clear.

Now can you please provide a solution to it if you have any.

Thanks,

Praveen.

former_member211944
Active Participant
0 Kudos

Hi Praveen,

How would you get these tag names for which you want to fetch the quantity and UOM from SCADA database?

Would the formula with tag names come as a string?

Basically you want to replace the tag names with the values coming from SCADA system and then calculate the value. Kindly let me know if my understanding is correct?

Regards,

Rohit Negi.

austin_jacob
Explorer
0 Kudos

Hi Praveen,

I would put what Rohit suggests in different words.

If you want the tag names to be dynamic. We can Map it to the TagName1, TagName2 etc properties of tag Query action in a transaction. But, What I understand is we cant dynamically pass an expression from outside to the calculated columns action block. You can only configure the expression. So what you can do is, you can list out the different possibilities of tag name combinations you are going to query and use a switch case to pass them to different Calculated Columns Action block which has appropriate formula in them.

Regards,

Austin

former_member1231563
Participant
0 Kudos

Hi Rohit,

Hope you are doing great!!

Yes,you have understood the requirement correctly!

Thanks,

Praveen.

former_member1231563
Participant
0 Kudos

Hi Austin,

Thanks again!!

I'l try to implement it as you mentioned and see whether it works out or not.

Thanks,

Praveen

Answers (1)

Answers (1)

former_member211944
Active Participant
0 Kudos

Hi Praveen,

Creating an action block could be a solution but it would be little more time consuming one.

I was thinking that you could create a generic logic in the action block like how to do the calculation when 3 parameters are passed or when 4 parameters are passed.

Input to the action block could be a Collection e.g. an array or list so that you can pass the parameters dynamically.

Using "Calculated Columns action" could be a solution but that you would have to change when the numbers of parameters change.

Do let me know if you have found any other solution.

Regards,

Rohit Negi.

Former Member
0 Kudos

Browsing the history .. it looks like SAP had a Demo on MII 12.0 which was doing some calculations.

Considering that a form was being filled with what defined a formula, the JS code was as follows:

function doUpdate() {

          var strExpr = document.frmMain.txtExpression.value;

          if (strExpr != "") {

                    var myQuery = document.CalculatedChart.getQueryObject();

                    myQuery.setTagName(1,document.frmMain.Tag1.value);

                    myQuery.setTagName(2,document.frmMain.Tag2.value);

                    myQuery.setTagName(3,document.frmMain.Tag3.value);

                    myQuery.setTagName(4,document.frmMain.Tag4.value);

                    myQuery.setUserParameter("Expression",strExpr);

                    myQuery.setUserParameter("C1",document.frmMain.txtC1.value);

                    myQuery.setUserParameter("C2",document.frmMain.txtC2.value);

                    myQuery.setUserParameter("C3",document.frmMain.txtC3.value);

                    myQuery.setUserParameter("C4",document.frmMain.txtC4.value);

...



document.CalculatedChart.updateChart(true);

}

}

The user parameters were defined to grab the expression itself and the coefficient values used in the formula (up to 10 coefficients, 4 in the example). Then a special XSL transform was applied on the tag query result (bringing the Tag1 to Tag4 values), namely IllumCalculator.xsl .. this is how it started ..

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:calc="http://www.lighthammer.com" extension-element-prefixes="calc" exclude-result-prefixes="xalan calc">

...


<lxslt:component prefix="calc">


<lxslt:script lang="javaclass" src="class:com.sap.xmii.Illuminator.ext.ExtFunctions"/>

</lxslt:component>

...

MII 12.1 (and after) does not have the setUserParameter() method anymore linked with the getQueryObject(). Now, The user parameters were practically pushing the "C1 .. C10" and "Expression" to the XSL, where xalan was called to evaluate the formula. Another component being used was the class mentioned above.

I'm thinking now .. can we replicate this with the tools at hand? If a transaction is used via xacute to generate all the "user defined parameters" in an xml result, one can apply the same XSL transform (or similar), providing that the javaclass can be still found ..

Cheers,

Paul.