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

coding

Former Member
0 Likes
1,132

Hi all,

there is an internal table A with date as one one of the field.

i looped this table as loop at A.

Now the requirement is i want to delete the row from this internal table if date is zero.How to do this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,092

hi

chk if the date field is initial (Date with Zero) in your loop. and if yes then say " Delete Itab."

Deleting the line in Itab can be done using either Index or the Key.

-

Santosh

11 REPLIES 11
Read only

Former Member
0 Likes
1,092

if ur date field is referring to sy-datum then it has to be like this .

loop at itab.

if itab-date eq '00000000' 
delete itab index sy-tabix.
endif.

endloop.

regards,

vijay

Read only

Former Member
0 Likes
1,093

hi

chk if the date field is initial (Date with Zero) in your loop. and if yes then say " Delete Itab."

Deleting the line in Itab can be done using either Index or the Key.

-

Santosh

Read only

Former Member
0 Likes
1,092

Hi,

You can use this line of code tahts enough

DELETE itab WHERE date = '00000000'.

There is no need for a loop, this improves performance.

Hope thsi solves ur problem, reward points and clos eteh thraed if ur problem got solved.

Read only

anversha_s
Active Contributor
0 Likes
1,092

hi,

chk this.

<u>pls dont use sy-tabiz directlt inside the loop.</u>

chk this.

data : f_tabix like sy-tabix.

loop at itab.

f_tabix = sy-tabix.
 
if itab-date eq '00000000' 
delete itab index f_tabix .
endif.
 
endloop.

rgds

Anver

Read only

Former Member
0 Likes
1,092

Hi,

FIELD-SYMBOLS: <i_table> TYPE tabletype.

-


****

LOOP AT A ASSIGNING <i_table>.

IF <i_table>-field IS INITIAL.

DELETE A from <i_table>.

ENDIF.

ENDLOOP.

Regards,

Sunil

Read only

Former Member
0 Likes
1,092

To improve performance do not loop and delete within the loop. Just use the DELETE statement outside the loop using a WHERE clause for the date field.

IF deleting within a loop is necessary, ensure you save the SY-TABIX within a temporary variable immediately after the loop statement and use this index for deletion, cos SY-TABIX is susceptible to change by other statements within the loop prior to deletion also.

Regards,

Aditya

Read only

Former Member
0 Likes
1,092

execute the code.

data : begin of itab occurs 0,
       f1(2) type c,
       f2 like sy-datum,
       end of itab.

DATA : CNTR LIKE SY-TABIX.

       ITAB-f1 = 'A'.
       ITAB-F2 = '20072801'.

       APPEND ITAB.
       CLEAR ITAB.

       ITAB-f1 = 'B'.
       ITAB-F2 = '00000000'.

       APPEND ITAB.
       CLEAR ITAB.


      LOOP AT ITAB.
      CNTR = SY-TABIX.
      IF ITAB-F2 = '00000000'.
      DELETE ITAB INDEX CNTR.
      ENDIF.
      ENDLOOP.

      LOOP AT ITAB.
      WRITE:/ ITAB-F1,
              ITAB-F2.
      ENDLOOP.

regards,

vijay

Read only

Former Member
0 Likes
1,092

Hi shwetha,

check this code,

REPORT zex33.
data : begin of itab occurs 0,
f type i,
f2 type sy-datum,
f3(10),
end of itab.

itab-f = 20 .
itab-f2 = '10052006'.
itab-f3 = '10/05/2006'.
APPEND ITAB.
CLEAR ITAB.

itab-f = 20 .
itab-f2 = '11052006'.
itab-f3 = '11/05/2006'.
APPEND ITAB.
CLEAR ITAB.

itab-f = 25 .
APPEND ITAB.
CLEAR ITAB.

itab-f = 25 .
APPEND ITAB.
CLEAR ITAB.

itab-f = 30 .
itab-f2 = '12052006'.
itab-f3 = '12/05/2006'.
APPEND ITAB.
CLEAR ITAB.

itab-f = 30 .
itab-f2 = '10082006'.
itab-f3 = '10/08/2006'.
APPEND ITAB.
CLEAR ITAB.

itab-f = 30 .
itab-f2 = '10082006'.
APPEND ITAB.
CLEAR ITAB.

write : / 'Internal table before'.
loop at itab.
  write : / itab-f , itab-f2 , itab-f3.
endloop.

loop at itab.
  if itab-f2 eq '00000000' or itab-f3 eq space.
     delete itab index sy-tabix.
  endif.
endloop.

write : / 'Internal table after deletion'.
loop at itab.
  write : / itab-f , itab-f2 , itab-f3.
endloop.

Read only

Former Member
0 Likes
1,092

DELETE A WHERE DATE = '0'.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
1,092

data : f_tabix like sy-tabix.

loop at itab.

f_tabix = sy-tabix.

if itab-date eq '00000000'

delete itab index f_tabix .

endif.

endloop.

This should solve the problem.

Read only

Former Member
0 Likes
1,092

Hi Shweta ,

If you just want to delete the entries which do not have a value in the date feild then you do not need to loop on the intermal table to do it.

Just write

DELETE A WHERE DATE IS INITIAL.

Regards

Arun