
This is my first blog post so I thought I would start with something simple – the ABAP existence check. Sometimes you just need to know if a record exists in the database. You don’t actually have to return any data from the database. This is a simple and elegant method to do so.
*&---------------------------------------------------------------------*
*& Report zmc_abap_existence_check
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmc_abap_existence_check.
SELECT SINGLE @abap_true FROM sflight INTO @DATA(lv_found)
WHERE carrid = 'AZ'
AND connid = '0555'
AND fldate = '20180531' .
CASE lv_found.
WHEN abap_true .
WRITE: / 'Record found' .
WHEN abap_false .
WRITE: / 'Record not found' .
ENDCASE.
The output of the program looks like this:

I found that this can speed up my code a lot in certain use cases. It’s nice and clean not having to declare a variable or work area and then filling it with data you’re not going to use.
Have fun.
Martin.