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: 

Deletion from a Ztable

Former Member
0 Kudos
107

I have to delete all those records from one of my ztable where length of material no. (matnr) is less than 18 characters.

can anyone give me the idea of query that I'll have to write.

Regards,

Alok.

9 REPLIES 9

former_member404244
Active Contributor
0 Kudos
83

Hi Alok,

First get all the records in an internal table ITAB whose matnr length is LT 18.

then write the below logic.

delete ztable from ITAB.

if sy-subrc eq 0.

commit work.

endif.

regards

Nagaraj

Message was edited by: nagaraj kumar nishtala

0 Kudos
83

Dear nagaraj,

Here I have to address the length of the field 'matnr'.

Alok.

Former Member
0 Kudos
83

Hi

itab type ztable

Select * from ztable into itab.

loop at itab into wa_itab.

count = strlen(wa_itab-field).

if count ge 18.

DELETE itab from wa_itab.

endif.

endloop.

DELETE ztable from table itab.

Former Member
0 Kudos
83

delete ztable where matnr <> '000000000000000000'.

Former Member
0 Kudos
83

Try like this...

fetch the values of z table into an internal table..

loop at the internal table..

every time get the length of matnr field.

if matnr field length is < 18.

delete ztable where matnr = ur internal table matnr value.

Madhavi

Former Member
0 Kudos
83

Hi Alok,

u can try following also.

DATA: v1(19) TYPE c,

n(19) TYPE n.

START-OF-SELECTION.

v1 = '000023456'.

PACK v1 TO n.

WRITE:/ n.

IF n < '100000000000000000'.

WRITE:/ 'lesser'.

ELSE.

WRITE:/ 'greater'.

ENDIF.

v1 = '111111111111111111'.

PACK v1 TO n.

WRITE:/ n.

IF n < '100000000000000000'.

WRITE:/ n.

WRITE:/ 'lesser'.

ELSE.

WRITE:/ 'greater'.

ENDIF.

-Anu

Former Member
0 Kudos
83

Hi,

follow below logic

data lv_matnr(17) type c.

do 17 times.

clear lv_index,lv_matnr.

lv_index = sy-index.

do lv_index times.

concatenate lv_matnr '_' into lv_matnr.

endo.

delete from ztable where matnr like lv_matnr.

enddo.

Regards

amole

Former Member
0 Kudos
83

Hi,

Retrieve all the data into an internal table.

Loop at itab into lw_itab.

*Calculate the length of material

l_length = strlen(lw_itab-matnr).

if l_length < 18.

delete ztable where matnr = lw_matnr.

if sy-subrc = 0.

commit.

endif.

endif.

endloop.

Reward if it is helpful.

Cheers.

Former Member
0 Kudos
83

Hi,

Correction in detete statement in my previous reply.

delete ztable where matnr = lw_itab-matnr.

Cheers