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: 

for all entries-dupli

Former Member
0 Kudos

how to avoid duplicate entries in a table using for all entries

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The following are required when you are using FOR ALL ENTRIES..

1)

Remove the duplicate entries for the key that you are selecting on.

2)

Check if the internal table is populated before using FOR ALL ENTRIES.

3)

Select all the key fields of the table that you are going to select..

Example

-


DATA: ITAB_VBAK LIKE VBAK OCCURS 0 WITH HEADER LINE.

DATA: ITAB_VBAP LIKE VBAP OCCURS 0 WITH HEADER LINE.

DATA: ITAB_VBAP_TMP LIKE VBAP OCCURS 0 WITH HEADER LINE.

SELECT MANDT VBELN POSNR INTO TABLE ITAB_VBAP

FROM VBAP

WHERE MATNR IN SO_MATNR.

IF SY-SUBRC = 0.

ITAB_VBAP_TMP = ITAB_VBAP.

SORT ITAB_VBAP_TMP BY VBELN.

DELETE ADJACENT DUPLICATES FROM ITAB_VBAP_TMP

COMPARING VBELN.

IF NOT ITAB_VBAP_TMP[] IS INITIAL.

SELECT MANDT VBELN

INTO TABLE ITAB_VBAK

FROM VBAK

FOR ALL ENTRIES IN ITAB_VBAP_TMP

WHERE VBELN = ITAB_VBAP_TMP-VBELN.

ENDIF.

Thanks,

Naren

2 REPLIES 2

rahulkavuri
Active Contributor
0 Kudos

hi instead of using for all entries with select stmt

move the contents of that table into another internal table and remove the duplicate entries & then select contents

Remove all the duplicate entries before using the select statement.

itab2[] = itab1[].

sort itab1.

delete adjacent dupilcates from itab1.

then use the for all entries

Former Member
0 Kudos

Hi,

The following are required when you are using FOR ALL ENTRIES..

1)

Remove the duplicate entries for the key that you are selecting on.

2)

Check if the internal table is populated before using FOR ALL ENTRIES.

3)

Select all the key fields of the table that you are going to select..

Example

-


DATA: ITAB_VBAK LIKE VBAK OCCURS 0 WITH HEADER LINE.

DATA: ITAB_VBAP LIKE VBAP OCCURS 0 WITH HEADER LINE.

DATA: ITAB_VBAP_TMP LIKE VBAP OCCURS 0 WITH HEADER LINE.

SELECT MANDT VBELN POSNR INTO TABLE ITAB_VBAP

FROM VBAP

WHERE MATNR IN SO_MATNR.

IF SY-SUBRC = 0.

ITAB_VBAP_TMP = ITAB_VBAP.

SORT ITAB_VBAP_TMP BY VBELN.

DELETE ADJACENT DUPLICATES FROM ITAB_VBAP_TMP

COMPARING VBELN.

IF NOT ITAB_VBAP_TMP[] IS INITIAL.

SELECT MANDT VBELN

INTO TABLE ITAB_VBAK

FROM VBAK

FOR ALL ENTRIES IN ITAB_VBAP_TMP

WHERE VBELN = ITAB_VBAP_TMP-VBELN.

ENDIF.

Thanks,

Naren