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 data into table before insert

Former Member
0 Likes
2,078

hi Experts,

how to write a code for delete the data first from ztable before inserting the data into the same table after execution of program.

I have written like

data itab like ztable occurs 0 with header line.

If ztable is not initial.

delete itab.

modify ztable from itab.

endif.

but this code is not working.Plz reply as soon as possible.

Thx in advance.

Regds,

Vipul

14 REPLIES 14
Read only

viquar_iqbal
Active Contributor
0 Likes
1,579

Hi

you can use refresh itab[].

this would delete all the data from itab.

Read only

0 Likes
1,579

do you want to delete all the rows or a particular row?

Read only

0 Likes
1,579

i want to delete all the rows but when i put debug it show it skip from the if condition.

Read only

0 Likes
1,579

I don't think U can check if Ztable is empty or not ..

remove this statement ..

write as ..

If itab[] is not initial.

clear itab[].

modify ztable from itab.

endif.

Read only

Former Member
0 Likes
1,579

Hi,

Can i have ur reqiurement clear....

ur trying to delete the table entries first then trying to insert the entries to the same table...

so let me know,that the entries ur deleting are same as that of the entries ur inserting.?

if not y u want to delete the table entries first.

Regards,

Rohan.

Read only

Former Member
0 Likes
1,579

Hi,

Your requirement is not clear. Please specify it clearly.

you have deleted itab then modifying ztable from itab. how come data will be there in itab.

thanks,

Srilakshmi.

Read only

Former Member
0 Likes
1,579

use


If ztable is not initial.
clear: itab , itab[]."delete itab.
modify itab from ztable.
endif.


clear: itab , itab[]

.

Edited by: tahir naqqash on Feb 23, 2009 4:28 PM

Read only

0 Likes
1,579

Hi,

When you are checking a table whether it is initial or not.

Use

 if itab[] is not initial.....endif

and if you want to delete the data in internal table.

You can always use

 Refresh : itab[].

or if you want to delete only the cirrent line Use.

 delete itab.

Hope this may help.

Regards,

Amitteja

Read only

Former Member
0 Likes
1,579

try this:

loop at itab.

delete itab from 1.

endloop.

modify ztable from itab.

Read only

Former Member
0 Likes
1,579

Hi Vipul,

Simply write the following code:-

If MARA is your table.

*

DELETE from MARA.

*

This will delete all entries.

If you want to delete only some entries, you can provide a where clause.

And then write the code for inserting the entries.

Read only

0 Likes
1,579

Thx my problem solved.

Read only

Former Member
0 Likes
1,579

Hi Vipul,

Could you please give your requirement very clearly?

Regards,

Anil

Read only

Former Member
0 Likes
1,579

try this

delete ztable

insert ztable from itab.

regards

Varun

Read only

Former Member
0 Likes
1,579

hi Vipul,

Try doing this.....

DATA: itab type standard tabe of ztable.

select * from ztable into table itab.

if sy-subrc = 0.

delete ztable.

else

modify ztable from itab.

endif.

This will work, I have tried it out.

Thanks and Regards

Suraj