Application Development 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: 

What is inverse of FOR ALL ENTRIES

Former Member
0 Kudos

Hi everyone!

The FOR ALL ENTRIES keyword gets the entries in a db table equal to the entries in an internal table right?

What is the inverse of that (meaning excluding the entries in an internal table)?

Thanks!

8 REPLIES 8

gopi_narendra
Active Contributor
0 Kudos

When you use FOR ALL ENTRIES there must be atleast one equality in the select statement to that of the FOR ALL ENTRIES internal table field.

This is what i meant -

You can use NE when you are using FOR ALL ENTRIES, but its always good to use +ve checks like = or IN where ever possible than NOT IN and <>.


select <data> from <table> 
              into table <itab2>
              for all entries in <itab1>
              where <field> NE itab1-<field>.

Rather you can also use the way below, but is always a performance issue and is not suggested always in cases like large data.

loop at itab.

select <data> from <table> into <itab2> where <field> <b>NE</b> itab-<field>.

clear : itab.

endloop.

Regards

Gopi

0 Kudos

This message was moderated.

Former Member
0 Kudos

hi richard,

i guess there is no direct opposite. either u have to use ur own logic or if entries are fewer u can use NOT IN {.....}.

regards,

sap fan

Former Member
0 Kudos

You can write other way :

Let me say one example :

i want to get material number as well Material description.

Material number at MARA Table,Material description at MAKT Table

you have two options like Join or for all entries.now i am not following join as well for all entries method.

data : begin of i_mara occurs 0,

matnr like mara-matnr,

end of i_mara.

  • final internal table

data : begin of i_final occurs 0,

matnr like mara-matnr,

maktx like makt-maktx,

end of i_final.

start-of-selection.

select * from mara into table i_mara.

loop at i_mara.

select single maktx from makt into makt-maktx

where matnr = i_mara-matnr

and spras = 'E'.

if sy-subrc eq 0.

i_final-matnr = i_mara-matnr.

i_final-maktx = i_makt-maktx.

append i_final.

endif.

endloop

check the above code ,i simply written select single *

but always use for all entries ,

Thanks

Seshu

GuyF
Active Participant
0 Kudos

I think the simplest solution is to create a range for the field that you base your exclude on.

For example, say you want to select from MARA, but exclude a few items, which are in local table lt_exclude.

DATA: LT_EXCLUDE TYPE STANDARD TABLE OF MARA,

WA_EXCLUDE TYPE MARA,

LT_MARA TYPE STANDARD TABLE OF MARA..

RANGES LR_MATNR FOR MARA-MATNR.

" BUILDING THE RANGE

LOOP AT LT_EXCLUDE INTO WA_EXCLUDE.

LR_MATNR-SIGN = 'I'.

LR_MATNR-OPTION = 'EQ'.

LR_MATNR-LOW = WA_EXCLUDE-MATNR.

LR_MATNR-HIGH = ' '.

APPEND LR_MATNR.

ENDLOOP.

" THE SELECT QUERY ITSELF

SELECT * FROM MARA INTO LR_MARA

WHERE MATNR NOT IN LR_EXCLUDE.

Hope this helps.

former_member194669
Active Contributor
0 Kudos

Hi,

Ranges have limitation of no of records. please check note 635318.

aRs

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You can make use of ranges to achieve that as follows.Kindly reward points by clicking the star on the left of reply,if it helps.

tables mara.

select-options s_matnr for mara-matnr.

ranges r_matnr for mara-matnr.

data : itab type standard table of mara,

wa type mara,

itab1 type standard table of makt,

wa1 type makt.

select * from mara into table itab where matnr in s_matnr.

if sy-subrc eq 0.

loop at itab into wa.

r_matnr-low = wa-matnr.

r_matnr-sign = 'I'.

r_matnr-option = 'EQ'.

append r_matnr.

endloop.

endif.

select * from makt into table itab1 where matnr not in r_matnr.

loop at itab1 into wa1.

write : / wa1-matnr.

endloop.

Former Member
0 Kudos

hi! Ricardo Caliolio

Can use

SELECT <data>FROM <table> INTO TABLE <itab2> FOR ALL ENTRIES IN

<itab1>

WHERE NE <itab1>

but Performance wise its not advisable.

Regards,

Nagulan.