2008 Jul 11 6:19 PM
I want to do something like this....
Let's say my ITAB has MATNR & DUP fields & let's say ITAB has entries like this...
ITAB-MATNR ITAB-DUP
123
123
345
456if any of the MATNR's are repeated in ITAB I want to flag DUP for such repeated records so the ITAB would look like below......
ITAB-MATNR ITAB-DUP
123
123 X
345
456Please note : only the records repeated after the first unique record should be flagged.
2008 Jul 11 6:33 PM
Try this
REPORT zrich_0001.
TYPE-POOLS: abap.
TYPES: BEGIN OF ttab,
matnr(18) TYPE c,
dup TYPE abap_bool,
END OF ttab.
DATA: itab TYPE TABLE OF ttab.
DATA: wa LIKE LINE OF itab.
DATA: itab_copy TYPE TABLE OF ttab.
DATA: wa_copy LIKE LINE OF itab_copy.
DATA: tabix TYPE i.
wa-matnr = '000000000000000123'. APPEND wa TO itab.
wa-matnr = '000000000000000123'. APPEND wa TO itab.
wa-matnr = '000000000000000123'. APPEND wa TO itab.
wa-matnr = '000000000000000345'. APPEND wa TO itab.
wa-matnr = '000000000000000456'. APPEND wa TO itab.
wa-matnr = '000000000000000456'. APPEND wa TO itab.
itab_copy = itab.
LOOP AT itab_copy INTO wa_copy.
tabix = sy-tabix + 1.
LOOP AT itab INTO wa FROM tabix
WHERE matnr = wa_copy-matnr.
wa-dup = abap_true.
MODIFY itab FROM wa.
ENDLOOP.
ENDLOOP.
LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-dup.
ENDLOOP.Regards,
Rich Heilman
I want to do something like this....
Let's say my ITAB has MATNR & DUP fields & let's say ITAB has entries like this...
ITAB-MATNR ITAB-DUP
123
123
345
456if any of the MATNR's are repeated in ITAB I want to flag DUP for such repeated records so the ITAB would look like below......
ITAB-MATNR ITAB-DUP
123
123 X
345
456Please note : only the records repeated after the first unique record should be flagged.
2008 Jul 11 6:22 PM
loop at itab.
if itab-matnr = v_matnr.
itab-dup = 'X'.
endif.
v_matnr = itab-matnr.
modify itab index sy-tabix.
endloop.
2008 Jul 11 6:28 PM
Sort itab by matnr.
loop at itab.
if sy-tabix eq 1.
v_matnr = itab-matnr.
else
if itab-matnr = v_matnr.
itab-dup = 'X'.
endif.
v_matnr = itab-matnr.
modify itab index sy-tabix.
endif.
endloop.
Just some additional inputs for Ravis logic
Cheers
Kothand
2008 Jul 11 6:26 PM
sort itab by matnr.
loop at itab.
at new matnr.
clear counter.
end at.
counter = counter + 1.
if counter gt 1.
itab - dup = X.
modify itab.
endif.
endloop.
2008 Jul 11 6:27 PM
Hi,
Try this..
SORT itab BY matnr.
data: v_prev_matnr type matnr.
field-symbols: <wa> LIKE LINE OF ITAB.
LOOP AT ITAB ASSIGNGING <WA>.
IF sy-tabix = 1.
v_prev_matnr = <wa>-matnr.
ENDIF.
if v_prev_matnr ne <wa>-matnr.
clear: v_count.
endif.
v_count = v_count + 1.
* Set the duplicate flag..if there is more than one record.
if v_count > 1.
<wa>-dup = 'X'.
endif.
v_prev_matnr = <wa>-matnr.
ENDLOOP.Hope this helps.
Thanks
Naren
2008 Jul 11 6:33 PM
Try this
REPORT zrich_0001.
TYPE-POOLS: abap.
TYPES: BEGIN OF ttab,
matnr(18) TYPE c,
dup TYPE abap_bool,
END OF ttab.
DATA: itab TYPE TABLE OF ttab.
DATA: wa LIKE LINE OF itab.
DATA: itab_copy TYPE TABLE OF ttab.
DATA: wa_copy LIKE LINE OF itab_copy.
DATA: tabix TYPE i.
wa-matnr = '000000000000000123'. APPEND wa TO itab.
wa-matnr = '000000000000000123'. APPEND wa TO itab.
wa-matnr = '000000000000000123'. APPEND wa TO itab.
wa-matnr = '000000000000000345'. APPEND wa TO itab.
wa-matnr = '000000000000000456'. APPEND wa TO itab.
wa-matnr = '000000000000000456'. APPEND wa TO itab.
itab_copy = itab.
LOOP AT itab_copy INTO wa_copy.
tabix = sy-tabix + 1.
LOOP AT itab INTO wa FROM tabix
WHERE matnr = wa_copy-matnr.
wa-dup = abap_true.
MODIFY itab FROM wa.
ENDLOOP.
ENDLOOP.
LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-dup.
ENDLOOP.Regards,
Rich Heilman
2008 Jul 11 6:38 PM
Full points to Rich as I need not sort the ITAB to get this thing working.....
2008 Jul 11 6:40 PM
Raju....
You did not tell us that you did not wanted to sort the itab..:(...
add a clear statement after my code to make it work..I cannot edit it now...
Just kidding....:)
Edited by: Ravi Kanth Talagana on Jul 11, 2008 7:40 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |