Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preferred Boolean type for ABAP Development

Tags:

abap

SAP doesn't have a core Data Type for boolean values. Additionally, higher level boolean types in SAP typically have three states: true ('X'), false (' ') and unknown ('-').

Now obviously booleans are a cornerstone of a lot of my development work but I realised that I haven't been terribly consistent in my type (data element) usage. So far I believe these are the most common:

  • abap_bool: defined in the abap type-pool, unconstrained but constants are defined for true, false, unknown, yes and no
  • os_boolean: data element, Yes ('X') or No (' ')
  • xfeld: data element, True ('X') or False (' '), lacks a field label, described as a checkbox

In my code I've mainly used abap_bool as I can then work with constants instead of character values, not that I couldn't assign abap_true to an xfeld. However, I've been cautioned that this type pool might not always be available.

I'm now wondering about the best practices for boolean values, specifically:

  • Is there a preferred type that I should use?
  • Will using the abap type-pool cause issues in certain modules or scenarios?
  • Does the possibility of abap_bool containing an unknown or indeed any character value matter?
like image 771
Lilienthal Avatar asked Mar 12 '14 14:03

Lilienthal


People also ask

How do you declare a Boolean variable in SAP ABAP?

When working explicitly with truth values, use the type abap_bool as a substitute for a real Boolean data type. A data object declared in this way should have no values other than the relevant constants abap_true and abap_false (also abap_undefined).

Which data type will be used for Boolean?

A boolean data type is declared with the bool keyword and can only take the values true or false . When the value is returned, true = 1 and false = 0 .

What are the two Boolean data types?

The boolean value can be of two types only i.e. either True or False.

What is Abap_false?

Using abap_true and abap_false The type group abap contains a data type abap_bool of type char with length 1, and the constants abap_true and abap_false . These constants serve as substitutes for a real Boolean data type.


1 Answers

I use the type pool ABAP and its constants in coding. It should always be available, though you may have to include it manually on older systems. For dictionary elements, I prefer to create my own data elements using any of the default domains so that I can add descriptions to suit my needs. You can use WDY_BOOLEAN as well.

like image 154
vwegert Avatar answered Sep 27 '22 18:09

vwegert