Skip to Content
avatar image
Former Member

checking if a value exists in a standard table

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!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 28, 2008 at 12: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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 28, 2008 at 12:24 PM

    hi wuyia nata

    Select single * from dbtab into wa

    where condition.

    if sy-subrc = 0.

    exists.

    esle.

    no records

    endif,

    Regards

    Deva

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 28, 2008 at 12: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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 28, 2008 at 12: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 28, 2008 at 12:28 PM

    Hi,

    check this sample code for retrieving data from mara

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

    regards

    padma

    Add comment
    10|10000 characters needed characters exceeded