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: 

ABAP CDS view not returning correct result for difference of two fields

Former Member
0 Kudos

Hi,

We have defined a CDS view ZOPEN_ORDERS (with some parameters) on VBAK/VBAP/VBFA/VBUP and MSEG tables to get the summarized delivery quantities and stock in transit for all materials . Result returned is like:

Material(MATNR) Delivery Quan(RFMNG) In transit (MENGE)
Mat1 100 20
Mat2 200 0

On top of this we have created another view to return the difference of the two columns RFMNG and MENGE as below:

define view ZOP_DDL with parameters
iv_werks : werks_d,
iv_atpchk : flaf,
iv_unres : flag,
iv_rw_stock : flag

as select from ZOPEN_ORDERS_DDL( iv_werks : $parameters.iv_werks , iv_atpchk : $parameters.iv_atpchk , iv_unres : $parameters.iv_unres , iv_rw_stock : $parameters.iv_rw_stock )

{ matnr,
rfmng as rfmng,
menge,
rfmng - ( cast (menge as abap.quan(15,3) ) ) as labst_pm,
rfmng - menge as labst_org }

The problem is that the second view does not return the difference of RFMNG and MENGE . Both LABST_ORG and LABST_PM are zero if MENGE is zero . Otherwise the result is correct.

MATNR RFMNG MENGE LABST_PM LABST_ORG
Mat1 100 20 80 80
Ma2 200 0 0 0

Appreciate any help in this regard.

Thanks in advance!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Issue solved!

Help link: https://archive.sap.com/discussions/thread/3877121

If an operand hasa null value, airthmetic operation results in null value as well. So used the following case statement for substraction.

case
when menge is null
then rfmng
else rfmng - menge
end as labst_pm

1 REPLY 1

Former Member
0 Kudos

Issue solved!

Help link: https://archive.sap.com/discussions/thread/3877121

If an operand hasa null value, airthmetic operation results in null value as well. So used the following case statement for substraction.

case
when menge is null
then rfmng
else rfmng - menge
end as labst_pm