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: 

checking if a value exists in a standard table

Former Member

Hi everyone, a simple question. Can anyone show me an code example for reading a standard table while checking if a certain value exists in a field of the table?

Thanks!

1 ACCEPTED SOLUTION

Former Member

Hi wuyia nata,

You can use where condition to understand this.

For example;

Select single * from Pa0002

WHERE NACHN EQ 'wuyia'.

if sy-subrc eq 0.

Write: 'Value found'.

else.

Write: 'No such data'.

endif.

Of course you firstly should provide key fields at where.

Hope helps.

5 REPLIES 5

JozsefSzikszai
Active Contributor

hi,

if you only want to know if the entry exists or not, than best is to use SELECT COUNT. Something like:

SELECT COUNT( * )
FROM ...
WHERE...

IF sy-subrc EQ 0.
==> exists
ELSE.
==> does not exist
ENDIF.

hope this helps

ec

Former Member
0 Kudos

hi wuyia nata

Select single * from dbtab into wa

where condition.

if sy-subrc = 0.

exists.

esle.

no records

endif,

Regards

Deva

Former Member
0 Kudos

Hi Nata,

Use SELECT query with WHERE clause and specify the field name which you are looking for data in WHERE clause.

Eg: Looking for particular plant for a material


SELECT *
    FROM MARC
    INTO GT_MARC
 WHERE WERKS = <Particular Plant/Plant(s)>.

Thanks,

Vinay

Former Member

Hi wuyia nata,

You can use where condition to understand this.

For example;

Select single * from Pa0002

WHERE NACHN EQ 'wuyia'.

if sy-subrc eq 0.

Write: 'Value found'.

else.

Write: 'No such data'.

endif.

Of course you firstly should provide key fields at where.

Hope helps.

Former Member
0 Kudos

Hi,

check this sample code for retrieving data from mara

select single * from mara
     into wa where matnr = '100-100'.

regards

padma