‎2007 May 02 2:03 PM
Hi Colleagues,
how can we read a sorted internal table by reading a particular field which contains duplicate only once.
Thanks
Anuj
‎2007 May 02 2:06 PM
Hi,
READ TABLE ITAB WITH KEY xyz = xyz
abc = abc
a11 = a11
-
-
Do not use the Binary search with the read statment and use the correct values after the WITH KEY
Regards
Sudheer
‎2007 May 02 2:07 PM
Hi,.
say u have a itab
f1 f2
101 1000
102 1000
103 1001
104 1002
105 1002
now:
1. sort itab by f2.
2. loop at itab.
at new f2.
perform sub_name. "This sub routinge will fire only when f2 contains changes...
endloop
Jogdand M B
‎2007 May 02 2:19 PM
hi Jogdand,
i am using same but i am getting an error -- " at can be specified only once."
code :--
LOOP AT lt_qpk1cdtab INTO ls_qpk1cdtab at new codegruppe.
ls_qpk1cdtab_2 = ls_qpk1cdtab.
AT NEW codegruppe.
CLEAR ls_coding.
CONCATENATE is_entry_data-katalogart '%'
ls_qpk1cdtab_2-codegruppe INTO lv_parent_key.
MOVE lv_parent_key TO ls_coding-coding_key.
MOVE ls_qpk1cdtab_2-codegruppe
TO ls_coding-coding.
MOVE ls_qpk1cdtab_2-kurztextgr TO ls_coding-coding_text.
ls_coding-is_expanded = abap_false.
ls_coding-is_leaf = abap_false.
APPEND ls_coding TO lt_coding.
ENDAT.
CLEAR ls_coding.
CONCATENATE is_entry_data-katalogart '%'
ls_qpk1cdtab_2-codegruppe '%'
ls_qpk1cdtab-code
INTO ls_coding-coding_key.
MOVE ls_qpk1cdtab-code TO ls_coding-coding.
MOVE ls_qpk1cdtab-kurztextcd TO ls_coding-coding_text.
ls_coding-parent_key = lv_parent_key.
ls_coding-is_expanded = abap_false.
ls_coding-is_leaf = abap_true.
APPEND ls_coding TO lt_coding.
ENDLOOP.
‎2007 May 02 2:45 PM
Hi,
ur codes are correct BUT remove at new code gruppe from first line i.e. loop.. and uncomment at and endat in below lines.
LOOP AT lt_qpk1cdtab INTO ls_qpk1cdtab. "at new codegruppe. change here like this.
ls_qpk1cdtab_2 = ls_qpk1cdtab.
* AT NEW codegruppe.
CLEAR ls_coding.
CONCATENATE is_entry_data-katalogart '%'
ls_qpk1cdtab_2-codegruppe INTO lv_parent_key.
MOVE lv_parent_key TO ls_coding-coding_key.
MOVE ls_qpk1cdtab_2-codegruppe
TO ls_coding-coding.
MOVE ls_qpk1cdtab_2-kurztextgr
‎2007 May 03 3:35 AM
Hi Jogdand ,
wat is a difference , i already did that in my code pasted i mention ... at and end at within loop are commented.
Thanks
Anuj
‎2007 May 03 3:43 AM
‎2007 May 03 4:38 AM
In the loop statement you cannot use AT new , remove that
Remove the one in bold,
LOOP AT lt_qpk1cdtab INTO ls_qpk1cdtab <b>at new codegruppe</b>
‎2007 May 03 4:46 AM
than we are back to square one .... i need to reduce number of iterations of loop... initially i was using
loop at itab
at new codegruppe
endat .
endloop.
but this is a wrong usage as if codegruppe are duplicated lot many times we have a perfomance degradation. so how should i reduce the number of iterations.
please lemme know..
Anuj
‎2007 May 02 2:12 PM
use this way...
READ TABLE ITAB WITH KEY <field1> = <field1>
<field2> = <field2>
-
-
<fieldn> = <fieldn>.
‎2007 May 03 4:57 AM
say itab values are
f1 f2
100 1000
101 1000
102 1001
103 1001
104 1001So now you want to read the 2nd record as it is duplicate only once
data : count type i value '0'.
loop at itab.
at end of f2.
if count eq 1.
write : / itab-f1 , itab-f2. " here is ur record
count = 0.
endif.
endat.
count = count + 1.
endloop.
‎2007 May 03 5:03 AM
Hi chandreashekhar,
sorry for the confusion , i need to read all distinct values with minimum loop iteration .
F2 : - 1000 and 1001
Thanks
Anuj
‎2007 May 03 5:06 AM
Hi chandreashekhar,
sorry for the confusion , i need to read all distinct values with minimum loop iteration .
F2 : - 1000 and 1001
Thanks
Anuj
‎2007 May 03 5:07 AM
Then it is as simple as this....
loop at itab.
at new f2.
read table itab index sy-tabix.
write : / itab-f1 , itab-f2.
endat.
endloop.
‎2007 May 03 5:13 AM
Hi,
Thanks for your reply , ony one question here before i use this.... if say we have 5000 records and only 5 new f2 fields how many times loop would be executed.
will it be 5 in this case or 5000
Thanks
Anuj
‎2007 May 03 5:15 AM
You should have debugged and checked this ))
The use of Control commands is to trigger only when there is a change in field while looping , so i guess only 5 times
‎2007 May 03 5:23 AM
‎2007 May 03 5:24 AM
You cannot do as simple as that..I dont why you are hanging at a simple thing!!!!!!!!!!!!!!!!!!!!
‎2007 May 03 5:33 AM
‎2007 May 03 5:34 AM
‎2007 May 03 6:19 AM
i guess only solution could be delete adjacent duplicates and then loop...
thanks everybody..
Anuj