‎2008 Apr 21 2:09 PM
Hi,
Can some one tell me how to delete a single row from Database table, where we have duplicate entries using DELETE Statement.
Just like Select Single or Select upto 1 row.
currently i'm using
Delete from PA0022 where conditions.
Using this all records are getting deleted at once. but i need only once row to be deleted.
<REMOVED BY MODERATOR>
Thanks,
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 12:46 PM
‎2008 Apr 21 2:15 PM
You need to be more specific with your delete. All these fields are part of the key. Ensure that all the fields are popluated that will make your delete unique to the record you want to delete.
PERNR
SUBTY
OBJPS
SPRPS
ENDDA
BEGDA
SEQNR
‎2008 Apr 21 2:13 PM
‎2008 Apr 21 2:15 PM
Hi,
Thanks for your reply,
I have a condition to be checked to delete. More over how to find out the row number in PA0022 for a specific record.
Thanks,
‎2008 Apr 21 2:14 PM
‎2008 Apr 21 2:15 PM
Use FM : HR_INFOTYPE_OPERATION to delete from
infotypes ...
Pass 'DEL' for parameter OPERATION
‎2008 Apr 21 2:15 PM
You need to be more specific with your delete. All these fields are part of the key. Ensure that all the fields are popluated that will make your delete unique to the record you want to delete.
PERNR
SUBTY
OBJPS
SPRPS
ENDDA
BEGDA
SEQNR
‎2008 Apr 21 2:20 PM
Hi Paul,
I have taken care of those key fields, but the thing, if a record is created multiple times on the same day then duplicates will appear.
So i need to delete those duplicate keeping only one record.
Any suggestions?
Thanks,
‎2008 Apr 21 2:23 PM
SEQNR will always bee Unique if nothing else and the first one of the day would be equal to 1.
DELETE * FROM PA0022 where <your conditions> and SEQNR GT 1.
I would look into using FM for deletes as previouly suggested unless you are sure these entries do not effect any other tables.
‎2008 Apr 21 3:19 PM
Hi Paul,
Thanks a lot for reply,
I tried using this code, but still its not working out, what it is doing is, it is not deleting other single records with seqnr = 0 which were created on any other day.
My req: i need to delete all duplicates keeping only earliest record for given pernr zpbegda zpendda zpcertmajo zpcertsub.
I'm working on it.
DELETE FROM pa0022 CLIENT SPECIFIED
WHERE mandt = sy-mandt
AND pernr EQ pi_0022_dupl-pernr
AND subty EQ '69'
AND begda EQ pi_0022_dupl-begda
AND endda EQ pi_0022_dupl-endda
and seqnr GT 0
AND zpbegda EQ itab_dupl-zpbegda
AND zpendda EQ itab_dupl-zpendda
AND zpcertmajo EQ itab_dupl-zpcertmajo
AND zpcertsub EQ itab_dupl-zpcertsub.
‎2008 Apr 21 4:22 PM
First of all: Do NOT delete entries from a standard DB table just like this, since there probably are many relationships with other tables. Use the function modules for this like already suggested.
One more TIP: How come you have duplicate entries in your database table? Try to avoid this by checking the data before saving. Do not insert new entries, better to modify the entry upon saving using a user exit or BAdI!!!!!
‎2008 Apr 21 2:17 PM
Hi Frd
Try this coding
DELETE FIELD INDEX <ROW NUMBER>
<REMOVED BY MODERATOR>
BY
Pari
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 12:46 PM
‎2008 Apr 21 2:24 PM
Hi,
Table maintanence generator is nothing but making a table available for adding records and deleting records.
The transaction code used is SM30.
follow below steps
1) go to se11 check table maintanance check box under
attributes tab
2) utilities-table maintanance Generator->
create function group and assign it under
function group input box.
also assign authorization group default &NC& .
3)
select standard recording routine radio in table
table mainitainence generator to move table
contents to quality and production by assigning
it to request.
4) select maintenance type as single step.
5) maintainence screen as system generated numbers
this dialog box appears when you click on create
button
6) save and activate table
using sm30 you can create entries manually.
check these links
1. Maintenance type
It specifies when you insert the new record, dat to be filled for the new entry should come in same screen one step) or new screen should come for data entry(two step)
2. Maintenance Screen
this is screen which is displayed to user. you can edit the screen and set the attributes of screen as per your need.
e.g.-if you want one of fields as output only and in the pAI of screen you can populate the value>
3. Recording routine
recording routine is same as your delivery class of table.>
if recording routine is no or use it means 'A'-no transport request number is asked while saving the entries.>
if it is standard -'C'it means it will ask for transport request number