‎2008 Jul 21 9:49 AM
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
‎2008 Jul 21 9:55 AM
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
‎2008 Jul 21 9:59 AM
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
‎2008 Jul 21 10:04 AM
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.
‎2008 Jul 21 10:24 AM
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
‎2008 Jul 21 10:30 AM
if you copy the whole code here, I could take a closer look...
‎2008 Jul 21 9:58 AM
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
‎2008 Jul 21 10:01 AM
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.
‎2008 Jul 21 10:26 AM
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
‎2008 Jul 23 11:36 AM
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.