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 record from database table

Former Member
10,309

Hi

i want to delete the records from ZTABLE. Following coding is not working. pls help me.

Select * from z1ychlog into table it_z1log
             where  VBELN  in s_vbeln
             AND    vstel  = p_vstel
             AND    WERKS  = P_werks.
loop at it_z1log.
if it_z1log-APPROVELNO is not initial.
*do nothing
else.
delete z1ychlog.
endif.
endloop.

Edited by: Kumar k on Jun 11, 2008 9:28 AM

10 REPLIES 10
Read only

Former Member
0 Likes
2,551

Hi,

Use like this.

tables z1ychlog.

loop at it_z1log.

if it_z1log-APPROVELNO is not initial.

*do nothing

else.

clear z1ychlog.

move it_z1log to z1ychlog.

delete z1ychlog.

endif.

endloop.

\[removed by moderator\]

Edited by: Ravi Kumar on Jun 11, 2008 9:42 AM

Edited by: Jan Stallkamp on Jun 11, 2008 10:35 AM

Read only

Former Member
0 Likes
2,551

Hi ,

You will need to use the syntax as below.

DELETE { {FROM target [WHERE sql_cond]}

| {target FROM source} }.

Ex:

SELECT carrid connid fldate

FROM sflight

INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab

WHERE carrid = p_carrid AND

fldate = sy-datum AND

seatsocc = 0.

DELETE sflight FROM TABLE sflight_key_tab.

Also it would be better if you call an explicit COMMIT WORK for the database operation to take place.

\[removed by moderator\]

Regards.

Edited by: Jan Stallkamp on Jun 11, 2008 10:35 AM

Read only

Former Member
0 Likes
2,551

DELETE   z1ychlog 
       WHERE  VBELN  in s_vbeln
             AND  vstel       = p_vstel
             AND  WERKS  = P_werks
             AND  APPROVELNO EQ SPACE.

IF SY-SUBRC EQ 0.
COMMIT WORK.
ENDIF.
Read only

Former Member
0 Likes
2,551

Hi

after delete statement use COMMIT statemnt.

Regards,

sriram

Read only

Former Member
0 Likes
2,551

Hi,

you are deleting wrong table.

Select * from z1ychlog into table it_z1log

where VBELN in s_vbeln

AND vstel = p_vstel

AND WERKS = P_werks.

loop at it_z1log.

if it_z1log-APPROVELNO is not initial.

*do nothing

else.

*delete z1ychlog. "You are dng

delete it_z1log. " do this

endif.

endloop.

\[removed by moderator\]

regards,

Dhan.

Edited by: Jan Stallkamp on Jun 11, 2008 10:36 AM

Read only

Former Member
0 Likes
2,551

Hi kumar,

Select * from z1ychlog into table it_z1log

where VBELN in s_vbeln

AND vstel = p_vstel

AND WERKS = P_werks.

loop at it_z1log.

if it_z1log-APPROVELNO is not initial.

delete it_z1log where APPROVELNO = space

or

delete it_z1log where APPROVELNO = 0

try this , may this will work

Regards

Thushara

Read only

0 Likes
2,551

Hi

I want to delete the records from Ztable. Not internal table

Read only

Former Member
0 Likes
2,551

Hi

u should try to use statement

Delete target from source

where target is name of your table

and source is the itab.

Statement will delete the the

records from dbtab matching the selection criteria

in itab

OR

use tables statement

Tables:Ztable

Select * from Ztable where....

Delete Ztable

Here data is getting populated into itab with same name as Ztable and respective records are deleted

Surbhi

Read only

0 Likes
2,551

Hi

i changed my coding. but still delete statement is not working. Anyone pls help me?

Select * from z1ychlog into table it_z1log
             where  VBELN  in s_vbeln
             AND    vstel  = p_vstel
             AND    WERKS  = P_werks
             AND   APPROVELNO = space.

if sy-subrc = 0.
delete z1ychlog from it_z1log.
else.
endif.

Read only

Former Member
0 Likes
2,551

hii

use DELETE table-name WHERE condition.

it will delete your records as per your condition.

\[removed by moderator\]

twinkal

Edited by: Jan Stallkamp on Jun 11, 2008 10:36 AM