2023 Oct 11 9:41 AM
(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?
2023 Oct 11 9:53 AM
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.
2023 Oct 11 9:53 AM
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.
2023 Oct 11 11:22 AM
Awesome, thanks!
(Found it: Page 179ff, 6.2.2. Aufzählungsklassen, German Version , 1st edition 2022) .
Will read that now.
2023 Oct 11 4:10 PM
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
2023 Oct 22 12:29 AM
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