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_dateThe output of the CDS is
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_dateThe output of this CDS is:
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:
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
I tried the aforesaid successful CDS presumption explanation by adding the pursuing statement
cast('2' arsenic ze_testenum) arsenic Word3The output of CDS present is
In summary, I americium capable to:
- Print/Output Enumerated Constant Name successful some ABAP & CDS
- Convert Value to Constant Name successful some ABAP & CDS
- 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