02-28-2021 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.
02-28-2021 7:13 AM
02-28-2021 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.
02-28-2021 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 LIKP
You 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
03-01-2021 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.
03-01-2021 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.
03-01-2021 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
03-01-2021 5:22 PM
03-02-2021 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
03-02-2021 8:37 AM
IN this case, just convert the DELETE statement in a SELECT statement into an internal table, and use a DELETE statement using the intyernal table.
You can load the data by batch and destroy it as in my example or switch to a cursor technique (OPEN CURSOR) and batch read (FETCH) this is basic Abap
03-03-2021 8:54 AM
Ask an abapper tp convert theDELETE statement of my sample into a SELECT INTO TABLE and then add a DELETE using this internaml table.
03-03-2021 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'.
03-03-2021 9:36 AM
Replace
SELECT vbeln FROM zle_ca_id_tmp
with
SELECT * FROM zle_ca_id_tmp
and use the whole database table for the internal table structure definition
move also
subrc = sy-subrc.
out of the if/endif block
03-03-2021 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!
03-04-2021 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!
03-04-2021 2:33 PM
select maximum rows site:sap.com
(and the official ABAP documentation "UP TO" appears in 4th position for me)
03-05-2021 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.
03-08-2021 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.
03-10-2021 9:19 AM
Thanks for your support sandra.rossi / raymond.giuseppi .I have modified the query, tested and it is working well.
03-11-2021 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.
03-11-2021 8:20 AM
03-11-2021 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!
03-11-2021 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.
03-11-2021 12:55 PM
Hello sandra.rossi ,Sorry .Can you please give the code for the above case.Thanks in advance!
03-11-2021 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".
03-11-2021 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.