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

how to get delete data from database?

Former Member
0 Likes
2,568

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
Read only

jogeswararao_kavala
Active Contributor
0 Likes
2,440

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
Read only

0 Likes
2,440

Hello

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

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

regards

Christian

Read only

0 Likes
2,440

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

Read only

former_member196331
Active Contributor
0 Likes
2,440

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.

Read only

0 Likes
2,440

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?

Read only

jogeswararao_kavala
Active Contributor
0 Likes
2,441

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.

Read only

SimoneMilesi
Active Contributor
0 Likes
2,440

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.

Read only

raghug
Active Contributor
0 Likes
2,440

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.

Read only

kaus19d
Active Contributor
0 Likes
2,440

This message was moderated.

Read only

raghug
Active Contributor
0 Likes
2,440

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.

Read only

kaus19d
Active Contributor
0 Likes
2,440

This message was moderated.

Read only

0 Likes
2,440

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 .


Read only

0 Likes
2,440

thanks its working.