2005 Oct 15 7:44 AM
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
2005 Oct 15 8:18 AM
Or Another way:
tables <DBTAB>.
select single * from <DBTAB>.
check sy-subrc = 0.
....
Svetlin
2005 Oct 15 7:55 AM
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.
2005 Oct 15 8:18 AM
Or Another way:
tables <DBTAB>.
select single * from <DBTAB>.
check sy-subrc = 0.
....
Svetlin
2005 Oct 15 8:50 AM
Dear svetlin,
r u sure that select single * query works with out giving key field condition??
2005 Oct 15 8:58 AM
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
2005 Oct 15 8:23 AM
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