2013 Oct 30 5:31 PM
Hi experts ,
First of all happy Diwali.
I need you guy's help.
Actually my requirement is that I have my final internal table. I am displaying it my alv.
First internal table
exp :
Column A B C D E
10 7 1 3 5
2 4 4 7 8
now I have one more internal table with only one column in which it is containing the field name of first internal table dynamically ( Means my second internal table can may be ( A , B ) or may ( A and E ) in
Eg. Col1 or col1
A A
B E
Now I want to find duplicate entry from my first internal table for only those field of my table which are in my second tables Col1 like ( A and B) or ( A and E)
Please help me .
Thanks and Regards
Bipin
2013 Oct 30 5:42 PM
2013 Oct 30 6:27 PM
If your second table has columns A and B. Are you trying to find duplicates in column A and duplicates in column B of first table? Or do you mean the duplicates comparing columns A and B?
Regards,
Steve
2013 Oct 31 4:55 AM
Hi Steve,
Yes if my second table has column A and B.
Then I am trying to find out duplicate entry ( or duplicate value of Column A and B in my first table )
Eg.
First table
A B C D E
10 4 3 4 1
8 9 4 2 6
10 4 11 12 0
It means line item 1 and 3 is duplicate row or entry in my first table.
I already did this for static fixed column , but i am getting problem when column become dynamic
like ( some time A and B or some time D or E )
Thanks and Regards
Bipin
2013 Oct 31 6:04 AM
Hi Bipin,,
What will you do with the duplicate entries? Can you elaborate that??
Then it is possible to tell you..
And share your code also. It will help us.
Thanks,
Ajit
2013 Oct 31 6:31 AM
Hi Ajit
Thanks for reply.
I Just want mark red those duplicate entries and want to display " duplicate entry " comment on remark field in alv.
Thanks and Regards
Bipin
2013 Oct 31 6:47 AM
ITAB1 has field name
COL1
A
B
ITAB2 has
COl A B C D
1 2 3 4
2 4 5 5
1 2 3 4
Loop at ITAB1.
sort ITAB2 by (ITAB1-COL1).
concatenate 'ITAB2-' ITAB1-COL into lv_field.
LOOP at ITAB2.
lv_count = lv_count + 1.
if lv_val ne (lv_field).
lv_val = (lv_field).
else.
if lv_count gt 1
" Meaning more than one entry. highlight or add coment
endif.
endif.
ENDLOOP
2013 Oct 31 9:19 AM
Dear nabheet madan
Thanks for Reply.
Can you tell me what is lv_val in ur logic
2013 Oct 31 10:07 AM
LV_VAL will be blank initially so first time when your loop will go it will store its value that yes for value 10 one entry has come. Next time it will check if same then mean duplicate(lv_counter greater than 1) else different you assign new value and initialize lv_count = 1.
ITAB1 has field name
COL1
A
B
ITAB2 has
COl A B C D
1 2 3 4
2 4 5 5
1 2 3 4
Loop at ITAB1.
sort ITAB2 by (ITAB1-COL1).
concatenate 'ITAB2-' ITAB1-COL into lv_field.
LOOP at ITAB2.
lv_count = lv_count + 1.
if lv_val ne (lv_field).
lv_val = (lv_field).
lv_count = 1.
else.
if lv_count gt 1
" Meaning more than one entry. highlight or add coment
endif.
endif.
ENDLOOP
2013 Oct 31 7:03 AM
Hi Bipin,
Do you want delete the duplicate entries or you want bring out in separate table ?
Regards,
Mujeeb
2013 Oct 31 7:58 AM
Hi Bipin,
I misuderstood your requirement.
You have to make slight changes to the code I had given before.
You will get your output.
it_dat1 is your internal table with data, and it_col is your internal table containing column names of the first table.
I have another table it_dat1_tmp with the same structure as your first internal table.
Follow this logic, you will get the output.
it_dat1_tmp[] = it_dat1.
loop at it_col into wa_col.
sort it_dat1_tmp by (wa_col-col).
delete ADJACENT DUPLICATES FROM it_dat1_tmp COMPARING (wa_col-col).
endloop.
loop at it_dat1 into wa_dat1.
if wa_tmp = wa_dat1.
wa_dat1-remark = 'Duplicate entry'.
modify it_dat1 from wa_dat1 TRANSPORTING remark.
endif.
read table it_dat1_tmp into wa_tmp FROM wa_dat1.
if sy-subrc ne 0.
wa_dat1-remark = 'Duplicate entry'.
modify it_dat1 from wa_dat1 TRANSPORTING remark.
endif.
wa_tmp = wa_dat1.
clear wa_dat1.
endloop.
loop at it_dat1 into wa_dat1.
write 😕 wa_dat1.
endloop.
Message was edited by: Susmitha Susan Thomas
2013 Oct 31 10:14 AM
ok
so you can try something like this:
DATA: BEGIN OF ITAB OCCURS 0,
A(2),
B(2),
C(2),
D(3),
E(2),
END OF ITAB.
DATA: BEGIN OF ITAB_KEY OCCURS 0,
FIELD_NAME(1) TYPE C,
END OF ITAB_KEY.
DATA: BEGIN OF ITAB_VAL OCCURS 0,
KEY(15) TYPE C,
INDEX TYPE I,
END OF ITAB_VAL.
FIELD-SYMBOLS: <FS_VAL> TYPE ANY.
DATA: L_POS TYPE I,
L_OFFSET TYPE I.
START-OF-SELECTION.
DO 2 TIMES.
ITAB-A = '1'.
ITAB-B = '11'.
ITAB-C = '2'.
ITAB-D = '200'.
ITAB-E = '4'.
APPEND ITAB.
ENDDO.
DO 2 TIMES.
ITAB-A = '21'.
ITAB-B = '12'.
ITAB-C = '24'.
ITAB-D = '150'.
ITAB-E = '6'.
APPEND ITAB.
ENDDO.
ITAB_KEY-FIELD_NAME = 'A'.
APPEND ITAB_KEY.
ITAB_KEY-FIELD_NAME = 'B'.
APPEND ITAB_KEY.
ITAB_KEY-FIELD_NAME = 'E'.
APPEND ITAB_KEY.
LOOP AT ITAB.
CLEAR ITAB_VAL.
ITAB_VAL-INDEX = SY-TABIX.
L_OFFSET = 0.
LOOP AT ITAB_KEY.
ASSIGN COMPONENT ITAB_KEY-FIELD_NAME OF STRUCTURE ITAB TO <FS_VAL>.
IF SY-SUBRC = 0.
DESCRIBE FIELD <FS_VAL> LENGTH L_POS IN CHARACTER MODE.
MOVE <FS_VAL> TO ITAB_VAL-KEY+L_OFFSET(L_POS).
L_OFFSET = L_OFFSET + L_POS.
ENDIF.
ENDLOOP.
APPEND ITAB_VAL.
ENDLOOP.
SORT ITAB_VAL BY KEY.
WRITE: 'Duplicated key:'.
LOOP AT ITAB_VAL.
AT NEW KEY.
WRITE: / ITAB_VAL-KEY.
ENDAT.
WRITE: / ITAB_VAL-INDEX.
ENDLOOP.
Max
2013 Oct 31 11:39 PM
Hello Bipin,
Here is the logic for your requirement,
Declare a new field inside the internal table called newfield (or any suitable name) this will help you to identify the duplicate records.
Declaration:
Assigning values:
Logic:
Result:
Here I'm comparing the duplicate records with respect to the fields A and C. With the help of the newfield you can understand the duplicate records.
Hope this one is helpful for you.
Thanks
Nivash S