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: 

data existence check for database table

Former Member
1,812

Hi guys,

anybody suggest me a better & effective way of checking a database table whether data exist in it or not?

ur help appericiated...

raja

1 ACCEPTED SOLUTION

Former Member
0 Kudos
395

Or Another way:

tables <DBTAB>.

select single * from <DBTAB>.

check sy-subrc = 0.

....

Svetlin

5 REPLIES 5

Former Member
0 Kudos
395

There are vairious ways

Most effective one is

Select * up to 1 rows from <DBTAB>.

endselect .

If sy-subrc ne 0.

endif .

( Sy-subrc will not be zero if data does not exist )

Or

Select count( * ) from <DBTAB>.

If sy-subrc ne 0.

endif.

( This will be slower than the first one in case table has some data ).

Cheers.

Former Member
0 Kudos
396

Or Another way:

tables <DBTAB>.

select single * from <DBTAB>.

check sy-subrc = 0.

....

Svetlin

0 Kudos
395

Dear svetlin,

r u sure that select single * query works with out giving key field condition??

0 Kudos
395

Hi Raja

But what do you really want to do? Do you want to check if there is a certain record or if there is at least one record?

Anyway SELECT SINGLE works wituout condition, it should return the first record.

But I think is better:

Select * up to 1 rows from <table>.

endselect .

Than:

Select single * from <table>.

Max

Message was edited by: max bianchi

Former Member
0 Kudos
395

Hi

I think the best way is to do a selection withouh use of haderline.

PARAMETERS: P_BUKRS LIKE T001-BUKRS.

AT SELECTION-SCREEN.

SELECT SINGLE BUKRS FROM T001 INTO P_BUKRS

WHERE BUKRS = P_BUKRS.

IF SY-SUBRC <> 0.

MESSAGE E.....

ENDIF.

MAX