Skip to Content

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

Aug 18, 2017 at 08:18 AM


avatar image


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,
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.

Mat1 100 20 80 80
Ma2 200 0 0 0

Appreciate any help in this regard.

Thanks in advance!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Vartika Gupta Aug 18, 2017 at 11:29 AM

Issue solved!

Help link:

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

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

10 |10000 characters needed characters left characters exceeded