Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

(How) can I use the Value Range / Fixed Values from ( SE11 ) domains as constants in my ABAP Code ?

joachimrees1
Active Contributor

(How) can I use the Value Range / Fixed Values from ( SE11 DOMA) domains as constants in my ABAP code ? What is good practice ?

Example: Z_MY_DOMAIN, tab Value Range, Fixed Values:

Y yes
N no

What I cloud do is just this:

DATA: ls_my_data type Z_MY_DOMAIN . 
Constants: C_YES type C value 'Y'. 
Constants: C_NO type C value 'N'. 

Case ls_my_data . 
when C_YES .
...
when C_NO .
...
endcase. <br>
But it brings with it the problems of having to keep my code constants and the domain values in sync, manually. (Think: later introducing C_MAYBE or changing Y + N to 0 + 1 ). What is a good way tho handle this?
1 ACCEPTED SOLUTION

matt
Active Contributor

Check out enumeration classes in the Clean ABAP book (may also be in the Clean ABAP git repository). There is an example of an enumeration class based on domain values, that includes ABAP Unit test to make sure it's consistent with the domain.

4 REPLIES 4

matt
Active Contributor

Check out enumeration classes in the Clean ABAP book (may also be in the Clean ABAP git repository). There is an example of an enumeration class based on domain values, that includes ABAP Unit test to make sure it's consistent with the domain.

joachimrees1
Active Contributor

Awesome, thanks!

(Found it: Page 179ff, 6.2.2. Aufzählungsklassen, German Version , 1st edition 2022) .

Will read that now.

Sandra_Rossi
Active Contributor

Interesting. I would like to know more without purchasing the book 😉

Found it too, chapter 6.2 Constants, Clean ABAP: A Style Guide for Developers

By: et al., Klaus Haeuptle

Publisher: Rheinwerk Publishing Inc. © 2021

GeovanaLettnin
Product and Topic Expert
Product and Topic Expert

Dear joachim.rees3,

We helped you to accept the answer, since there were no updates after 7 days.

You can unaccept it anytime if the answer provided was not helpful enough and you have further questions.

Best regards,

Geovana