cancel
Showing results for 
Search instead for 
Did you mean: 

delete

Former Member
0 Kudos
38

In this code when the bolded if condition fails i want to delete that record. I tried "delete struct1 index sy-tabix" but that record is not deleted.

I tried "clear struct1 ". its deletes the current record.

but in some field its getting zero value & it is appending as a additional record.

Please help me.

loop at cdhdr.

if ( it1-tcode = 'FSS0' or it1-tcode = 'FS00' ).

w1_saknr = it1-objectid+4(10).

w_orgid = it1-objectid+14(4).

loop at it_cdpos where changenr eq it1-changenr

and objectid eq it1-objectid

and objectclas eq it1-objectclas.

<b>If w_orgid in r_orgid.</b>

IF ( it_CDPOS-FNAME = 'XLOEV' AND it_cdpos-value_new eq 'X' ).

replace struct1-change_ind with 'D' into struct1-change_ind.

struct1-bukrs = w_orgid.

struct1-cost = space.

struct1-plant = space.

append struct1.

else.

struct1-bukrs = w_orgid.

struct1-change_ind = w_chngid.

struct1-cost = space.

struct1-plant = space.

append struct1.

endif.

<b>else.

delete struct1 index sy-tabix.</b>

endif.

append struct1.

endloop.

endif.

endloop.

Accepted Solutions (0)

Answers (6)

Answers (6)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Try this.You are using an append just before the endloop.That's not needed.

loop at it_cdpos where changenr eq it1-changenr

and objectid eq it1-objectid

and objectclas eq it1-objectclas.

If w_orgid in r_orgid.

IF ( it_CDPOS-FNAME = 'XLOEV' AND it_cdpos-value_new eq 'X' ).

replace struct1-change_ind with 'D' into struct1-change_ind.

struct1-bukrs = w_orgid.

struct1-cost = space.

struct1-plant = space.

append struct1.

else.

struct1-bukrs = w_orgid.

struct1-change_ind = w_chngid.

struct1-cost = space.

struct1-plant = space.

append struct1.

endif.

else.

clear struct1.

<b>endif.

endloop.</b>

Former Member
0 Kudos

Hello Silviya,

U have used

delete struct1 index sy-tabix. however sy-tabix would hold value from the loop stmt. Which record u would want to delete. If u know which record to delete use

delete struct1 with table key.

If the record is not found for the first time then the IF stmt will fail and it will go to else where it will try and delete a record which is not existent.

Former Member
0 Kudos

Hi Siliviya,

Could you please recheck the code .

<b>If</b> w_orgid in r_orgid.

IF ( it_CDPOS-FNAME = 'XLOEV' AND it_cdpos-value_new eq 'X' ).

replace struct1-change_ind with 'D' into struct1-change_ind.

struct1-bukrs = w_orgid.

struct1-cost = space.

struct1-plant = space.

append struct1.

else.

struct1-bukrs = w_orgid.

struct1-change_ind = w_chngid.

struct1-cost = space.

struct1-plant = space.

append struct1.

endif.

<b>else.</b>

<b>At this point of time only u want to delete, then r u sure that at this time You have got record in the Struct1 and if yes , then do send us thatpart of code also.</b> this you need to confirm us.

delete struct1 index sy-tabix.

Cheers

Sunny

Rewrd points, if found helpful

Former Member
0 Kudos

Hi Vijay,

Here i dont want to append the current record in struct1 (it should be deleted) when bolded if condition fails . Thats the requirement.

loop at it1 .

struct1-OBJECTCLAS = it1-OBJECTCLAS.

struct1-OBJECTID = it1-OBJECTID.

struct1-KEYVALUE = w_saknr.

struct1-CHANGENR = it1-CHANGENR.

struct1-USERNAME = it1-USERNAME.

struct1-UDATE = it1-UDATE.

struct1-UTIME = it1-UTIME.

struct1-TCODE = it1-TCODE.

struct1-PLANCHNGNR = it1-PLANCHNGNR.

struct1-ACT_CHNGNO = it1-ACT_CHNGNO.

struct1-WAS_PLANND = it1-WAS_PLANND.

if ( it1-tcode = 'FSS0' or it1-tcode = 'FS00' ).

w1_saknr = it1-objectid+4(10).

w_orgid = it1-objectid+14(4).

loop at it_cdpos where changenr eq it1-changenr

and objectid eq it1-objectid

and objectclas eq it1-objectclas.

<b>If w_orgid in r_orgid.</b>

IF ( it_CDPOS-FNAME = 'XLOEV' AND it_cdpos-value_new eq 'X' ).

replace struct1-change_ind with 'D' into struct1-change_ind.

struct1-bukrs = w_orgid.

struct1-cost = space.

struct1-plant = space.

append struct1.

else.

struct1-bukrs = w_orgid.

struct1-change_ind = w_chngid.

struct1-cost = space.

struct1-plant = space.

append struct1.

endif.

<b>else.

clear struct1</b>.

endif.

endloop.

endif.

append struct1.

sort struct1 by udate bukrs.

delete adjacent duplicates from struct1 comparing all fields.

endif.

endloop.

Former Member
0 Kudos

Hi Silviya, as i had mentioned, remove the append part in the code

append struct1. " remove this

sort struct1 by udate bukrs.

delete adjacent duplicates from struct1 comparing all fields.

endif.

if u chk in debugging mode, u ll c that append statement is getting executed twice..so after u clear struct1, u are again saying APPEND, so it appends a blank line into ur table..i guess ur problem shud be solved if u remove this command ..

Hope it helps,

Regards,

Bikash

Former Member
0 Kudos

Hi Silviya, dont put append struct1. after u have deleted the record, ie

else.

delete struct1 index sy-tabix.

endif.

<b>append struct1.</b> " remove this

endloop.

Hope it helps,

Regards,

Bikash

Former Member
0 Kudos

hi

did u try reading the table and then deleting

Read table itab with key.....

delete itab index sy-tabix.

thanks,

priya