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

Delete repeat fields

Former Member
0 Likes
737

Hello.

I have a internal table with some fields, and many fiels are repeat. I would delete the fields that are repeat, but not all the fields of this record.

Example:

Code Name Price Date Num

10 X 20 12-10 9

10 X 20 15-10 12

15 R 14 14-10 8

15 R 14 12-10 5

and i would....

10 X 20 12-10 9

15-10 12

15 R 15 14-10 8

12-10 5

Thanks!!!!

1 ACCEPTED SOLUTION
Read only

ferry_lianto
Active Contributor
0 Likes
691

Hi,

Please try this.


data: string_old(5),
      string_new(5).

sort itab.

loop at itab.
  at first.
    move: itab-code(2)  to string_old(2),
          itab-name(1)  to string_old+2(1), 
          itab-price(2) to string_old+3(2).
    
    continue.
  endat.     

  move: itab-code(2)  to string_new(2),
        itab-name(1)  to string_new+2(1), 
        itab-price(2) to string_new+3(2).

  if string_old = string_new.
    move: spaces to itab-code(2),
          spaces to itab-name(1),
          spaces to itab-price(2).
    
    modify itab.
  endif.

  string_old = string_new.

endloop.

Regards,

Ferry Lianto

6 REPLIES 6
Read only

ferry_lianto
Active Contributor
0 Likes
691

Hi,

Please try to sort the internal table and use delete adjacent duplicate entries statement.

Syntax:


DELETE ADJACENT DUPLICATE ENTRIES FROM <itab> 
                          [COMPARING <f1> <f 2> ...  
                          |ALL FIELDS].

Regards,

Ferry Lianto

Read only

0 Likes
691

No, becase delete adjecent delete all the record, and only want to delete the three first fields of the record......

Read only

0 Likes
691

Try to mention first three fields in delete adjacent.

sort itab by field1 field2 field3.

DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>

COMPARING field1 field2 field3.

Now it should work.

Thanks

Seshu

Message was edited by:

Seshu Maramreddy

Read only

Former Member
0 Likes
691

Hi,

Try like this:

Delete Adjacent Duplicates From Itab.

Regards,

Bhaskar

Read only

Former Member
0 Likes
691

Hi

What do you really mean with DELETE?

It can't delete the fields, but it can clear or don't write their value:

SORT ITAB BY CODE NAME PRICE.

DATA: _NEW.

LOOP AT ITAB.
  _NEW = SPACE.

  AT NEW PRICE.
     _NEW = 'X'.
  ENDAT.

  IF _NEW = 'X'.
    WRITE: / ITAB-CODE, ITAB-NAME, ITAB-PRICE, ITAB-<FIELD>........
  ELSE.
    WRITE: / ITAB-<FIELD>........
  ENDIF.

ENDLOOP.

The field PRICE has to be define as CHAR field

Max

Read only

ferry_lianto
Active Contributor
0 Likes
692

Hi,

Please try this.


data: string_old(5),
      string_new(5).

sort itab.

loop at itab.
  at first.
    move: itab-code(2)  to string_old(2),
          itab-name(1)  to string_old+2(1), 
          itab-price(2) to string_old+3(2).
    
    continue.
  endat.     

  move: itab-code(2)  to string_new(2),
        itab-name(1)  to string_new+2(1), 
        itab-price(2) to string_new+3(2).

  if string_old = string_new.
    move: spaces to itab-code(2),
          spaces to itab-name(1),
          spaces to itab-price(2).
    
    modify itab.
  endif.

  string_old = string_new.

endloop.

Regards,

Ferry Lianto