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: 

delete entries from ztable

Former Member
0 Kudos

we are having a ztable. now our requirement is to delete entries in the ztable through

the zreport.

in the selection screen we give the material num and date(which is stored in the field of a ztable)

based on this we need to delete the entries.

please tell me how to do this , either we need to have internal table or directly delete the

ztable,

in selection screen we declared the parameter of int i . so user can give 4 or 5 or 10 .

means if he gives 10 it means sydate-10 days before. before 10 days data should be deleted

and after 10 days data to till date should be kept in the table.

so please give me a sample code .so tell me the best way to achieve this.

Thank you for all the replies.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Plz try this:

data: old_date type sy-datum,
                 p_num type i.

parameters: p_date type sy-datum.

old_date = p_date - p_num.    " suppose 10

 SELECT matnr
              date...
.......
   FROM ztable
  INTO TABLE ztable_1
  WHERE date BETWEEN p_date AND old_date.

  IF sy-subrc = 0.

    DELETE ztable 
    FROM TABLE ztable._1
    IF sy-subrc = 0.
    MESSAGE i029 WITH sy-dbcnt text-002 . " records deleted
    ENDIF.
  ENDIF.

Hope this helps you.

Plz reward if useful.

Thanks,

Dhanashri.

Edited by: Dhanashri Pawar on Jun 25, 2008 2:22 PM

8 REPLIES 8

peter_ruiz2
Active Contributor
0 Kudos

hi shiva,

1. retrieve all the data that you need to be deleted based on the selection-screen parameters into an internal table

2. process your internal table and remove records which does not need to be deleted.

3. use this code to delete the data from your z table.

delete ztable from table itab.

sy-subrc returns 0 if the process is executed successfuly. otherwise, it returns 4.

regards,

Peter

GauthamV
Active Contributor
0 Kudos

hi,

check this sample code.

TABLES : xyz.

select-options : s_datum for xyz-datum.

DELETE FROM xyz WHERE name = 'ABC'

AND datum in s_datum.

IF sy-subrc = 0.

MESSAGE 'RECORDS DELETED SUCCESFULLY' TYPE 'S'.

ENDIF.

former_member212653
Active Contributor
0 Kudos

REPORT  ZTEST_SOURAV15.

data: wa_ztable type ztable.

select-options:
s_matnr for wa_ztable-matnr.
PARAMETERS:
p_count type i obligatory.

start-of-selection.

data: l_date type datum.

l_date = sy-datum - p_count.
delete from ztable
where matnr in s_matnr and
          zzdate lt l_date.
if sy-subrc = 0.
 message s000(ztest) with 'Data deleted sucessfully'.
endif.

Former Member
0 Kudos

DELETE

FROM ZTABLE

WHERE parameer = ''

AND ZTABLE-date BETWEEN sy-datum AND p_date

Former Member
0 Kudos

Hi,

You requirment can be broken up into 2 parts first is to get the date based on the parameter before to which you want to delete data from the table based on that date you can find out the date using some FM or simple sydatum - date as on selection screen should also do the trick.

For the second part you can use a simple delete statement delete ztab where date is less than date as you have calculated.

Regards,

Himanshu

sivasatyaprasad_yerra
Active Contributor
0 Kudos

get the date based on the input provided by user. i;e, from selection screen.

and use that date in delete ztable where date > (date).

Regards,

Siva.

Former Member
0 Kudos

Hi,

You can this way-

Parameters: p_num type i obligatory.

Data: w_date type sy-datum.

w_date = sy-datum - p_num.

Delete * from ztable where date <= w_date.

if sy-subrc = 0.

Message 'records deleteed successfully' type 'I'.

Endif.

Thanks

Former Member
0 Kudos

Hi,

Plz try this:

data: old_date type sy-datum,
                 p_num type i.

parameters: p_date type sy-datum.

old_date = p_date - p_num.    " suppose 10

 SELECT matnr
              date...
.......
   FROM ztable
  INTO TABLE ztable_1
  WHERE date BETWEEN p_date AND old_date.

  IF sy-subrc = 0.

    DELETE ztable 
    FROM TABLE ztable._1
    IF sy-subrc = 0.
    MESSAGE i029 WITH sy-dbcnt text-002 . " records deleted
    ENDIF.
  ENDIF.

Hope this helps you.

Plz reward if useful.

Thanks,

Dhanashri.

Edited by: Dhanashri Pawar on Jun 25, 2008 2:22 PM