Skip to Content

CDS view issue (cannot get correct value from database)

Hi, experts

I define a CDS view to get records from table MCHB, but all of the clabs field equals 0 in the results. Actually, there are many records whose clabs > 0 in the database. The view is defined like this:

define view ZTEST001_11 as select from mchb
{
matnr,
charg,
lgort,
werks,
clabs
}

And if I add a where clause " where clabs > 0", the view will not be able to get any data. Is there any special restriction in CDS view whcih I am not aware of?

Add comment
10|10000 characters needed characters exceeded

  • Do you mean these statements?

    @AbapCatalog.sqlViewName: 'ZCI_TEST'
    @AbapCatalog.compiler.compareFilter: true
    @AccessControl.authorizationCheck: #NOT_REQUIRED
    @EndUserText.label: 'QAQ'
    define view ZTEST001_11 as select from mchb
    {
    matnr,
    charg,
    lgort,
    werks,
    clabs
    }

    or these?


    CREATE VIEW "ZCI_TEST" AS SELECT
    "MCHB"."MANDT" AS "MANDT",
    "MCHB"."MATNR",
    "MCHB"."CHARG",
    "MCHB"."LGORT",
    "MCHB"."WERKS",
    "MCHB"."CLABS"
    FROM "MCHB" "MCHB"

  • This looks OK.

    Just a hunch:

    Replace

    @AccessControl.authorizationCheck: #NOT_REQUIRED

    with

    @AccessControl.authorizationCheck: #NOT_ALLOWED

    Can you check the ST05 trace of your acces to the view?

    What is the result if you access the DB-view 'ZCI_TEST' directly instead of the CDS entity ZTEST001_11.?

  • The 'ZCI_TEST' has the same query results with 'ZTEST001_11' .

    I checked 'ZCI_TEST' in se16, the clabs is zero, too.

    After replacing '@AccessControl...' the results seems not change.

    This is the ST05 trace record of CDS view:

    This is the record of selecting from table MCHB

    Oh, it seems the real source is NSDM_V_MCHB...I replaced MCHB with it in the DDL, and it works fine now!

    Thank you very much.

    But now I think I should be careful to define a ABAP CDS view. Do you know how to avoid to write incorrect DDL statement in such case? If we must check whether there is a redirection, it will cost some time...

    2hqrv.png (14.6 kB)
    gubhb.png (16.0 kB)
  • Get RSS Feed

2 Answers

  • Best Answer
    Aug 11, 2017 at 09:07 AM

    Seem that's I had the right idea in the comments -> ST05.

    The result was not influenced by CDS access control, but ST05 showed that there seems to be a redirect.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 11, 2017 at 07:55 AM

    I did the following simple things:

    CDS view:

    @AbapCatalog.sqlViewName: 'KELLER1_CDS_V0' 
    define view kellerh_cds_view0
       as select from  
        demo_expressions
         { 
          id,
          dec3
        }; 
    

    ABAP program:

    DELETE FROM demo_expressions.
    INSERT demo_expressions
      FROM TABLE @( VALUE #( ( id = 'X' dec3 = '1234.567' )
                             ( id = 'Y' dec3 = '1234' ) ) ).
    
    SELECT *
           from kellerh_cds_view0
           INTO TABLE @data(result).
    
    cl_demo_output=>display( result ).
    

    No problem.

    RESULT

    ID DEC3

    X 1234.567

    Y 1234.0

    Can you do the same?

    Add comment
    10|10000 characters needed characters exceeded