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: 

Check if Table contains specific value

Former Member
0 Kudos

Hi Guru's,

How do i check if a table contains a specific value?

I want to check if a table contains the value that a user entered, is there any option to check the table without select query.

or

which is the best way to check the table for a specific record with respect to performance?

Regards,

Sudheer.M

13 REPLIES 13

paul_max1
Explorer
0 Kudos

Hi sudheer,

SELECT SINGLE after which you verify the value of sy-subrc. If 4, value doesn't exist, if 0 value exist.

Former Member
0 Kudos

hi Sudheer,

You will need a select query to access the database for sure.

The best way of doing this perfomance wise would be using upto 1 rows statement as this would return the result set when and entry is found satisfying your where clause.

Select USER_ENTRY

UPTO 1 ROWS

from ZTABLE

WHERE USER_ENTRY = LV_UENTRY.

Hope this helps. Please revert if issues.

Regards,

DN.

former_member197475
Active Contributor
0 Kudos

Hi Sudheer.

You can check the table contents in T-Code SE16. Enter the table name and execute it to check the data.

BR,

RAM

sivaganesh_krishnan
Contributor
0 Kudos

HI sudheer,

I would code it as,

SELECT count( * ) from table UP TO 1 ROWS WHERE field = value.

if sy-subrc <> 0 .

"value not exits .

endif.

" if subrc is 0 then value exits

Former Member

Dear, If you want to get that value in some report program then you need to use the select statement.

lv_str type string.

Select single <any_column_name> from <table_name> into lv_str where <Column_name**>   = ^^.

if sy-subrc <> 0.

" Means entry doesn't exist.

else.

" entry exist.

endif.

** Column name, one which that particular entry is store.

^^ Value of entry.

if you just want to check then try in se16 or se11.

Former Member
0 Kudos

I am using select single in a report which is taking too much time, so is there any option to redude the time.

will select upto 1 row reduce the time????

0 Kudos

SELECT SINGLE on primary key for sure.

0 Kudos

Select single also look at the very first record.

HI Sudheer,

Try reading the answers in this dicussion . Iam sure your douts will be cleared

0 Kudos

In addition to what Paul Max said,

If you cannot select single on Primary Key due to input constraints, you can index your input  parameter:

http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eb20446011d189700000e8322d00/content.htm

Regards,

KS

0 Kudos

Sudheer,

Select single is preferred when you have all hte primary keys in your where clause, else its always advisable to use UPTO N ROWS statement.

You can put a trace ON and check the performance yourself.

Regards,

DN.

former_member187651
Active Participant
0 Kudos

Dear Sudheer,

You got two ways for value check in table against your input.

1. Programmatic:   

  Select Single * from xyz  where condition.

2. Direct go to SE11 or Se16

  Input your value and get the result.

I think with posts above you got the result.

Regards,

Chandan

Former Member
0 Kudos