Application Development and Automation 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 - Data Inconsistency

Former Member
0 Kudos
5,163

Hello All,

I have created a simple CDS view with a select on MARD.

define view zmat_stk_view
  as select from mard
{
  matnr      as material_no,
  werks      as plant,
  lgort      as sloc,
  labst      as un_stk
}
where
  matnr = 'X00088337'

When I execute this CDS, the data I get is as following. Please see the highlighted unrestricted stock(un_stk) for storage location(sloc) = 1000.

When I see in se16n, labst value = 100 for for sloc = 100.

Has any one else face this issue? Any suggestions/guidance is much appreciated.

1 ACCEPTED SOLUTION

retired_member
Product and Topic Expert
Product and Topic Expert
2,985

Seems that there is a replacement object defined in SE11 for MARD.

13 REPLIES 13

Former Member
0 Kudos
2,985

Try below.

define view zmat_stk_view

as select from mard {

Key matnr as material_no,

Key werks as plant,

Key lgort as sloc,

labst as un_stk

}

where matnr ='X00088337'

retired_member
Product and Topic Expert
Product and Topic Expert
0 Kudos
2,985

What should that change?

retired_member
Product and Topic Expert
Product and Topic Expert
0 Kudos
2,985

Are you sure that you work with the same client?

What is the result when you access the CDS view with Open SQL and the table with an equivalent Open SQL SELECT in an ABAP program?

0 Kudos
2,985

Hi Horst,

I can confirm that I am working on the same client.

SELECT matnr,
werks,
lgort,
labst
FROM mard
INTO TABLE @DATA(lt_mard_data)
WHERE matnr = 'X00088337'.

SELECT *
INTO TABLE @DATA(lt_mard_data_cds)
 FROM zmat_stk_view.

I wrote the above select statements in a program.

The select on MARD works correctly but the one on CDS is still returning incorrect value.

0 Kudos
2,985

Strange. Could you please also show the view annotations?

What happens if you access the CDS DB view?

0 Kudos
2,985

Annotations are :-

@AbapCatalog.sqlViewName: 'ZMAT_STK' 
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Material Stock'

The data is incorrect in the cds db view also.

I got the same incorrect data when I tried accessing the cds view from the SQL Console.

0 Kudos
2,985

Now, we have to compare the ST05 traces of the above SELECT statements of your ABAP program. There must be a difference.

0 Kudos
2,985

Hi Horst,

ST05 trace is as below.

0 Kudos
2,985

Uh-huh, see the object names. The first SELECT doesn't access MARD.

There must be a replacement object defined in SE11 for MARD.

retired_member
Product and Topic Expert
Product and Topic Expert
2,986

Seems that there is a replacement object defined in SE11 for MARD.

0 Kudos
2,985

Thank you Horst!

I changed it from MARD to the replacement object in my cds view and it worked like a charm.

Happy New Year!

Best,

Aashrith.

0 Kudos
2,985

Shukria!

We were facing exactly same issue and resolved it exactly as above.

Cheers.

former_member579519
Participant
0 Kudos
2,985

Go to SE11--> Extras--> Replacement Objects

Replace table as nsdm_e_mard in view