Skip to Content
0
Sep 16, 2020 at 09:29 AM

Using another view instead of Service_Model convention

45 Views

Hi,

I have the following CDS in a CAP Java service, and such service is named "MasterDataService":

namespace sap.cre.core.view.model;
context Sites {
    //@cds.persistence.exists
    entity Site {
        key Irn : String(50);
        LongName : String(255);
        ShortName : String(30);
        virtual Intreno : String(40);
        Buildings : Composition of many Buildings.Building on Buildings.SiteRef=$self
    }
}


context Buildings {
    //@cds.persistence.exists
    entity Building {
        key Irn : String(50);
        SiteRef : Association to Sites.Site;
        LongName : String(255);
        ShortName : String(30);
        UsageTypes : Composition of many Buildings.BuildingUsageType on UsageTypes.BuildingRef=$self;
    }


    entity BuildingUsageType {
        BuildingRef : Association to Buildings.Building;
        UsageType : String(50);
        StartDate : Date;
        EndDate : Date;
    }
}

The model will automatically adopt view "MasterDataService_Building" from HANA to select fields as declared.

But I actually want to point it to another view, with a different name. Is that possible?

I tried to use something like this instead, but got a bunch of errors:

    entity Building as select from MasterDataService_Building_AnotherName  {
        key Irn : String(50);
        SiteRef : Association to Sites.Site;
        LongName : String(255);
        ShortName : String(30);
        SiteShortName : String(30);
        UsageTypes : Composition of many Buildings.BuildingUsageType on UsageTypes.BuildingRef=$self;
    }

Error:

[ERROR] db/schema.cds:15:36-63: No artifact has been found with name "MasterDataService_Building_AnotherName" (in view:"sap.cre.core.view.model.Buildings.Building")

Any idea?

Thanks!