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: 

Dynamic Select

Former Member
0 Kudos
129

Hi All,

Can we write dyanamic select statement ?

My requirement is I have some thousands of tables in the internal table. I will need to check every table has got data or not ?

Please share your thoughts.

regards

Ram

9 REPLIES 9

JozsefSzikszai
Active Contributor
0 Kudos
74

hi Ram,

welcome to SDN

yes, you can, something like:

LOOP AT itab.
SELECT COUNT( * )
FROM (itab-table).
IF sy-subrc EQ 0.
==> yes, there is data in the DB table
ELSE.
==> no, there is no data in the DB table
ENDIF.
ENDLOOP.

hope this helps

ec

0 Kudos
74

Hi Eric,

Actually I have tried the same statemet. Below is that :

select count ( * ) from (lstab-table)

into lv_count.

but its throwing dump saying that unknown dynamic object.

Suggest me.

Regards

Ram

0 Kudos
74

make sure that (lstab-table) contains the table name in capitals during run time. You can also make a check before the SELECT COUNT:

SELECT COUNT( * ) FROM DD02L WHERE TABNAME EQ lstab-table.

IF sy-subrc EQ 0.

==> table exists

ENDIF.

0 Kudos
74

Hi Eric,

Thanks .

Infact all my tables which are being checked in select statement are from DD02L only. They are all very much existing and they are also in capitals.

Regards

RR

0 Kudos
74

if you copy the whole code here, I could take a closer look...

former_member787646
Contributor
0 Kudos
74

Hi

Try the following code....

DATA: v_count type i.

LOOP AT itab.

SELECT COUNT( * ) INTO v_count FROM (itab-<fieldname>).

IF v_count = 0.

....code goes here

ELSE.

....code goes here

ENDIF.

ENDLOOP.

Hope this would help you.

Murthy

Former Member
0 Kudos
74

take a look at this code...

select tabname

from dd02l

into table it_tab.

loop at it_tab.

select *

from it_tab-tabname

if sy-subrc ne 0.

capture those tables(it_tab-tabname)

and display it or do ur req. functionality here...

else.

endif.

endloop.

Former Member
0 Kudos
74

hi ram,

yes you can use dynamic select statements.

The statement

SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE|TABLE <node>.

declares a node <node> of a logical database for dynamic selections in the selection include.

To use the dynamic selections in the SELECT statements of the subroutine PUT_<node>, you must use the data object DYN_SEL. The data object DYN_SEL is automatically generated in the logical database program as follows:

TYPE-POOLS RSDS.

DATA DYN_SEL TYPE RSDS_TYPE.

You do not have to program these lines yourself. The data object DYN_SEL is available in the database program but not in a connected executable program.

The type RSDS_TYPE of the data object is defined in the type group RSDS as follows:

TYPE-POOL RSDS.

  • WHERE-clauses ------------------------------

TYPES: RSDS_WHERE_TAB LIKE RSDSWHERE OCCURS 5.

TYPES: BEGIN OF RSDS_WHERE,

TABLENAME LIKE RSDSTABS-PRIM_TAB,

WHERE_TAB TYPE RSDS_WHERE_TAB,

END OF RSDS_WHERE.

TYPES: RSDS_TWHERE TYPE RSDS_WHERE OCCURS 5.

  • Expressions Polish notation ---------------

TYPES: RSDS_EXPR_TAB LIKE RSDSEXPR OCCURS 10.

TYPES: BEGIN OF RSDS_EXPR,

TABLENAME LIKE RSDSTABS-PRIM_TAB,

EXPR_TAB TYPE RSDS_EXPR_TAB,

END OF RSDS_EXPR.

TYPES: RSDS_TEXPR TYPE RSDS_EXPR OCCURS 10.

  • Selections as RANGES-tables -----------------

TYPES: RSDS_SELOPT_T LIKE RSDSSELOPT OCCURS 10.

TYPES: BEGIN OF RSDS_FRANGE,

FIELDNAME LIKE RSDSTABS-PRIM_FNAME,

SELOPT_T TYPE RSDS_SELOPT_T,

END OF RSDS_FRANGE.

TYPES: RSDS_FRANGE_T TYPE RSDS_FRANGE OCCURS 10.

TYPES: BEGIN OF RSDS_RANGE,

TABLENAME LIKE RSDSTABS-PRIM_TAB,

FRANGE_T TYPE RSDS_FRANGE_T,

END OF RSDS_RANGE.

TYPES: RSDS_TRANGE TYPE RSDS_RANGE OCCURS 10.

  • Definition of RSDS_TYPE

TYPES: BEGIN OF RSDS_TYPE,

CLAUSES TYPE RSDS_TWHERE,

TEXPR TYPE RSDS_TEXPR,

TRANGE TYPE RSDS_TRANGE,

END OF RSDS_TYPE.

Edited by: Rahul Kumar Sinha on Jul 21, 2008 11:27 AM

Former Member
0 Kudos
74

Hi Ram,

check this code ,

TABLES : jhak,zdynm_fieldnm.

DATA : itab LIKE jhak OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME .

SELECT-OPTIONS : s_dt FOR jhak-erfdate.

SELECTION-SCREEN : END OF BLOCK blk1.

SET PF-STATUS 'NEW'.

SELECT * FROM zdynm_fieldnm CLIENT SPECIFIED

WHERE mandt = sy-mandt.

WRITE :/01 zdynm_fieldnm-field_name AS CHECKBOX, ' ',

zdynm_fieldnm-field_name.

ENDSELECT.

AT USER-COMMAND.

CASE sy-ucomm.

WHEN 'EXEC'.

PERFORM check_box.

ENDCASE.

Reward points if useful.

Regards,

Muneesh Gitta.