2018 Aug 08 9:14 AM
Hello Experts,
as I know :
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
2018 Aug 08 9:53 AM
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.