Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Subtraction inconsistency

former_member214084
Participant
0 Kudos

Hi Experts

I have written cds view for budget report using BPJA & COSP tables.

So far everything is working as expected until last step where I encounter a weird behavior which I don't understand.

Final formula I am using to calculate the available budget is as below :

Budget(BPJA value) - Spend(COSP) = Available.

  • 100.00 - 0.00 = 0. 00 This is the issue, instead is should be 100.00 in Available
  • 100.00 - 20.00 = 80.00 This is working fine

Please point me to possible cause of this issue.

1 REPLY 1

pmhatre
Explorer

This is my personal observation, I noticed that the value you might see in Spend(COSP) in the CDS output might show as '0.00', but in general it would be either initial or null.

In order to avoid such situation, you need to check the value first and then perform the arithmetic operations:

case
when ( ( Spend(COSP) is initial or Spend(COSP) is null ) 
then Budget(BPJA value)
else
Budget(BPJA value) - Spend(COSP)
end as Available

You can also use the COALESCE function:

COALESCE((Budget(BPJA value) - Spend(COSP)), Budget(BPJA value)) as Available