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: 

how to know if ZTABLE is initial

Former Member
0 Kudos
621

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.

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos
200

Hello.

Why not:


SELECT * FROM (dim_table) UP TO 1 ROWS.
  EXIT.
ENDSELECT.
IF sy-subrc EQ 0.
*  NOT EMPTY
ENDIF.

Regards,

Valter Oliveira.

8 REPLIES 8

valter_oliveira
Active Contributor
0 Kudos
201

Hello.

Why not:


SELECT * FROM (dim_table) UP TO 1 ROWS.
  EXIT.
ENDSELECT.
IF sy-subrc EQ 0.
*  NOT EMPTY
ENDIF.

Regards,

Valter Oliveira.

Former Member
0 Kudos
200

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

0 Kudos
200

edit

Edited by: robert phelan on Jun 17, 2008 7:05 PM

Former Member
0 Kudos
200

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.

former_member598013
Active Contributor
0 Kudos
200

Hi Javiar,

Use the below Key.


Select single xxx into v_xxx from table.
if sy-subrc = 0.
  write: ' Record Found'.
endif.

Former Member
0 Kudos
200

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.

0 Kudos
200

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

former_member156446
Active Contributor
0 Kudos
200
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.