ABAP CDS Enum declaration and accessing values

3 weeks ago 3

I americium trying to find however to entree the Values from Enum successful ABAP utilizing the pursuing example.

I person declared the pursuing Enum

@EndUserText.label: 'Enum Value' define benignant ze_testenum : abap.char(8) enum { UNKNOWN = initial; Sun = '7'; Mon = '1'; Tue = '2'; Wed = '3'; Thu = '4'; Fri = '5'; Sat = '6'; }

Next, I defined the pursuing View Entity

define presumption entity ZI_TestEnum arsenic prime from I_CalendarDate { cardinal CalendarDate, ze_testenum.#Sun arsenic Word } where CalendarDate = $session.system_date

The output of the CDS is

Juwin_0-1737988224823.png

Next, I updated the View explanation to:

define presumption entity ZI_TestEnum arsenic prime from I_CalendarDate { cardinal CalendarDate, ze_testenum.#Sun arsenic Word, cast(ze_testenum.#Sun arsenic abap.char(8)) arsenic Word2 } where CalendarDate = $session.system_date

The output of this CDS is:

Juwin_1-1737988323238.png

Next, I tried to usage the aforesaid method successful ABAP utilizing the pursuing class

class zcl_je_test definition public final make nationalist . nationalist section. interfaces if_oo_adt_classrun. protected section. backstage section. endclass. class zcl_je_test implementation. method if_oo_adt_classrun~main. out->write( ze_testenum-mon ). out->write( conv string( ze_testenum-mon ) ). endmethod. endclass.

Output of this people is:

Juwin_2-1737988586149.png

Here successful ABAP, casting doesn't person the worth of Mon to 1 dissimilar successful CDS View definition. Why this quality successful behavior?

I added the pursuing connection successful the Class

out->write( conv ze_testenum( '1' ) ).

Now the output of the people is

Juwin_3-1737988676181.png

I tried the aforesaid successful CDS presumption explanation by adding the pursuing statement

cast('2' arsenic ze_testenum) arsenic Word3

The output of CDS present is 

Juwin_4-1737988813523.png

In summary, I americium capable to:

  1. Print/Output Enumerated Constant Name successful some ABAP & CDS
  2. Convert Value to Constant Name successful some ABAP & CDS
  3. Convert Constant Name to Value successful CDS by Casting, whereas Casting successful ABAP codification doesn't person the value

Question(1) : Is casting the close method to entree the defined fixed values (Enumerated Values) from the CDS?

Question (2): How bash I person Constant Name to Value successful ABAP code?

Tagging blog proprietor present for amended reach @AndreaUS 

Read Entire Article