08-28-2008 1:18 PM
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!
08-28-2008 1:26 PM
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.
08-28-2008 1:21 PM
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
08-28-2008 1:24 PM
hi wuyia nata
Select single * from dbtab into wa
where condition.
if sy-subrc = 0.
exists.
esle.
no records
endif,
Regards
Deva
08-28-2008 1:25 PM
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
08-28-2008 1:26 PM
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.
08-28-2008 1:28 PM
Hi,
check this sample code for retrieving data from mara
select single * from mara
into wa where matnr = '100-100'.
regards
padma