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

How to compare two fields from the same table in the select statement

former_member215254
Participant
0 Likes
10,999

Hi, friends

I try to compare tow fields from the same table, but no result,

For example, this

data: cptotchek tyep i.

select count(*) into cptotchek

from aufk where erdat = aufk-idat2 .

The result is cptotchek = 0, but there are the records in aufk , where, aufk-erdat = aufk-idat2.

Please, help me, i don't use the loop statement for optimize my program.

Regards

Hi, friends

I try to compare tow fields from the same table, but no result,

For example, this

data: cptotchek tyep i.

select count(*) into cptotchek

from aufk where erdat = aufk-idat2 .

The result is cptotchek = 0, but there are the records in aufk , where, aufk-erdat = aufk-idat2.

Please, help me, i don't use the loop statement for optimize my program.

Regards

4 REPLIES 4
Read only

deepak_dhamat
Active Contributor
0 Likes
3,268

Hi ,

it will not return any value when you are using column of same table

such as Date Field , Because while Using Aggregate Function it will not check with self column

. For that you have to take data in one internal table and then you can work on it .

And if you are worried about Performance it will not affect , untill you are selecting only required data .

you can try this way .

data: cptotchek type i.

types : begin of w_aufk.

include structure aufk .

types : end of w_aufk .

data : it_aufk type standard table of w_aufk with header line .

select * into corresponding fields of table it_aufk

from aufk .

loop at it_aufk .

if it_aufk-erdat = it_aufk-idat2 .

write : / it_aufk-erdat , it_aufk-idat2 .

else .

delete it_aufk .

endif .

endloop.

Regards

Deepak.

Read only

Former Member
3,268

The ABAP help is your friend, just do the F1 on the SELECT statement. Let me give you the jump start now, so you're prepared for the next time...

Look at the [SELECT|http://help.sap.com/abapdocu_70/en/ABAPSELECT.htm] statement, drill down into the [WHERE|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] clause and then into the [sql_cond|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm]. There you'll see the following comment:

You can specify the same column names (comp, dbtabcomp, tabaliascomp) for col as are listed in the specification of single columns after SELECT.

The SELECT statement you've listed is only syntactically correct, if you have defined a variable or table with name AUFK. Most likely the variable is initial and thus you're searching for entries with a blank creation date (and naturally none should exist). So change your query to this:


select count(*) into cptotchek from aufk where erdat = aufk~idat2.

Note that for this single statement there's no need to define AUFK as a variable (via DATA or TABLES).

Cheers, harald

Read only

former_member215254
Participant
0 Likes
3,268

Thinks, problem solved, as the last's answer.

select count(*) into cptotchek from aufk where erdat = aufk~idat2.

Regards again.

Read only

former_member215254
Participant
0 Likes
3,268

Thinks, problem solved, as the last's answer.

select count(*) into cptotchek from aufk where erdat = aufk~idat2.

Regards again. Youu2019re the best.