Application Development 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: 

assign a FIELD-SYMBOL to a line of the internal table by index

Former Member
0 Kudos
3,298

Hi,

I would like to find out all the lines of an internal table itab (without headline) which have some fields in common.

so I defined two field-symbols <fs1> and <fs2>, looped the itab and assigned it  to <fs1> : LOOP AT itab ASSIGNING <fs1>.

Next step, I want to assign <fs2> to the following line of the current line, and compare <fs2> to <fs3> until the end of the page. I don't know how to assign a field-symbol to the specified line of a internal table.

Or if you have other propositions, please do not hesitate to tell me.

Thx a lot.

Yi

1 ACCEPTED SOLUTION

Former Member
0 Kudos
883

Try

LOOP AT xxx ASSIGNING <fs1>

l_tabix = sy-tabix + 1. "Next row

....

" Read Next Row

READ TABLE xxx ASSIGNING <fs2> INDEX l_tabix.

Regards,

Christian

4 REPLIES 4

Former Member
0 Kudos
884

Try

LOOP AT xxx ASSIGNING <fs1>

l_tabix = sy-tabix + 1. "Next row

....

" Read Next Row

READ TABLE xxx ASSIGNING <fs2> INDEX l_tabix.

Regards,

Christian

Former Member
0 Kudos
883

Hi Yi,

have you tried to implement one of the two most used searching algoritms?

- sequential/linear search

- binary search

If not, you can find lot of information and example code.

Regards,

Former Member
0 Kudos
883

Hi Yi

As Christian said above you can Read the table by Index while looping.

Or

You can Loop save the first line and then compare the second to the previous.

Eg.

LOOP AT itab ASSIGNING <fs1>.

     IF <fs2> IS INITIAL.

          <fs2> = <fs1>.

     ELSE.

          "Compare

     ENDIF.

ENDLOOP.

Regards

Vic

amy_king
Active Contributor
0 Kudos
883

Hi Yi,

See the section on control level processing in the document Processing Table Entries in Loops. Depending on what you are trying to do, you may be able to accomplish your task with the AT FIRST, AT NEW, AT LAST, AT END OF additions. Just be aware that the order of fields in the table structure and the sort order of records plays a role in control level processing.

Cheers,

Amy