2023 Feb 20 9:48 AM
I want to check if a record already exist in a table ( zcustomer ) by using it's primary key ( zzcustomer_no) before inserting a new record from the structure table ls_customer to actual table zcustomer. how do i do that?
2023 Feb 20 10:27 AM
you can use modify statement, which will internally check the entries before inserting into custom table zcustomer.
Modify zcustomer from ls_customer.
2023 Feb 20 9:54 AM
Hello,
You can use the code below:
SELECT SINGLE @abap_true
FROM scarr
WHERE carrid = @carrier
INTO @DATA(exists).
IF exists = abap_true.
cl_demo_output=>display( |Carrier { carrier } exists in SCARR| ).
ELSE.
cl_demo_output=>display( |Carrier { carrier } does not exist in SCARR| ).
ENDIF.
You can also check the following blog from keller.m - the ‘X’ in the select statement
2023 Feb 20 9:56 AM
Just read any already existing record with a simple SELECT statement. (or use a dirty ACCEPTING DUPLICATE KEYS or a dirty MODIFY)
But first check duplicate records in the internal table.
2023 Feb 20 10:27 AM
you can use modify statement, which will internally check the entries before inserting into custom table zcustomer.
Modify zcustomer from ls_customer.
2023 Feb 21 11:21 AM
The main question is...?
If you need to check if a record exists, the SELECT SINGLE option (as akmal1216 suggested) is the way to go. It's irrelevant WHY you want to check it.
If you need to check it because it's giving you an error while INSERTing, then you must think your process' requirements. What the customer asked for? If you don't care about the existing data, go for a MODIFY (as shantraj said), but it's a very dirty thing to do (as raymond.giuseppi points).
But the main problem here is your question.
And I will not point at the use of CAPS in the subject...