Application Development and Automation 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: 
Read only

Data Objects for Truth and False Values

Former Member
0 Likes
2,847

Hello Experts,
as I know :

  • abap_true of value “X”
  • abap_false of value ” “
  • abap_undefined of value “-“.


But I don't know when we have to use them and which benefits they bring along, but today I have seen them in some coding like below as I think

TYPE-POOLS: abap.
DATA:
  lv_flag TYPE abap_bool value abap_false

  IF lv_flag EQ 'X'.
...
  ELSEIF lv_flag IS INITIAL.
...
  ENDIF.

  IF lv_flag EQ abap_true.
...
  ELSEIF lv_flag EQ abap_false.
...
  ENDIF.

can some when explaining to me the difference and the using of them with some

examples as why we do not write directly the loops.

Best Regards

Jenie

1 REPLY 1
Read only

matt
Active Contributor
1,778

It's to do with clarity of meaning - semantics. lv_flag is a bad name for the variable. Let's say it's used to indicate whether a report is run in test, or whether it does updates. You could then have something like this.

IF lv_flag EQ 'X'.
  " Write result to screen.
ELSE.
  " Write result to database
ENDIF.

Compare with this, where I've replaced lv_flag with a meaningfully named variable, and I'm using abap_true.:

IF in_test_mode EQ abap_true.
  " Write result to screen.
ELSE.
  " Write result to database
ENDIF.
 

The second example is much more readable. You know exactly what is happening.

Generally speaking, for fixed values, it's better to use meaningful constants. In ABAP abap_true and abap_false are supplied for this purpose. In later versions of ABAP, you don't even need to use the TYPE-POOLS:abap. statement.