‎2021 Feb 28 7:13 AM
I am using two table zle_ca_id_tmp and likp.My requirement is create a program and below logic
If ZLE_CA_ID_TMP.VBELN is not in LIKP.VBELN then delete the row the zle_ca_id_tmp in a single shot.
This should be done in a single read statement in my requirement.
I am using the below code and facing a issue in select and delete statement.Kindly please help in modifying with the correct query.
Situation
table zle_ca_id_tmp has 12,500,000 rows and table likp has 700,000 rows
we have two tables zle_ca_id_tmp and likp so do one read using both tables.
Create a new program with the below
If ZLE_CA_ID_TMP.VBELN is not in LIKP.VBELN
Then delete the row from table ZLE_CA_ID_TMP
Either if the outbound delivery no longer exists in LIKP then delete it from table ZLE_CA_ID_TMP Or if the outbound delivery exists in LIKP then leave it alone in the table ZLE_CA_ID_TMP
This should clear about 12 million rows.
LIKP contains lots of deliveries which are not present on table ZLE_CA_ID_TMP
Therefore
My code:
SELECT a~vbeln INTO TABLE li_zle_ca_id FROM zle_ca_id_temp AS a WHERE NOT EXISTS ( SELECT b~vbeln FROM likp AS b WHERE b~vbeln = a~vbeln ) .
IF sy-subrc = 0.
DELETE zle_ca_id_temp FROM TABLE li_zle_ca_id.
COMMIT WORK.
Can you please help in modifying the query for my requirement.
‎2021 Feb 28 7:13 AM
‎2021 Feb 28 8:10 AM
What is your "issue in select and delete statement"? Is it the result of SELECT which doesn't select the lines you want or is it DELETE which doesn't delete?
Please use the debugger and tell us.
‎2021 Feb 28 6:26 PM
We would really need more information about what really is the problem here to help the best. But you can start with removing the b~ in
WHERE NOT EXISTS (Select b~vbeln from LIKPYou never define the b, so that can't possibly work.
Next tip, if you're having problem with the DELETE is to make sure that the row type of li_zle_ca_id is matching the entire table key of your table. ABAP Documentation
‎2021 Mar 01 8:52 AM
Hello Sandra,
I am having issue in select and delete. It is not fetching the value and also sy-subrc gets failed for the condition.The requirement is using a single select and delete statement for the table zle_ca_id_tmp.vbeln is not in LIKP.vbeln then it should delete the records from zle_ca_id_tmp.Can you please help in modifying the query of select and delete.Thanks.
‎2021 Mar 01 9:15 AM
I will suppose you get in trouble due to high number of records to delete and triggered some dump?
Could you switch to a logic such as :
DATA subrc TYPE sy-subrc.
WHILE subrc = 0.
DELETE FROM zle_ca_id_tmp
WHERE NOT EXISTS ( SELECT vbeln FROM likp WHERE vbeln EQ zle_ca_id_tmp~vbeln )
UP TO 100000 ROWS.
subrc = sy-subrc.
CALL FUNCTION 'DB_COMMIT'.
ENDWHILE.
‎2021 Mar 01 1:22 PM
Hi Raymond,
My functional team has asked to change the below.Can you please in this regards.
Select needs to be changed
LIKP contains lots of deliveries which are not present on table ZLE_CA_ID_TMP
Therefore
‎2021 Mar 01 5:22 PM
‎2021 Mar 02 8:12 AM
Hi Sandra, The code given by him is working but my functional has asked to do with below select statement first and then delete.
Select needs to be changed
LIKP contains lots of deliveries which are not present on table ZLE_CA_ID_TMP
Therefore
‎2021 Mar 02 8:37 AM
‎2021 Mar 03 8:54 AM
‎2021 Mar 03 9:04 AM
Hello Raymond,
I am using the below code but it is not working .Can you please in this regards.
WHILE subrc = 0.
SELECT vbeln FROM zle_ca_id_tmp INTO TABLE li_zle_ca_id WHERE NOT EXISTS ( SELECT vbeln FROM likp WHERE vbeln EQ zle_ca_id_tmp~vbeln ).
IF sy-subrc EQ 0. DELETE zle_ca_id_tmp FROM TABLE li_zle_ca_id.
subrc = sy-subrc.
CALL FUNCTION 'DB_COMMIT'. ENDIF. ENDWHILE.
WRITE: 'The records are deleted from table ZLE_CA_ID'.
‎2021 Mar 03 9:36 AM
‎2021 Mar 03 9:56 AM
Hello Raymond,
I have tried the code but it is not working for me. Can you please help in modifying the query for this requirement.
Thanks in advance!
‎2021 Mar 04 1:07 PM
Hello Raymond,
The code worked but my functional has asked me to do this in smaller chunks so commit after each 1000 rows. Can you please help in providing the code for this requirement. Thanks in advance!
‎2021 Mar 04 2:33 PM
select maximum rows site:sap.com
(and the official ABAP documentation "UP TO" appears in 4th position for me)
‎2021 Mar 05 6:59 AM
Hello Raymond/Sandra,
I have used the below query.Can you please confirm for the same.
SELECT * FROM zle_ca_id INTO TABLE li_zle_ca_id PACKAGE SIZE 1000 WHERE NOT EXISTS ( SELECT vbeln FROM likp WHERE vbeln EQ zle_ca_id~vbeln ).
IF sy-subrc EQ 0.
DELETE zle_ca_id FROM TABLE li_zle_ca_id.
COMMIT WORK.
‎2021 Mar 08 9:55 AM
DATA mycursor TYPE cursor.
OPEN CURSOR WITH HOLD mycursor FOR
SELECT * FROM zle_ca_id PACKAGE SIZE 1000 WHERE NOT EXISTS ( SELECT vbeln FROM likp WHERE vbeln EQ zle_ca_id~vbeln ).
DO.
FETCH NEXT mycursor INTO TABLE li_zle_ca_id.
IF sy-subrc <> 0.
EXIT.
ENDIF.
DELETE zle_ca_id FROM TABLE li_zle_ca_id.
COMMIT WORK.
ENDDO.
CLOSE CURSOR mycursor.
‎2021 Mar 10 9:19 AM
Thanks for your support sandra.rossi / raymond.giuseppi .I have modified the query, tested and it is working well.
‎2021 Mar 11 5:39 AM
Hello raymond.giuseppi / sandra.rossi , I have one question for this issue.If I use the below code in my development,
SELECT * FROM zle_ca_id INTO TABLE li_zle_ca_id PACKAGE SIZE 1000 WHERE NOT EXISTS ( SELECT vbeln FROM likp WHERE vbeln EQ zle_ca_id~vbeln ).
IF sy-subrc EQ 0.
DELETE zle_ca_id FROM TABLE li_zle_ca_id.
COMMIT WORK.
WRITE: 'The records are deleted from table ZLE_CA_ID'.
ELSE.
WRITE: 'No records are deleted from table ZLE_CA_ID'.
ENDIF.
ENDSELECT.
What will happen say there are 1500 records as the above query will take 1000 records first since we are using the package size 1000 and will it take remaining 500 records next?
Can you please suggest any improvement in the above code to be done.
‎2021 Mar 11 8:20 AM
‎2021 Mar 11 12:40 PM
Hello sandra.rossi / raymond.giuseppi ,I have modified the query as per your suggestion.Kindly please find below.
SELECT * FROM zle_ca_id INTO TABLE li_zle_ca_id PACKAGE SIZE 1000 WHERE NOT EXISTS ( SELECT vbeln FROM likp WHERE vbeln EQ zle_ca_id~vbeln ).
DELETE zle_ca_id FROM TABLE li_zle_ca_id.
COMMIT WORK.
ENDSELECT.
IF sy-subrc EQ 0.
WRITE: 'The records are deleted from table ZLE_CA_ID'.
ELSE. WRITE: 'No records are deleted from table ZLE_CA_ID'.
ENDIF.
I have tested with less data.Since I dont have much test data in development system,I am not able to test further.Can
you please review and please let me know if any changes required.Thanks!
‎2021 Mar 11 12:45 PM
vinodhict123 You should use PACKAGE SIZE 1 and select 2 lines to delete to see whether COMMIT WORK works inside SELECT...ENDSELECT.
‎2021 Mar 11 12:55 PM
Hello sandra.rossi ,Sorry .Can you please give the code for the above case.Thanks in advance!
‎2021 Mar 11 1:34 PM
VIJAY v You said that you "have tested with less data". You need only 2 lines in table zle_ca_id to do a complete test to see whether COMMIT WORK works inside SELECT...ENDSELECT, by replacing temporarily "PACKAGE SIZE 1000" with "PACKAGE SIZE 1".
‎2021 Mar 11 5:41 PM
Thanks sandra.rossi ,I have done the testing and it is going to dump for the code in test environment so I will go with the OPEN CURSOR technique as per your suggestion.