How to specify key in CDS view?

I defined a CDS view based on an entity. When I activate, it says:
Missing specification of keys for view "sap.ms.data::DB.ApplicationView".
However, I am at a lost how the specify key in CDS View. The developer guide did not mention anything. If I put a key before one of the attribute:
Cannot find sub artifact "key" in "Application"
My CDS view is as follows:
view ApplicationView as select from Application {
  ApplicationId,
  AccountRef.AccountId,
  DisplayName,
  Version

I found out how to do it, define the key in the service descriptor as:
service {
"sap.ms.data::DB.ApplicationView" as "App" key ("ApplicationId", "AcctId");

Similar Messages

  • CDS View: How to define JOIN in hdbdd file?

    Maybe I missed something, but how can I define JOINs for a CDS view in a hdbdd file?
    I have the following 2 tables and a view. The view claims that there is a syntax error on "left".
    I found no examples on how to JOIN in the documentation (only for ABAP).
    @Catalog.tableType : #COLUMN  
    entity Project {
    key ID      : Integer64 not null;
    Name        : hana.VARCHAR(64) not null;
    Description : hana.VARCHAR(256);
    @Catalog.tableType : #COLUMN  
    entity Scenario {
    key ID      : Integer64 not null;
    Name        : hana.VARCHAR(256) not null;
    Description : hana.VARCHAR(256);
    ProjectID   : Integer64 not null;
    view MData as select from Project left join Scenario on Scenario.ProjectID = Project.ID {
      Project.Name as Project,
      Scenario.Name as Scenario

    OK, I made some progress, but now I have the following problem:
    [1310081] No association with cardinality > 1 allowed in WHERE Clause
      @Catalog.tableType : #COLUMN   
      entity Project {
        key ID      : Integer64 not null;
        Name        : hana.VARCHAR(64) not null;
        Description : hana.VARCHAR(256);
        Scenarios   : association[*] to Scenario on Scenarios.ProjectID = ID;
      @Catalog.tableType : #COLUMN   
      entity Scenario {
        key ID      : Integer64 not null; 
        Name        : hana.VARCHAR(256) not null;
        Description : hana.VARCHAR(256);
        ProjectID   : Integer64 not null;
        Variants    : association[*] to Variant on Variants.ScenarioID = ID;
      @Catalog.tableType : #COLUMN   
      entity Variant {
        key ID      : Integer64 not null;
        Name        : hana.VARCHAR(64); 
        Description : hana.VARCHAR(256);
        ScenarioID  : Integer64 not null;
        TestTypes   : association[*] to TestType on TestTypes.VariantID = ID;
      @Catalog.tableType : #COLUMN   
      entity TestType {
        key ID      : Integer64 not null;
        Name        : hana.VARCHAR(64) not null; 
        Description : hana.VARCHAR(256);
        VariantID   : Integer64 not null;
      view MData as select from Project {
        Project.Name as Project,
        Scenarios.Name as Scenario,
        Scenarios.Variants.Name as Variant
      } where Scenarios.Variants.TestTypes.Name = 'SUT';

  • How to set key fields in a Database view

    Hi guru's
    iam balaji,plz guide me with how to set key fields in a view.......that field is a non key field in the base table....
    thanks in advance,
    Balaji.S

    take a look at this:
    Diagnosis
        In the view, not all of the mandatory fields were included as key
        fields. The key of the view therefore is not unique.
    System Response
        All the fields are regarded as key fields in order to guarantee that th
        key lengths are unique.
    Procedure
        For views with a large number of fields, this could have a negative
        effect on the performance for the language construction described below
        In this case, all the mandatory key fields should be included in the
        view.
    regards

  • How to specify  tablespace for a primary key inde in create table statement

    How to specify the tablespace for a primary key index in a create table statement?
    Does the following statement is right?
    CREATE TABLE 'GPS'||TO_CHAR(SYSDATE+1,'YYYYMMDD')
                ("ID" NUMBER(10,0) NOT NULL ENABLE,
                "IP_ADDRESS" VARCHAR2(32 BYTE),
                "EQUIPMENT_ID" VARCHAR2(32 BYTE),
                "PACKET_DT" DATE,
                "PACKET" VARCHAR2(255 BYTE),
                "PACKET_FORMAT" VARCHAR2(32 BYTE),
                "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP,
                 CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") TABLESPACE "INDEX_DATA"
                 TABLESPACE "SBM_DATA";   Thank you
    Edited by: qkc on 09-Nov-2009 13:42

    As orafad indicated, you'll have to use the USING INDEX clause from the documentation, i.e.
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE TABLE GPS
      2              ("ID" NUMBER(10,0) NOT NULL ENABLE,
      3              "IP_ADDRESS" VARCHAR2(32 BYTE),
      4              "EQUIPMENT_ID" VARCHAR2(32 BYTE),
      5              "PACKET_DT" DATE,
      6              "PACKET" VARCHAR2(255 BYTE),
      7              "PACKET_FORMAT" VARCHAR2(32 BYTE),
      8              "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP,
      9               CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") USING INDEX TABLESP
    ACE "USERS"
    10               )
    11*              TABLESPACE "USERS"
    SQL> /
    Table created.Justin

  • How to convert a timestamp to date/time in CDS View?

    Dear experts,
    I would like to convert a timestamp to a date and time within a CDS view.
    This is what I tried to do:
    Cast (Cast(<timestamp> as abap.dec(8,0)) as abap.dats) as <date>
    I also thought about first converting the timestamp into a plain numerical character, then using substring and then casting it to abap.dats. Then its giving me an error that says: "dec can't be converted into numc".
    The above written code also throws an error - "function not allowed/ no cast within a cast".
    It is quite nasty not being able to write a cast within a cast - how else am i supposed to achieve a date here?
    I am looking forward to have your answers!
    Thanks and BR
    Anja

    Hi Anja,
    what you try to do is currently not possible, a feature not available in CDS views.
    Yet it surely is a feature, ABAP developers would like to see on the feature request list .
    Cheers,
      Jasmin

  • How to select top one in CDS view ?

    I have tried following logic to select top one in CDS view but its giving error -
    define view Cds_View_First_Reference as select  top one CReferredObject from CDSVIEWCROSSREF

    Hi Ruchi,
    since you posted this question in "ABAP in Eclipse" I assume you are asking about CDS in ABAP. This is important because the CDS features sets in ABAP and (native) HANA are different.
    Be that as it may,, SELECT TOP 1 is neither supported in the CDS implementation in ABAP nor in HANA.
    In ABAP you might consider using the min() or max() function together with the appropriate GROUP BY clause in the CDS view (depending on what you want to achieve), but you can also easily "implement" this in the Open SQL statement which selects from your CDS view.
    Using the additions SELECT SINGLE or UP TO 1 ROWS and an appropriate ORDER BY clause in Open SQL, you can achieve the same as SELECT TOP 1.
    Unfortunately there is currently no possibility to define a view which delivers the TOP 1 which you can again use in another view ("view on view").
    Kind regards
    Chris

  • Union in CDS View with different columns

    Hello,
    I have two entities E1 {a: Integer; b: Integer} and E2 {a: Integer; c: Integer} and I want to build a CDS view which does a union on both like:
    SELECT a, b, null as c FROM E1
    UNION SELECT a, null as b, c  FROM E2
    I have written the following:
    view UnionView as select from E1 {a, b, null as c} union select from E2 {a, null as b, c}
    Now I get the error message: Feature is not supported
    Has anybody an idea, how to model this with a CDS view? With a graphical calculation view, this is possible, but I want to build it as a CDS view.
    Regards,
    Michael

    What revision is your system on?  I show that UNION was new syntax in SPS 09.
    http://help.sap.com/hana/SAP_HANA_Core_Data_Services_CDS_Reference_en.pdf
    I tried the following in my system and it worked just fine:
    namespace playground;
    @Schema: 'PLAYGROUND'
    context unionDemo {
        entity E1 {
      key a : Integer;
      b : String(20);
      c : LocalDate;
    entity E2 {
      key x : String(20);
      y : LocalDate;
      z : Integer;
    view V as
      select from E1 { a, b, c}
      union
      select from E2 { z, x, y};

  • Having a problem with creating/using a primary key on a view

    I have a problem with a primary key on a view
    I created the view and primary key as follows:
    CREATE OR REPLACE FORCE VIEW "MDD"."ROCK_LU" ("DESCRIPTION",
         UNIQUE ("DESCRIPTION") RELY DISABLE,
         CONSTRAINT "ROCK_LU_PK" PRIMARY KEY ("DESCRIPTION") RELY DISABLE) AS
    SELECT DESCRIPTION
    FROM MRMC_LU
    WHERE ROCK = 'T';
    The view with the primary key appears to have been created as there were no error messages. (The above was from the sql tab in sql developer.)
    When I try to create the foreign key on my mdd_hr table - I get an error
    /* hr_name - foreign key */
    ALTER TABLE mdd_hr add CONSTRAINT hr_name_fk FOREIGN KEY (hr_name) REFERENCES rock_lu(description);
    Error report:
    SQL Error: ORA-02270: no matching unique or primary key for this column-list.
    When I lookup the index in sql developer, rock_lu_pk is not there.
    All my other foreign keys work - but I don't understand what I am doing wrong with this one. Please help.
    glenn
    Background - as to why I want to use a view as a lookup table.
    The MRMC_LU table that the view is created from is structured like:
    DESCRIPTION - MINERAL - ROCK - MODIFIER - COMMODITY
    ANHYDRITE - T - T - T
    APLITE - T - - T
    GRAPHITE - T - - - T
    GREYWACKE - - T
    DESCRIPTION is a list of all names of minerals, rocks, modifiers and commodities. T is entered in each valid field. Often a description name is used for both a mineral and a rock or a mineral and a commodity or any other combination. Because this database is just starting up, it was more efficient to create one table that could be updated (and thereby automatically update the MINERAL_LU, ROCK_LU, MODIFIER_LY, COMMODITY_LU views) rather than create and maintain four separate but similar tables. A primary key cannot be generated for the MRMC_LU table as there are nulls in each column
    except DESCRIPTION.
    Perhaps there is a smarter way to do this?

    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_85a.htm#2065512
    You can specify constraints on views and object views. You define the constraint at the view level using the out_of_line_constraint clause. You define the constraint as part of column or attribute specification using the inline_constraint clause after the appropriate alias.
    Oracle does not enforce view constraints. However, operations on views are subject to the integrity constraints defined on the underlying base tables. This means that you can enforce constraints on views through constraints on base tables.
    Restrictions on View Constraints
    View constraints are a subset of table constraints and are subject to the following restrictions:
    You can specify only unique, primary key, and foreign key constraints on views. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.
    Because view constraints are not enforced directly, you cannot specify INITIALLY DEFERRED or DEFERRABLE.
    View constraints are supported only in DISABLE NOVALIDATE mode. You must specify the keywords DISABLE NOVALIDATE when you declare the view constraint, and you cannot specify any other mode.
    You cannot specify the using_index_clause, the exceptions_clause clause, or the ON DELETE clause of the references_clause.
    You cannot define view constraints on attributes of an object column.
    Rgds.

  • How can I get the old view of iCal back on my MacBook Pro and iPhone?

    How can I get the old view of iCal back on my MacBook Pro and iPhone?  The Mavrick version is crisp and clean but a colored dot is not the same as a highlighted word. I rely on my iCal on my MacBook Pro and iPhone 5 to help me track which of the 8 sites I visit for my job during the week - the color coding is (was key) to organizing and tracking meetings.  I hate the upgrade! 

    If purchased through the Mac App Store then it can be installed on up to five authorized CPUs. Otherwise, it's controlled by the license that came with the software.
    To install on another computer copy the downloaded installer application to the other computer.

  • No table entries found for specified key

    Hi All,
    I have developed a program to upload data from flat file with the help of GUI UPLOAD. It is succesfully updating data in my Z-table.
    Whenever I tried to view the content of table for specific field, message shows No table entries found for specified key. However if I add * as a suffix, it shows the data & when I directly Execute table it also displays the data.
    I have also cross checked the spaces before or after the specific content, no space found.
    Only two fields are creating this issue Individually (one of them is key field)
    Regards
    Mukul Maheshwari

    Hi Dear ,
    Here i had implemented program go through it you can understand easily.
    While creating table give one field as primary as you know that.
    tables zdata1.
    data it_tab type TABLE OF zdata1 WITH HEADER LINE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = 'C:\Documents and Settings\E50039\Desktop\data.txt'     ***************File path
       HAS_FIELD_SEPARATOR           = 'X'
      TABLES
        DATA_TAB                      = it_tab
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT it_tab.
    zdata1-no1 = it_tab-no1.
    zdata1-name = it_tab-name.
    zdata1-empid = it_tab-empid.
    insert zdata1.
    ENDLOOP.
    Flat file
    1 name1 empid1
    2 name2 empid2
    note: Give the tabspace between values in flat file.
    Edited by: Aditya.G on Oct 12, 2011 10:22 AM

  • How to get key and text value of field "TNDRST" in VTTK from R/3 into BI

    There is one field call "TNDRST(Tender Status)" in SAP table VTTK in R/3. We can find  key value, but we are unable to find text for this field in VTTK. However we can see text value if we double click domain:TNDRST and go to value range.
    Questions, how to get key value and text of TNDRST together in BI. Do we need to create a master data source for TNDRST text information in R/3 and extracting into BI, if yes, how to? Are there any easy way to do it??
    Thanks,
    Sudree

    Hi Sudree,
    You need to create a generic Text Datasource to extract this information into BI System.
    1. Create a generic DS based on Table: DD07T
    2. The fields should be put in the extract structure.
              DOMNAME (Make this as Selection in the DS ) -
    Filter the Domain Name
              DOMVALUE_L -
    Key Value of Tender Status
              DDTEXT -
    Text / Description
              DDLANGUAGE -
    Language
    3. DD07T is the table with all the Domain names & their values, so in the Infopackage enter the Selection Value for DOMNAME as 'TNDRST' and then run it.
    Or you can create a view out of this table based on DOMNAME filter as 'TNDRST'.
    Regards,
    Chathia.

  • Using HANA SQL Functions in select list of CDS Views

    Dear Expert,
    Kindly please let me know if we can use the HANA SQL Function (Ex: ADD_DAYS, SECONDS_BETWEEN) in the select list of CDS Views?
    If I create a CDS like below I get error that timestamp is not supported.
    For Example:
    @AbapCatalog.sqlViewName: 'ZMR_H_CA'
    @EndUserText.label: 'CAG A'
    define view viewname
    with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
    as select from table {
    key resource_key,
    TO_TIMESTAMP(begtstmp) as start_tmp,
    TO_TIMESTAMP(begtstmp) as end_tmp
    where
    (begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
    and
    (begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
    Thanks,
    Giri

    Hi Giri,
    the list of provided features can be found in the ABAP Language Documentation (F1 in the CDS View).
    As CDS in ABAP is abstracted from the database layer, the database features are not directly accessible. That means, you cannot use any HANA or MaxDB feature available. So the answer to your question is no. The reason for this is, that ABAP CDS views can be created on all SAP-supported databases, hence, we can only provide those features, supported by all databases.
    Having said this, there are some exception, e.g. the CDS views with input parameters, which are not supported by all databases. In these cases, you'd have to additionally use the utility class CL_ABAP_DBFEATURES (see http://scn.sap.com/community/abap/blog/2014/10/10/abap-news-for-740-sp08--abap-core-data-services-cds) for more details.
    Best,
      Jasmin

  • Questions on CDS Views with input parameters

    Dear Experts,
    1. Can we call a CDS View (or generated database view) with input parameters inside an AMDP? I am looking for something similar to the feature in HANA where we can consume calculation view with filters inside SQL Script?
    2. I understand we can next CDS Views, but how we can next (call) a CDS View with input parameters inside another CDS View?
    Thanks,
    Giri

    Hi Thomas,
    I get the below error that the CDS View's generated table function cannot take field from AMDP.
    I have a requirement to query the CDS View using 2 timestamps (start & end). So, in AMDP I have used the TIME_STAMP and try to pass it to the CDS View
    View code:
    define view Z_Ngi_Cag_A
    with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
    as select from table {
    resource_key
    where
    (begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
    and
    (begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
    I am calling using the below AMDP:
    DECLARE iv_start_date TIMESTAMP;
    DECLARE iv_end_date TIMESTAMP;
    SELECT CURRENT_TIMESTAMP INTO iv_start_date from dummy;
    SELECT ADD_DAYS(CURRENT_TIMESTAMP, 30) INTO iv_end_date from dummy;
    et_data =      SELECT * FROM ZMR_H_CA ( start_ts => iv_start_date, end_ts =>  iv_end_date );
    What could be wrong ? Is this not supported?
    Thanks,
    Giri

  • Error in CDS View

    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.

    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

  • Query on CDS Views and AMDPs

    Hello,
    I have few basic questions on CDS views and AMDPs:
    1. How do we identify the potential candidates in existing code where CDS views or AMDPs can/should be used for code-push down? Are there any recommendations?
    2. Should CDS views or AMDPs be used only for cases where we have data intensive calculations or they can be used as alternative to performance optimization techniques like to replace scenarios where multiple SELECTs or JOINs are used etc.?
    3. A CDS view internally can also contains a SELECT statement with JOINs. How does this help improve performance? I can just write the same SELECT in a CDS view and it will improve performance because the processing is at DB level? Is that a valid argument?
    Best Regards,
    Mohit

    Dear Mohit,
    as mentioned by Thomas: "There is no difference in performance between Open SQL and CDS views". The decision whether you want to use a CDS views instead of Open SQL is mainly based upon the question how you want to structure your coding. For instance, if a specific select appears multiple times in your coding you may decide to wrap it into a class-method and then call this class-method instead. Then in your coding there would be only a single instance of this select. Another option would be to wrap this select into a CDS-view and then select from this view instead of calling the class-method. The single instance of your select would then be stored in the CDS-view. If it comes to testing the view might have some additional advantages, e.g. you may use SE16 to browse its data. All this is not related to performance.
    Regards, Christian

Maybe you are looking for

  • Unable to connect to an instance using EM but connecting fine with SQL*Plus

    Good morning, I followed these steps (from the 2 Day DBA document): 1. I created a template (including database) from an instance named "orcl" using DBCA, before proceeding to create the template, DBCA informed me that the instance would be shutdown,

  • Rollback / savepoint Issue

    Hi, I'm a little confused on how the rollback to savepoint works in the database. A transaction statement such as Rollback fires an internal commit. Does the command : Rollback to savepoint <savepoint name> also issues an implicit commit? I did the f

  • ABAP Vs Object oriented programming

    Dear Friends, Its been almost 5 years I'm working as ABAPer. I have worked in almost all the areas of ABAP Programming except ABAP Objects(other than using ALV functinlaity some times). I was trying to understand SAP's objects and the more i read or

  • Help! iPod not synch'ing completely

    Just noticed that my iPod doesn't completely synch with my Mac. For example, the Beatles album '1' has 27 tracks. They're all in my iTunes. When I update my iPod (manually, for all checked tracks), only 16 of the tracks from the album '1' are transfe

  • Has anyone successfully set up SSL email in thunderbird?

    [regarding dsl, not fios] It may be  that I have a more complicated than usual proxy situation - I already do a lot of online work on secure and anonymizing networks. Still, when after ignoring verizon's instructions for some months I finally got aro