2008 Jun 17 5:58 PM
Hi guys.
Im using a dinamic table and i need to know if that table is empty (is a real table not an internal).
if i use is initial, gives me if the variable is empty and i need to know if the real table, that is in the variable is empty.
data: DIM_TABLE TYPE TABLENAME.
if dim_table is initial.
DELETE FROM (dim_table).
if sy-subrc = 0.
CASE ti_table .
WHEN 'gt_ztsdhr000'.
INSERT (dim_table) FROM TABLE gt_ztsdhr000.
WHEN 'gt_ztsdhr001'.
INSERT (dim_table) FROM TABLE gt_ztsdhr001.
WHEN 'gt_ztsdhr002'.
INSERT (dim_table) FROM TABLE gt_ztsdhr002.
WHEN 'gt_ztsdhr003'.
INSERT (dim_table) FROM TABLE gt_ztsdhr003.
WHEN 'gt_ztsdhr004'.
INSERT (dim_table) FROM TABLE gt_ztsdhr004.
WHEN OTHERS.
ENDCASE.
endif.
endif.
2008 Jun 17 6:01 PM
Hello.
Why not:
SELECT * FROM (dim_table) UP TO 1 ROWS.
EXIT.
ENDSELECT.
IF sy-subrc EQ 0.
* NOT EMPTY
ENDIF.
Regards,
Valter Oliveira.
2008 Jun 17 6:01 PM
Hello.
Why not:
SELECT * FROM (dim_table) UP TO 1 ROWS.
EXIT.
ENDSELECT.
IF sy-subrc EQ 0.
* NOT EMPTY
ENDIF.
Regards,
Valter Oliveira.
2008 Jun 17 6:01 PM
First select the data from table to internal table.
select * from ztable into table i_table.
describe table i_table lines v_line.
if v_line = 0.
no data in table
endif.
Thanks
Seshu
2008 Jun 17 6:05 PM
2008 Jun 17 6:10 PM
Hello
PARAMETERS:
dbtab TYPE c LENGTH 10 DEFAULT 'SFLIGHT'.
DATA dref TYPE REF TO data.
FIELD-SYMBOLS:
<tab> TYPE ANY TABLE.
CREATE DATA dref
TYPE STANDARD TABLE OF (dbtab) WITH NON-UNIQUE DEFAULT KEY.
ASSIGN dref->* TO <tab>.
SELECT * FROM (dbtab) INTO TABLE <tab>.
IF sy-subrc NE 0.
WRITE: 'Empty table!'.
ENDIF.
Regards.
2008 Jun 17 7:33 PM
Hi Javiar,
Use the below Key.
Select single xxx into v_xxx from table.
if sy-subrc = 0.
write: ' Record Found'.
endif.
2008 Jun 17 8:00 PM
Hi,
can use this variant of select as well..
select count( * )
from <table_name> up to 1 rows.
Ex:
REPORT Z_TEST1.
parameter: p_table type char50.
start-of-selection.
select count( * )
from (p_table) up to 1 rows.
if sy-subrc = 0.
write: /'Table is not empty'.
else.
write: /'Table is empty'.
endif.
Regards,
Joy.
2008 Jun 17 8:06 PM
Joy - there's a lot of overhead when using an aggregate function. I't best to use
SELECT COUNT(*)
only when you need the actual number of rows.
Rob
2008 Jun 17 8:05 PM
DATA: l_count TYPE i.
SELECT COUNT(*) AS l_count
INTO l_count
FROM mara. "<<<ur Z table name
if l_count = 0.
write:/ empty.
endif.