Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Delete DB table rows do not exist in ITAB

ekekakos
Participant
0 Likes
2,682

I have a ztable with 3 rows,

I fill an ITAB with this 3 rows .

Then the user deletes the row with material 202 from the ITAB.

So now the ITAB has the following records:

How can I update the DB ZTABLE in order to have the same records as the ITAB.

1 way is to delete the records from ZTABLE and then MODIFY it from the ITAB.

So my question is, how to DELETE the extra row from ZTABLE in order to have the same number of rows with ITAB?

Thanks

Elias

I have a ztable with 3 rows,

I fill an ITAB with this 3 rows .

Then the user deletes the row with material 202 from the ITAB.

So now the ITAB has the following records:

How can I update the DB ZTABLE in order to have the same records as the ITAB.

1 way is to delete the records from ZTABLE and then MODIFY it from the ITAB.

So my question is, how to DELETE the extra row from ZTABLE in order to have the same number of rows with ITAB?

Thanks

Elias

4 REPLIES 4
Read only

FredericGirod
Active Contributor
0 Likes
2,413

Could you please, post your code, using the beautoful button [CODE].

Or just check the transaction ABAPDOCU, enter the keywork DELETE

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,413
  1. Lock the table (to avoid concurrent update by other user)
  2. Read the database table into internal table
  3. Logic to change the lines of the internal table
  4. Compare database table versus internal table
  5. Update database according to deletions, insertions, modifications
  6. Unlock the table

Alternatively, the step 4 can be avoided if the logic records the type of operation for each changed line (i.e. delete, insert, modification)

Read only

ekekakos
Participant
0 Likes
2,413

Thanks Sandra. My problem is in step No 5. The Insertion & Modification are covered by the command MODIFY. But how to tell the SAP: DELETE the lines from DB ZTABLE that do not exist in ITAB or KEEP only the lines that exist in ITAB?

Read only

lemoreno
Participant
0 Likes
2,413

Hi Elias,

I think you can do this:

Create 2 internal tables, one of them with all selected records, the other one with those records that were deleted by the user.

DATA: ti_selected TYPE STANDARD TABLE OF tp_table,
      ti_deleted  TYPE STANDARD TABLE OF tp_table.

SELECT field1, field2,....
INTO @ti_selected
FROM dbtable.

*When the user deletes a row, move it to TI_DELETED, then delete it from TI_SELECTED.
APPEND es_selected TO ti_deleted.
DELETE ti_selected WHERE .... .

*At the end of the process, delete the data base table with the records in TI_DELETED.
DELETE dbtable FROM TABLE @ti_deleted.

*Modify the records with TI_SELECTED
MODIFY dbtable FROM TABLE @ti_selected.