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

Logic

Former Member
0 Likes
398

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

3 REPLIES 3
Read only

former_member194669
Active Contributor
0 Likes
382

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

Read only

Former Member
0 Likes
382

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.

Read only

former_member378318
Contributor
0 Likes
382

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.