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: 

Error in CDS View

former_member195431
Participant
0 Kudos

In my program I am fetching a certain type of inbound IDOC which in 53 status and updating my custom table, for which I have written a select query which executes perfectly but gives me an error while executing as a DDL source.

Select Query in Program: -

DDL Source: -


Error:- Preceding INT2 field cannot be a key field.

Even though I haven't declare INT2 field as a key field, the view which is being created (after commenting field sdata) is considering that. Please help me fix this issue.

1 ACCEPTED SOLUTION

christian_seitel
Participant
0 Kudos

some additional explanation from F1 help on 'KEY'-statement in CDS-view:

KEY is used to define the current element as the key element of the current CDS entity. Any elements of a SELECT list can be defined as key elements. The key elements of the CDS entity are used to document the semantics of the data model. The addition key is ignored when the CDS view is activated and when accesses are performed in program executions.

More specifically, the key elements defined using KEY are ignored by the key of the CDS database view. Like in classic views, the key fields of the database view are derived implicitly from the key fields of the basis tables and the join conditions. If this is not possible, all fields of the database view are key fields.

4 REPLIES 4

christian_seitel
Participant
0 Kudos

Hi,

you would need to add additional fields to your CDS-view in a way that makes a key-calculation possible. E.g. the following CDS-view results in the above error:

define view ...

  as select from edid4

{

  dtint2,

  sdata

}

Now when you insert the fields

  docnum,

  counter,

  segnum,

before

  dtint2,

  sdata

then activation is possible !

There is F1-Help available at the Key-checkboxes of the DDIC view. Note that these Key-checkboxes are not related to the 'key' statement in the CDS-view.

christian_seitel
Participant
0 Kudos

some additional explanation from F1 help on 'KEY'-statement in CDS-view:

KEY is used to define the current element as the key element of the current CDS entity. Any elements of a SELECT list can be defined as key elements. The key elements of the CDS entity are used to document the semantics of the data model. The addition key is ignored when the CDS view is activated and when accesses are performed in program executions.

More specifically, the key elements defined using KEY are ignored by the key of the CDS database view. Like in classic views, the key fields of the database view are derived implicitly from the key fields of the basis tables and the join conditions. If this is not possible, all fields of the database view are key fields.

0 Kudos

Hello Christian,

Thanks for you inputs but the issue persists.

It worked for you because it was a single table in the example, but as mentioned in your second response " the key fields of the database view are derived implicitly from the key fields of the basis tables and the join conditions. If this is not possible, all fields of the database view are key fields." This is what exactly happening to my CDS View, all the fields are becoming key fields though I am joining to tables with their key fields.

Key fields in each of the tables: -

EDID4

DOCNUM--->Used to join

COUNTER

SEGNUM

EDIDS

DOCNUM--->Used to join

LOGDAT

LOGTIM

COUNTR(status)

EDIDC

DOCNUM--->Used to join

Thanks

Rajit

0 Kudos

Hi Rajit,

you are right, my simplified example only served the purpose of showing the basic principle, you would have to add several fields from several tables. This is inconvenient, but I think currently another workaround does not exist.
Regards, Christian