on 11-14-2021 8:32 PM
Hi,
I am trying to fill a structure that basically only has an ID and a percentage for an OData Service. All values come out of tables that are already part of the OData service, however the percentage is missing.
The OData Service is for a Fiori-application.
When I am tryng to calculate the percentage a error message is shown (roughly translated) it says:
"The operators DIV and MOD cannot be used in an expression that contains real decimal numbers such as X." with X being one of the two numbers I need for the calculation.
Because of our old system I can't use CDS Views.
The code is basically like this:
SELECT table1~id, DIV( table2~X, table2~Y) AS percentage
FROM table1 JOIN table2
ON table1~id EQ table2~id<br>INTO CORRESPONDING FIELDS OF TABLE @ET_ENTITYSET.
That's why I wanted to ask if someone got an idea how to solve it and can give me a hint.
Thanks in advance!
Philipp
Hey, just wanted to say
I just wanted to say that I got a solution for the problem now:
LOOP AT et_entityset ASSIGNING FIELD-SYMBOL(<ls_entity>).
IF ( <ls_entity>-y <> 0).
<ls_entity>-percent = <ls_entity>-x / <ls_entity>-y.
ELSE.
<ls_entity>-prozent = 0.
ENDLOOP.
After the select statement.
Just in case someone gets similar problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ptvoss,
dependend of the datatype (decimal places) you need to choose the function division instead of div.
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abensql_arith_func.htm
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abensql_expr_arith_abexa.htm
Alternative, you can try
select ...
CAST( table2~X as FLTP) / CAST( table2~Y as FLTP) AS percentage
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thorsten,
sadly I can't use division because it doesn't seem to be useable in open SQL only in abap cds, which isn't usable for me ...
When I tried using this:
select ...
CAST( table2~X as FLTP) / CAST( table2~Y as FLTP) AS percentage
The error message:
"The database field or the result type of the aggregate function X and the component "percentage" of "ET_ENTITYSET" are not compatible." shows up.
I already tried changing the EDM-Coretype, which was of no use.
Could it may be possible to use "loop at" to calculate the percentage after the select?
Hi Thorsten,
I don't know where to find that, but shouldn't it be the same as the one in the structure I am using for that entityset?
In that case it would be NUMC, could that be the problem? The structure was used for a dynpro application before and I am recycling it because I am using most of the data used to fill that structure.
User | Count |
---|---|
78 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.