‎2007 Aug 14 4:55 PM
Hi Friends,
I have records in the databae table like below.
ORDERNO STATUS
100----
N
100----
N
100----
Y
200----
N
I need to pickup the records which contains status = 'N' but If any one ORDERNO contains
the status 'Y' then i need to elimate that orderno for example in this case i need to select only
orderno 200
Pls advise me some logic for this
Thanks in advance
karthik
‎2007 Aug 14 5:00 PM
Hi,
itab1[] = itab[].
loop at itab.
read table itab1 with key orderno = itab-orderno
status = 'Y'.
if sy-subrc eq 0.
delete itab1 where orderno = itab-orderno.
endif.
endloop,
After this loop itab1 contains only N status order numbers
aRs
‎2007 Aug 14 5:05 PM
sort itab by orderno status.
itab_copy[] = itab[].
loop at itab.
loop at itab_copy where orderno = itab-orderno and status = 'Y'.
delete itab where orderno = itab_copy-orderno.
exit.
endloop.
endloop.
At the end itab will have only records that have a status N but no Y.
You can also do it this way.
itab_copy[] = itab[].
delete itab where status = 'Y'.
delete itab_copy where status = 'N'.
loop at itab.
read table itab_copy with key orderno = itab-orderno.
if sy-subrc = 0.
delete itab.
continue.
endif.
endloop.
‎2007 Aug 14 5:28 PM
Try the following if selecting straight from the database:
SELECT *
INTO TABLE itab1
FROM your_table AS your_table1
WHERE status = 'N'
AND NOT EXISTS ( SELECT *
FROM your_table
WHERE order_no = your_table1~order_no
AND status = 'Y' ).
Hope it helps.