‎2008 Oct 24 10:17 PM
Hello All,
I need to read a particular record from an internal table. Can you please help me build the logic?
Here's the scenario: I have Order Number and a flag as fields in an internal table. I need to pick the Order Number which is not flagged and next to the highest Order is which is flagged. Ignore anything in the middle. I know that I can get this done by creating another internal table. But was wondering how I do it using only 1 internal table.
In the following example, I need to pick Order 8450 because the highest flagged order is 7020.
Thanks a lot.
ITAB:
________
Order|Flag
9460|
8450|
7020|X
6030|X
5120|
5068|X
4320|X
2130|
1150|X
Thanks.
‎2008 Oct 24 10:25 PM
Something along the lines of:
READ TABLE itab WITH KEY flag = 'X'.
index = sy-tabix - 1.
READ TABLE itab INDEX index.I tested this and it does what I want it to do.
Rob
Edited by: Rob Burbank on Oct 24, 2008 5:31 PM
‎2008 Oct 24 10:25 PM
Something along the lines of:
READ TABLE itab WITH KEY flag = 'X'.
index = sy-tabix - 1.
READ TABLE itab INDEX index.I tested this and it does what I want it to do.
Rob
Edited by: Rob Burbank on Oct 24, 2008 5:31 PM
‎2008 Oct 24 10:32 PM
try to do that:
DATA: BEGIN OF itab OCCURS 0,
order(10),
flag,
END OF itab.
DATA: w_order LIKE itab-order,
w_tabix TYPE sy-tabix..
itab-order = 9460.
itab-flag = ' '.
APPEND itab.
itab-order = 8450.
itab-flag = ' '.
APPEND itab.
itab-order = 7020.
itab-flag = 'X'.
APPEND itab.
itab-order = 6030.
itab-flag = 'X'.
APPEND itab.
itab-order = 5120.
itab-flag = ' '.
APPEND itab.
itab-order = 5068.
itab-flag = 'X'.
APPEND itab.
itab-order = 4320.
itab-flag = 'X'.
APPEND itab.
itab-order = 2130.
itab-flag = ' '.
APPEND itab.
itab-order = 1150.
itab-flag = 'X'.
APPEND itab.
SORT itab BY order DESCENDING.
CLEAR w_tabix.
LOOP AT itab.
IF w_tabix IS INITIAL
AND itab-flag EQ 'X'.
w_tabix = sy-tabix.
ENDIF.
ENDLOOP.
w_tabix = w_tabix - 1.
READ TABLE itab INDEX w_tabix.
WRITE: itab-order.
‎2008 Oct 24 10:46 PM