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

Loop at itab Where

k_gjergja
Participant
0 Likes
990

Hello ,

I have internal table with several  collons. In colon three the values can be repeated , and I have to read only the firs one

something like this

col1    col2   col3  

1           A     Y

2           B     Y

5           N     Y

3           V     X

7           T      X

I have to readd only the first line  of each entry in Col3 so in this case i am interested only in  line 1 A Y , and 3 V X .

I tryed wirh at new col3 but id doesn work because col1 and colé are not unique . Than I tryed  with loop where statement .

with this code .

data lv_col3 like itab-col3

Loop at itab in wa

where col3 NE lv_col3.

    lv_col3 = wa_col3

endloop.

The idea was to pass the value of col3 to local variable  and in next loop take the same in "where" condition. It doesnt work .The loop goes trough all lines of internal table.

The intrenal table is declared like  this itab TYPE TABLE OF pc261 (  structure ).

colon ther and  local vareiable  are char 6 type.

Please can you explain why where statement doesnt work in this case and advice how can i get only the first entry of each value  of the colon 3.

Thanks

8 REPLIES 8
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
934

it2 = itab.

delete adjacent duplicates from it2 comparing col3.

Simple ?

Umarking the thread as question due to its basic nature.

Read only

0 Likes
934

Hi, it is simple to delete .But that was not the question. I am courious why 'where' statemen doesnt work.

Read only

0 Likes
934

Then read the F1 help on LOOP AT.

Read only

Phillip_Morgan
Contributor
0 Likes
934

Hello,

Instead of using loop where... try with AT NEW event.

But to do this (check for yourself), you should:

- sort the table (by col3 col1?)

- loop normally

- use AT NEW (put your logic in here)

Note: be careful because in the at new some fields will be filled with '*' (asterisks). So you should use a temporary structure to hold current record

Read only

RaymondGiuseppi
Active Contributor
0 Likes
934

Just read the LOOP WHERE documentation

The logical expression declared after WHERE is evaluated once when the loop is entered. Any changes to the second operand during loop processing are ignored.

So you could remove the WHERE and use a CHECK as first statement inside LOOP.

LOOP AT itab INTO wa.
   CHECK wa-col3 NE lv_col3.
   APPEND wa TO itab2.
   lv_col3 = wa-col3.
ENDLOOP.

Regards,

Raymond

Read only

0 Likes
934

thanks

Read only

Former Member
0 Likes
934

Hi Krsto,

Try to make use of ON CHANGE OF statement in loop. This will allow to specify coloumn name. so this event will be triggered on change of value of that coloumn only.

For more information goto this link..

http://help.sap.com/abapdocu_702/en/abapon.htm

Regard,

Praveen

Read only

matt
Active Contributor
0 Likes
934

Did you notice in that link that ON CHANGE OF is obsolete.