on 03-29-2022 2:34 PM
We are trying to calculate the sum using the SAP Business Rule Capability in BTP but it is yielding a validation error on the data type. The correct data type is used.
We have created a rule that allows input of user types with a conversions to FUE based on factor held in a decision table
the end result should provide data for each type of use and 1 total
our current rule allows entry of different user types and returns them as a table.
see below input payload provides METRIC_IN_TAB
{"RuleServiceId": "sjhbsjhbxshbdcljkdnldkcn","Vocabulary": [{"METRIC_IN_TAB": [{"METRIC_ID": "CLOUDZ46","INPUT_METRIC": "SSUSER","QUANTITY": 900},{"METRIC_ID": "CLOUDZ46","INPUT_METRIC": "DEUSER","QUANTITY": 100},{"METRIC_ID": "CLOUDZ46","INPUT_METRIC": "ADUSER","QUANTITY": 800
},{"METRIC_ID": "CLOUDZ46","INPUT_METRIC": "COUSER","QUANTITY": 400}]}]}
Output Payload provides METRIC_OUT_TAB
{ "Result": [ { "METRIC_OUT_TAB": [ { "INPUT_METRIC": "SSUSER", "NUM_FUE": 18.0 }, { "INPUT_METRIC": "DEUSER",
"NUM_FUE": 50.0 }, { "INPUT_METRIC": "ADUSER",
"NUM_FUE": 1600.0 }, { "INPUT_METRIC": "COUSER",
"NUM_FUE": 400.0 } ] } ]}
We Need to create a second rule with a result structure for a sum rule which creates a total of all the NUM_FUE values.
We created a Rule with no result structure which has the following logic in the Update sum function where total FUEs is a numeric element.when we va;idate this rule we get the following error Validation for rule has failed.In the branch If, the condition contains an invalid expression. Incompatible datatype with content METRIC_OUT_TAB.NUM_FUE
we also tried using total FUEs as a result
with the following function and this gives the error
Validation for rule has failed. In the branch If, the condition contains an invalid expression.
we also noticed in our rule set that it is not possible to specify more than 1 result vocabulary only input is possible for total FUEs
can anyone suggest a fix
thanks
L Harris
We have now resolved this with the Help of Archana.
Here are the Key points we discovered.
A rule service can only have 1 output structure, so we had to rethink the way we get the total and put it in the same output structure.
originally the rule contained a for each metric in statement
the for each function was as follows:
for each input record we updated NUM_FUE with a calculation based on the input metric, and each input metric was also copied from input to output. These are updated into a temporary structure that matches the output table structure.
then the temp structure was appended to the output table.
So we added 4 lines of code
line 1 sums the number of FUES from the METRIC_OUT_TAB and saves it in an element total FUEs.
Line 2 was updating the text 'Total' in the output temporary structure in the input metric field.
line 3 adds the Total FUEs to the to NUM_FUE field of the Temp Output structure
then line 4 appends the temp output structure into the table.
then from the same input we get the following output which now includes a total line:
{
"Result": [
{
"METRIC_OUT_TAB": [
{
"NUM_FUE": 18.0,
"INPUT_METRIC": "SSUSER"
},
{
"NUM_FUE": 50.0,
"INPUT_METRIC": "DEUSER"
},
{
"NUM_FUE": 1600.0,
"INPUT_METRIC": "ADUSER"
},
{
"NUM_FUE": 400.0,
"INPUT_METRIC": "COUSER"
},
{
"NUM_FUE": 2068.0,
"INPUT_METRIC": "Total"
}
]
}
]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.