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: 

Reg : Logic in ABAP

Former Member
0 Kudos

Hi Experts ,

I need some logic from u r side ..

For example !!!

1 . iam having table sbook which contains some duplicate entries.

my ques is iam planning to write some logic in my ypsu_cos Program.

i.e 1. First it has to delete all duplicate entries from sbook table .

2. from now onwards it has to check each & evry time , if any duplicate entry exits or not ? if so it has to delete the entry & if not it has to insert the value

Regs ,

Narayana Murthy

8 REPLIES 8

sastry_gunturi
Active Participant
0 Kudos

Use

DELETE ADJACENT DUPLICATES

Former Member
0 Kudos

Hi Narayana,

You can use this logic:

1.


SORT itab BY field1 field2.       " Sort the internal table first
DELETE ADJACENT DUPLICATES FROM itab COMPARING field1 field2.

2.


READ TABLE itab INTO wa_itab WITH KEY field1 = new-field1 field2 = new-field2.
IF sy-subrc NE 0.
  APPEND new TO itab.
ENDIF.

former_member196280
Active Contributor
0 Kudos

Hi Murthy,

Do the following, it will solve your problem.

1) SORT <internal table name> by field.

DELETE ADJACENT DUPLICATE ENTIRES FROM < internal table name>.

2) READ TABLE <internal table name> FROM <work area>

IF sy-subrc NE 0.

***INSERT your value

ENDIF.

Reward point if useful.

Regards,

SaiRam

Former Member
0 Kudos

Narayana,

You can use this logic:

1.

SORT itab BY field1 . " Sort the internal table first

DELETE ADJACENT DUPLICATES FROM itab COMPARING field1.

2.

In your loop of internal table...

LOOP AT ITAB

READ TABLE itab WITH KEY field1 = new-field1 binary search.

IF sy-subrc NE 0.

APPEND new TO itab.

ENDIF.

ENDLOOP.

Don't forget to reward if useful....

Former Member
0 Kudos

1) sort itab by <field name>.

delete adjacent duplicates from itab [comparing <field name(s)>].

2) take a int table ifinal like your itab(which contains data).

now..

loop at itab.

read table ifinal with key <field> = itab-<field>.

if sy-subrc = 0.

<you can modify ifinal by modify ifinal index sy-tabix after calculation.>

else.

append itab to ifinal.

endif.

clear : ifinal.

endloop.

regards

shiba dutta

mohammed_moqeeth
Active Participant
0 Kudos

Hi Narayana,

<u>You have to sort the table first then delete the duplicate entries as shown below:</u>

<b>sort itab by field1 field2 field3.

DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>

COMPARING field1 field2 field3.</b>

Regards,

Moqeeth.

Former Member
0 Kudos

see the below program for deleteing the dupicate Entries ...

DATA: BEGIN OF connection, 
        cityfrom TYPE spfli-cityfrom, 
        cityto   TYPE spfli-cityto, 
        distid   TYPE spfli-distid, 
        distance TYPE spfli-distance, 
      END OF connection. 

DATA connection_tab LIKE SORTED TABLE OF connection 
                    WITH NON-UNIQUE KEY cityfrom cityto 
                                        distid distance. 

SELECT cityfrom cityto distid distance 
       FROM spfli 
       INTO TABLE connection_tab. 
INSERT ADJACENT DUPLICATES FROM connection_tab. 
DELETE ADJACENT DUPLICATES FROM connection_tab. 

.

reward points if it is usefull ...

Girish

Former Member
0 Kudos

Hi Narayana,

Use this Command to avoid dublicate.

First sort that internal table by any of that field.

SORT ITAB_HEADER BY BANFN.

DELETE ADJACENT DUPLICATES FROM ITAB_HEADER COMPARING BANFN.

ITAB_HEADER is internal table.

IF USEFULL REWARD.