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 records from internal table

Former Member
0 Kudos

Hi experts...

I have one output, like

101 102 103

444 000 000

444 000 000

444 000 000

444 333 000

444 333 000

000 333 000

000 333 000

000 000 666

000 000 666

000 000 666

000 000 666

It is in alv report. I want to delete all 0 s and dupllicate value form internal table.

and output like

101 102 103

444 333 666

here 101 102 103 is title.

plz anybody can help me.

thank you

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Ankita ,

Please check this.

DATA : BEGIN OF itab OCCURS 0,

101(3) TYPE c,

102(3) TYPE c,

103(3) TYPE c,

END OF itab.

DATA : itab1 LIKE TABLE OF itab WITH HEADER LINE.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '333'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '333'.

itab-103 = '000'.

APPEND itab.

itab-101 = '000'.

itab-102 = '333'.

itab-103 = '000'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

SORT itab BY 101 102 103.

DELETE ADJACENT DUPLICATES FROM itab.

itab1[] = itab[].

LOOP AT itab.

LOOP AT itab1.

IF itab-101 = '000' AND itab-102 = '000' AND itab-103 = '000'.

EXIT.

ENDIF.

IF itab-101 = '000'.

itab-101 = itab1-101.

ENDIF.

IF itab-102 = '000'.

itab-102 = itab1-102.

ENDIF.

IF itab-103 = '000'.

itab-103 = itab1-103.

ENDIF.

MODIFY itab.

DELETE itab1 INDEX 1.

ENDLOOP.

ENDLOOP.

REFRESH itab1.

SORT itab BY 101 102 103.

DELETE ADJACENT DUPLICATES FROM itab.

LOOP AT itab WHERE 101 <> '000' AND 102 <> '000' AND 103 <> '000'.

APPEND itab TO itab1.

ENDLOOP.

itab[] = itab1[].

15 REPLIES 15

Former Member
0 Kudos

Loop at internal table

read Table itab where any of 101 , 102 103 is zero

then delete itab

endloop

regards

hitesh

0 Kudos

Hi hitesh,

I am not able to get my output. plz try to understand my problem and plz help me out.

thank you.

Former Member
0 Kudos

loop at tab where field = 000.

delete 000 record.

endloop.

gopi_narendra
Active Contributor
0 Kudos

use Delete adjacent duplicates comparing values field1 field2....etc what all fields you want to compare.

delete adjacent duplicate from itab comparing <field1 <field2>.

next delete the table which has 000 values

if the field type is type C (ie character)

delete itab where <field> = '000' " Use quotes

if the field type is numeric

delete itab where <field> is initial.

Regards

Gopi

Former Member
0 Kudos

Hi ankita,

Sort the internal table

Sort itab

delete adjacent duplicates from itab.

then you will get output like

101 102 103

444 000 000

444 333 000

000 333 000

000 000 666

Then do the code to get the required output

Regards

Arun

Former Member
0 Kudos

hi,

try like this,

loop at itab.

delete itab-fld1 where fld1 = '000'.

delete adjacent duplicates from itab.

write:/itab-fld1.

endloop.

if helpful reward some points.

with regards,

Suresh Aluri.

Former Member
0 Kudos

Hi,

try this one.Solve your problem.

loop at itab.

delete itab where field = '000'.

endloop.

Delete adjucent duplicates from table itab.

Regards

Debjani

Rewards point for helpful answer.

Former Member
0 Kudos

Hi Ankita ,

Please check this.

DATA : BEGIN OF itab OCCURS 0,

101(3) TYPE c,

102(3) TYPE c,

103(3) TYPE c,

END OF itab.

DATA : itab1 LIKE TABLE OF itab WITH HEADER LINE.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '333'.

itab-103 = '000'.

APPEND itab.

itab-101 = '444'.

itab-102 = '333'.

itab-103 = '000'.

APPEND itab.

itab-101 = '000'.

itab-102 = '333'.

itab-103 = '000'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

APPEND itab.

SORT itab BY 101 102 103.

DELETE ADJACENT DUPLICATES FROM itab.

itab1[] = itab[].

LOOP AT itab.

LOOP AT itab1.

IF itab-101 = '000' AND itab-102 = '000' AND itab-103 = '000'.

EXIT.

ENDIF.

IF itab-101 = '000'.

itab-101 = itab1-101.

ENDIF.

IF itab-102 = '000'.

itab-102 = itab1-102.

ENDIF.

IF itab-103 = '000'.

itab-103 = itab1-103.

ENDIF.

MODIFY itab.

DELETE itab1 INDEX 1.

ENDLOOP.

ENDLOOP.

REFRESH itab1.

SORT itab BY 101 102 103.

DELETE ADJACENT DUPLICATES FROM itab.

LOOP AT itab WHERE 101 <> '000' AND 102 <> '000' AND 103 <> '000'.

APPEND itab TO itab1.

ENDLOOP.

itab[] = itab1[].

0 Kudos

Hi Arjun...

if I want output like this then plz give me some hint,

101 102 103

222 0.000 444

because in my data there is some also 0s.

from ur below code i m not able to get 0s.

LOOP AT itab WHERE 101 <> '000' AND 102 <> '000' AND 103 <> '000'.

APPEND itab TO itab1.

ENDLOOP.

plz help me Arjun...

0 Kudos

your requirement is now confusing me....

you want to do away with the rows with 000 values altogether....but you want to hold 000.00??

i think you could use field symbols and remove the unwanted rows in a single loop.

0 Kudos

Try this

DATA : BEGIN OF ITAB OCCURS 0,

101(3) type c,

102(3) type c,

103(3) type c,

END OF ITAB.

DATA : ITAB1 LIKE TABLE OF ITAB WITH HEADER LINE.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

append itab.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

append itab.

itab-101 = '444'.

itab-102 = '000'.

itab-103 = '000'.

append itab.

itab-101 = '444'.

itab-102 = '333'.

itab-103 = '000'.

append itab.

itab-101 = '444'.

itab-102 = '333'.

itab-103 = '000'.

append itab.

itab-101 = '000'.

itab-102 = '333'.

itab-103 = '000'.

append itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

append itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

append itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

append itab.

itab-101 = '000'.

itab-102 = '000'.

itab-103 = '666'.

append itab.

if not itab[] is initial.

sort itab by 101 descending.

read table itab index 1.

itab1-101 = itab-101.

sort itab by 102 descending.

read table itab index 1.

itab1-102 = itab-102.

sort itab by 103 descending.

read table itab index 1.

itab1-103 = itab-103.

append itab1.

endif.

*

itab[] = itab1[].

Former Member
0 Kudos

you said it was an ALV Report ..then the code was as follows :

here the internal table is %g00 ..

"step:1

call function 'REUSE_ALV_GRID_DISPLAY' 
         exporting  i_callback_program = gc_repid 
                    I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' 
                    I_CALLBACK_USER_COMMAND  = 'USER_COMMAND' 
                    i_grid_title       = lc_grid_title 
                    is_layout          = lc_layout 
                    it_fieldcat        = gt_fieldcat 
                    it_sort            = sort 
                    i_save             = l_save 
                    is_reprep_id       = l_bbs_id 
                    is_variant         = l_variant 
         tables     t_outtab           = %g00 
         exceptions program_error      = 1 
                    others             = 2.

"step:2

FORM set_pf_status USING rt_extab TYPE slis_t_extab. 
  SET PF-STATUS 'ZSTANDARD'. 
ENDFORM. "Set_pf_status

In the above case the GUI status copied was named ZSTANDARD and adjusted accordingly, adding and removing the desired buttons. A button was added called '%DELETE'

"step:3

FORM user_command USING r_ucomm     LIKE sy-ucomm 
                        rs_selfield TYPE slis_selfield. 
DATA: li_count TYPE I. 
IF r_ucomm EQ '%DELETE'. 
  LOOP AT %g00 WHERE mark EQ 'X'. 
    ADD 1 TO li_count. 
  ENDLOOP. 
  IF li_count GT 0. 
    gc_delete_flag = 'X'. 
    r_ucomm = '&F03'. "Back arraow 
  ELSE. 
    MESSAGE W000 WITH 'Please highlight the rows to be deleted!'. 
  ENDIF. 
ENDIF. 
ENDFORM.  "User_command

reward points if it is usefull ...

Girish

Former Member
0 Kudos

Hi ankita patel ,

Before passing to the alv do this.

SORT ITAB BY F1 F2 F3.

DELETE ADJACENT DUPLICATES FROM ITAB.

DELETE ITAB WHERE F1 IS INITIAL.

DELETE ITAB WHERE F2 IS INITIAL.

DELETE ITAB WHERE F3 IS INITIAL.

Regatrds,

Rama.Pammi

Former Member
0 Kudos

FOR THE DUPLICATE

DELETE ADJACENT DUPLICATES FROM <itab> COMPARING <field name>.

for the zero valus

DELETE <itab> WHERE <field name> EQ '000'.

Don't Forget to Rewards.

Former Member
0 Kudos

Hi

You can use too statements at the lop condition

Delete adjacent duplicates from itab comparing '000'

It will solve your problem

Reward all helpfull answers

Regards

Pavan