Application Development and Automation 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: 
Read only

Performance -- loop at Internal table.

former_member196517
Contributor
0 Likes
1,827

Hi Colleagues,

how can we read a sorted internal table by reading a particular field which contains duplicate only once.

Thanks

Anuj

20 REPLIES 20
Read only

Former Member
0 Likes
1,767

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

Read only

Former Member
0 Likes
1,767

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

Read only

0 Likes
1,767

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.

Read only

0 Likes
1,767

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

Read only

0 Likes
1,767

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

Read only

0 Likes
1,767

i want to loop only for new codegruppe.

Read only

0 Likes
1,767

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>

Read only

0 Likes
1,767

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

Read only

Former Member
0 Likes
1,767

use this way...

READ TABLE ITAB WITH KEY <field1> = <field1>

<field2> = <field2>

-


-


<fieldn> = <fieldn>.

Read only

Former Member
0 Likes
1,767

say itab values are

f1      f2
100   1000
101   1000
102    1001
103    1001
104    1001

So 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.

Read only

0 Likes
1,767

Hi chandreashekhar,

sorry for the confusion , i need to read all distinct values with minimum loop iteration .

F2 : - 1000 and 1001

Thanks

Anuj

Read only

0 Likes
1,767

Hi chandreashekhar,

sorry for the confusion , i need to read all distinct values with minimum loop iteration .

F2 : - 1000 and 1001

Thanks

Anuj

Read only

0 Likes
1,767

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

.

Read only

0 Likes
1,767

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

Read only

0 Likes
1,767

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

Read only

0 Likes
1,767

5000 times... any other suggestion...

Read only

0 Likes
1,767

You cannot do as simple as that..I dont why you are hanging at a simple thing!!!!!!!!!!!!!!!!!!!!

Read only

0 Likes
1,767

Hi Experts we must be having a way , please lemme know .

Read only

0 Likes
1,767

Hi chandrasekhar i debugged and saw buddy ... its 5000..

Read only

0 Likes
1,767

i guess only solution could be delete adjacent duplicates and then loop...

thanks everybody..

Anuj