cancel
Showing results for 
Search instead for 
Did you mean: 

help on logic

Former Member
0 Kudos

Hi abapers.

i want to write a select statement as follows.

i have aufnr & auart fields in itab_aufk internal table.

i want to get some other fields from RSEB table.

the selection criteria is diff from order types.

loop at itab_aufk.

if itab_aufk-auart eq 'ZRF' or 'ZAC'.

select rsnum meins ...into iab_resb

from RESB

for all entries in itab_afko

where rsnum = itab_afko-rsnum

and rnpos ne '1'.

else.

select rsnum meins ...into iab_resb

from RESB

for all entries in itab_afko

where rsnum = itab_afko-rsnum.

endloop.

i want to avoide the loop statement for the above logic.

is there any alternative.

Please help me.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188685
Active Contributor
0 Kudos

Try using this logic .Get the select out of the loop



select rsnum meins ...into iab_resb
from RESB
for all entries in itab_afko
where rsnum = itab_afko-rsnum
and rnpos ne '0001'.


loop at itab_aufk.
if itab_aufk-auart eq 'ZRF' or 'ZAC'.
  read table it_afko with key aufnr = itab_aufk-aufnr.
    if sy-subrc = 0.
      read table it_resb with key rsnum = it_afko-rsnum. 
       if sy-subrc = 0 and it_resb-rnpos ne '0001'.
       endif. 
    endif.
  else.
   read table it_afko with key aufnr = itab_aufk-aufnr.
     if sy-subrc = 0.
      read table it_resb with key rsnum = it_afko-rsnum. 
       if sy-subrc = 0.
       endif. 
    endif.
endif.

endloop.

Answers (5)

Answers (5)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

select rsnum meins ...into table itab_resb

from RESB

for all entries in itab_afko

where rsnum = itab_afko-rsnum.

loop at itab_aufk.

read table itab_resb with key rsnum = itab_aufk-rsnum.

if sy-subrc eq 0 and itab_resb-mpos eq '1' and

( itab_aufk-auart = 'ZRF' or

itab_aufk-auart = 'ZAC' ).

delete itab_resb where rsnum = itab_aufk-rsnum and

mpos = itab_resb-mpos .

endif.

endloop.

Since loop is used here for internal table,it won't affect performance.

KIndly reward points if it helps.

Former Member
0 Kudos

Hi,

You can try this out.

declare another table itab_aufk1(example) and pass all the records of itab_aufk into this table.

DELETE itab_aufk WHERE itab_aufk-auart = 'ZRF' or 'ZAC'.

DELETE itab_aufk1 WHERE itab_aufk1-auart <> 'ZRF' and 'ZAC'.

Now itab_aufk will have records where auart <> either ZRF or ZAC

itab_aufk1 will have records where auart = ZRF or ZAC.

Now you can select records from RSEB based on the requirement.

Select .....for all entries in itab_aufk

into table ....

Select .... for all entries in itab_aufk1

appending table ... (I am not sure what your requirement is).

Hope this helps.

Vamsi

Former Member
0 Kudos

select rsnum meins rnpos...into iab_resb

from RESB

for all entries in itab_afko

where rsnum = itab_afko-rsnum

loop at itab_aufk.

l_index = sy-tabix.

if itab_aufk-auart eq 'ZRF' or 'ZAC'.

read table iab_resb index l_index.

if iab_resb-rnpos eq '1'.

delete iab_resb index l_index.

endif.

endif.

endloop.

Message was edited by: chandrasekhar jagarlamudi

Former Member
0 Kudos

Ramesh

Change as follows: <b> rspos ne '0001'</b>

Thanks

Kay

Former Member
0 Kudos

get all the data form resb into itab_resb depending on rsnum cond and delete all the record which rnpos = 1.

later process requiered record in internal table

Former Member
0 Kudos

I would suggest the logic as this way .

DATA : l_tabix TYPE sy-tabix .

IF LINES( itab_afko ) <> 0 .

SELECT rsnum rnpos meins ...

into iab_resb

from resb

for all entries in itab_afko

where rsnum = itab_afko-rsnum

endif.

SORT itab_afko BY rsnum .

LOOP AT iab_resb.

l_tabix = sy-tabix .

READ TABLE itab_afko WITH KEY rsnum = itab_afko-rsnum

BINARY SEARCH .

IF sy-subrc EQ 0 .

IF itab_aufk-auart EQ 'ZRF' OR 'ZAC' AND iab_resb-rnpos EQ '1'.

DELETE iab_resb INDEX l_tabix .

ENDIF .

ENDIF .

clear l_tabix .

ENDLOOP.

Let me know if you have any doubt .

Regards,

Vijay .

Message was edited by: VijayKumar Sharma