cancel
Showing results for 
Search instead for 
Did you mean: 

Union in CDS View with different columns

michael_vogel1
Explorer
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

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};

};

michael_vogel1
Explorer
0 Kudos

Hi Thomas,

I have a system on revision 93.

Your example is a bit different than my example. 

I want to have a column in the output, which is always null for entries of E1 and another column which is always null for entries of E2.

view UnionView as

  select from E1 {a, b, null as c}

  union

  select from E2 {a, null as b, c}

;

Here I get the error message "Feature not supported"

Regards,

Michael

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Then I'm guessing the error message is telling you that the null column union isn't supported. Have you tried it without the nulls to double check that this is the cause.

Although in my system I was able to get the union with the nulls to work just fine.


@nokey

entity E1A {a: Integer; b: Integer; };

@nokey

entity E2A {a: Integer; c: Integer; };

view VA as

SELECT from E1A { a, b, null as c }

  UNION

SELECT from E2A {a, null as b, c };

};

michael_vogel1
Explorer
0 Kudos

Hi Thomas,

it seems that you have a very actual HANA version. I have tested your code with revision 95, but still get the "Feature not supported" message. So I have to wait some weeks, until a revision which includes the feature is available.

Regards,

Michael

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Yes I can confirm that on my Rev95 system as well, I do receive a message with Feature not supported when using the Nulls in the Union. However the same syntax does work in newer internal builds.