Preferred Boolean type for ABAP Development

Lilienthal picture Lilienthal · Mar 12, 2014 · Viewed 12.8k times · Source

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?

Answer

vwegert picture vwegert · Mar 12, 2014

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.