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

Select statement

Former Member
0 Likes
708

Hi Gurus,

I need to select all the records from Z_tab to it_tab that meet below conditions:

mode = a or b

amount1 < amount2

and for this I have written the following code

select * into table it_tab

from z_tab

for all entries in it_temp

where mode = 'A' or mode = 'B'

and amount1 < amount2.

but its showing me an error that field amount2 is unkown, although this field is defined in my z_tab table.

please help me out.

Thanks

Rajeev Gupta

6 REPLIES 6
Read only

Former Member
0 Likes
689

Hi,

Hope your Ztab contains amount1 and amount2 fields.

For that select using

select * into table it_tab

from z_tab

for all entries in it_temp

where mode = 'A' or mode = 'B'.

delete it_itab where amount2 ge amount1.

finally you will have the required values in it_itab.

Regards,

Baburaj

Read only

Former Member
0 Likes
689

HI,

In this select you are trying to compare the two database table fields which is not possible. rather do this.

select * from z_tab into table itab where mode in ('A','B').

if sy-subrc eq 0.

delete itab where amont1 > amount2.

endif.

Y are u using the for all entris in it_Temp does this table contains amount2?

if yes

then use this.

select * from z_tab for all enteris in it_temp into table itab where mode in ('A','B') and amount1 < it_temp-amount2..

Thanks

mahesh

Read only

Former Member
0 Likes
689

You cannot do that in one single select statement. Easiest will be to get all the records (include the columns amount1 and amount2 as well to your itab) just based on mode and then loop at the itab. delete the record if amount1 < amount2.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
689

try amount2 > amount1

Read only

varma_narayana
Active Contributor
0 Likes
689

Hi..

The error is coming bcoz amount1 is not a field in ur Table zTab.

You have to change the query like this:

select * into table it_tab

from z_tab

for all entries in it_temp

where mode = 'A' or mode = 'B'

and amount2 > amount1.

<b>Reward if Helpful</b>

Read only

Former Member
0 Likes
689

use tablename.ammount2 it wil remove ur error

use the tablename to wich amnt2 is associated