Application Development 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: 

how to get delete data from database?

Former Member
0 Kudos

I created two database tables table 1 & table 2. When new entry is saved in table 2 ,then corresponding fields in table 1 entry should get delete automatically .i tried so many syntax to delete but not deleting. How to do it?

1 ACCEPTED SOLUTION

jogeswararao_kavala
Active Contributor
0 Kudos

See this sample code (First delete and then Insert)


DATA: itab  TYPE TABLE OF ztable,

         wa TYPE ztable,

  

   DELETE FROM ztable WHERE qmnum = '001000012345'.


   wa-qmnum = '001000012345'.

   wa-field1 = 'ABCDEFGH'.

   wa-field2 = 'Klmnopr stuvwxyz'.

....

....

   APPEND wa TO itab.

INSERT INTO ztable VALUES wa.

Alternatively you can use UPDATE command also.

12 REPLIES 12

0 Kudos

Hello

if you Drop an Table on the Database everthing is gone.

may have a lock at the Table CDPOS ( Change Historty)

regards

Christian

0 Kudos

I hope He is talking about custom Tables. Not standard tables.

former_member196331
Active Contributor
0 Kudos

While saving in Table2.

you can check the key column field in Table1 if it exists you can delete it by using coding

May i know what is the problem.

0 Kudos

table 1 has 3 fields,table 2 has those 5 fields including those 3 fields.I tried so many different type of syntax to delete but not getting required output?

jogeswararao_kavala
Active Contributor
0 Kudos

See this sample code (First delete and then Insert)


DATA: itab  TYPE TABLE OF ztable,

         wa TYPE ztable,

  

   DELETE FROM ztable WHERE qmnum = '001000012345'.


   wa-qmnum = '001000012345'.

   wa-field1 = 'ABCDEFGH'.

   wa-field2 = 'Klmnopr stuvwxyz'.

....

....

   APPEND wa TO itab.

INSERT INTO ztable VALUES wa.

Alternatively you can use UPDATE command also.

SimoneMilesi
Active Contributor
0 Kudos

Hi Raghava,

but what are you trying to achieve?

Deleting the whole record from Table1 or clear/change single fields for the corresponding record in Table1?

And I suggest you to change the title of your post: it seems that you need a way to retrieve deleted records.

raghug
Active Contributor
0 Kudos

I think he is talking about behavior something like a trigger or stored procedure directly on the database. I don't know about triggers in the SAP world, but stored procedures there seems to be help out there... Database Procedure Proxies for SQLScript and also ABAP Managed Database Procedures . You could also look at Core Data Services.

I personally have never used any of these, just being aware of how a database LUW works in SAP has been sufficient for me.

kaus19d
Active Contributor
0 Kudos

This message was moderated.

raghug
Active Contributor
0 Kudos

Kaushik Debnath  what you are recommending in the image that you posted is a way to bypass system security. I don't think that is what was being asked for and not something that should be promoted. If you need to change data, go through the proper channels set up by your organization.

kaus19d
Active Contributor
0 Kudos

This message was moderated.

0 Kudos

Here is the code .


Lets say ..


data : lt _table_1 type table od mara,

           lw _table_1 type mara,

           lt_table_2 type table of marc ,

         lw _table_2 type marc.


   lw _table 2 -field1 = 'text1'.

  lw _table 2 -field2 = 'text2'.

modify lt_table 2 from lw _table 2 .


if sy-subrc eq 0 .

commit work .

select single * from mara into lw _table_1 where field1 = lw _table 2-field1 .

if sy-subrc eq 0 .

delete  mara FROM WA lw _table_1 .

if sy-subrc eq 0 .

commit work .

endif .

endif .


Hope it should work .


0 Kudos

thanks its working.