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

Extract 3rd record

Former Member
0 Likes
995

Hi experts,

I am having 6 records in itab.

how to select 3rd height value.

1 100

2 130

3 90

4 90

5 100

6 120.

Please give me code.

I think first sort and next delete adjacent duplicate records next?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
964

Delete adjacent duplicates wont work here because the combination of two fields is unique. If you want to read exactly the third record then go for READ with INDEX 3.

If you mean you want to select the record with third highest value, then please specify if you are looking for the value in field1 or field 2.

8 REPLIES 8
Read only

Former Member
0 Likes
964

read table index 3

Read only

Former Member
0 Likes
964

hi praven

sort itab by descending.

delete adjacent duplicates of itab comapring <field>

read table itab index 3.

regards

deva

Read only

Former Member
0 Likes
964

Hi Dude,

first U delete adjacent duplicates from itab,

Then U sort the itab by Descending .

Then U read itab with sy-tabix = 3.

Hope this helps U.

Read only

Former Member
0 Likes
965

Delete adjacent duplicates wont work here because the combination of two fields is unique. If you want to read exactly the third record then go for READ with INDEX 3.

If you mean you want to select the record with third highest value, then please specify if you are looking for the value in field1 or field 2.

Read only

0 Likes
964

F2 value

Read only

0 Likes
964

Then just sort the internal table in the descending order based on F2, and read the index at 3.

SORT itab DESCENDING by F2.

READ table ITAB index 3 INTO wa_itab.

WRITE wa_itab-f2.

this will give you the required value

Read only

0 Likes
964

Hi,

There wont be much changes needed even if you want to read teh third record based on field2.

You need to sort the internal table based on second field and follow the same process suggested by others.

sort itab by field2 descending

delete adjacent duplicates conparing field2

read itab with index 3

Hope this will help.

Regards,

Swarna Munukoti.

Edited by: Swarna Munukoti on Aug 27, 2008 7:27 AM

Read only

Former Member
0 Likes
964

Hi,

plz try this way :


DATA: BEGIN OF TYPE_ITAB,
COL1 TYPE I,
COL2 TYPE I,
END OF TYPE_ITAB.

DATA: ITAB LIKE SORTED TABLE OF TYPE_ITAB WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.

READ TABLE ITAB ASSIGNING <FS> INDEX 3.
....

<FS> will have 3 and 90 values i.e. 3rd record.

hope this helps.

thanx,

dhanashri.