2013 May 15 8:27 AM
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
2013 May 15 9:03 AM
it2 = itab.
delete adjacent duplicates from it2 comparing col3.
Simple ?
Umarking the thread as question due to its basic nature.
2013 May 15 9:11 AM
Hi, it is simple to delete .But that was not the question. I am courious why 'where' statemen doesnt work.
2013 May 15 9:25 AM
2013 May 15 9:21 AM
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
2013 May 15 9:25 AM
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
2013 May 15 10:03 AM
2013 May 16 7:54 AM
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
2013 May 16 8:32 AM