I have a code in which I use the check_adr method to check if the selected address is in the table. The following logic occurs inside the check_adr method:
Here's how I've currently implemented it. The problem is that lt_addr will not be empty since 1 line for lv_addrnum_dd will be selected there, that is, the check does not work correctly. How to check for the existence of both values if they are filled? I need to implement with a read table check for each non-empty field. How can I do that?
SELECT SINGLE addrnum_dd addrnum_pbd
INTO (lv_addrnum_dd, lv_addrnum_pbd)
FROM zfsltcase_agr
WHERE case_guid = iv_case_guid.
IF sy-subrc = 0.
IF lv_addrnum_dd IS NOT INITIAL AND lv_addrnum_pbd IS NOT INITIAL.
SELECT addrnumber
INTO TABLE lt_addr
FROM adrc
WHERE ( addrnumber = lv_addrnum_dd OR addrnumber = lv_addrnum_pbd )
AND date_from <= sy-datum
AND date_to >= sy-datum.
IF lines( lt_addr ) = 0.
lv_chk = abap_true.
ELSE.
lv_chk = abap_false.
ENDIF.
ELSE.
lv_chk = abap_false.
ENDIF.
ENDIF.
As you wrote, you will be able to check this with a READ command and not have to write 2 separate SELECTs. In addition, the line_exists() function may also come in handy, if it is already available to you. If not already, you may want to check the sy-subrc value after READ TABLE to see if it finds the specified field.
The problem would be that if the table contains the key value lv_addrnum_dd and does not contain the key path lv_addrnum_pbd, then lv_chk should be true. If I am correct, the following code should help you:
SELECT addrnumber
INTO TABLE lt_addr
FROM adrc
WHERE ( addrnumber = lv_addrnum_dd OR addrnumber = lv_addrnum_pbd )
AND date_from <= sy-datum
AND date_to >= sy-datum.
IF line_exists( lt_addr[ addrnumber = lv_addrnum_dd ] )
AND NOT line_exists( lt_addr[ addrnumber = lv_addrnum_pbd ] ) .
lv_chk = abap_true.
ENDIF.
I hope I have understood the problem you outlined correctly and I was able to help.