FUNCTION y_ss_test_dynamic_selection.
*"----------------------------------------------------------------------
""Local interface:
*" IMPORTING
*" REFERENCE(TABNAME) LIKE DD02L-TABNAME
*" EXPORTING
*" REFERENCE(DS_CLAUSES) TYPE RSDS_WHERE
*" EXCEPTIONS
*" TABLE_NOT_VALID
*" OTHER_ERROR
*"----------------------------------------------------------------------
DATA texpr TYPE rsds_texpr.
DATA twhere TYPE rsds_twhere.
DATA trange TYPE rsds_trange.
DATA BEGIN OF qcat. "Selections View for
INCLUDE STRUCTURE rsdsqcat. "Free Selectoptions
DATA END OF qcat.
DATA BEGIN OF tabs OCCURS 10.
INCLUDE STRUCTURE rsdstabs.
DATA END OF tabs.
DATA BEGIN OF fields OCCURS 10.
INCLUDE STRUCTURE rsdsfields.
DATA END OF fields.
DATA BEGIN OF efields OCCURS 10.
INCLUDE STRUCTURE rsdsfields.
DATA END OF efields.
DATA selid LIKE rsdynsel-selid.
DATA actnum LIKE sy-tfill.
DATA title LIKE sy-title VALUE 'Selection Screen'.
DATA: maxnum LIKE sy-subrc VALUE '69'.
CLEAR tabs.
tabs-prim_tab = tabname.
COLLECT tabs.
DATA: position LIKE dd03l-position.
DATA: keyflag LIKE dd03l-keyflag.
CLEAR fields.
fields-tablename = tabname.
fields-sign = 'I'.
DATA: step LIKE sy-subrc.
SELECT fieldname keyflag position
INTO (fields-fieldname, keyflag, position)
FROM dd03l
WHERE tabname = tabname
AND fieldname NOT LIKE '.INCLU%'
AND datatype NE 'CLNT'
ORDER BY position.
ADD 1 TO step.
CHECK step LE maxnum.
IF keyflag 'X'.
efields = fields.
APPEND efields.
ENDIF.
APPEND fields.
ENDSELECT.
IF sy-subrc 0.
RAISE table_not_valid.
ENDIF.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
expressions = texpr
kind = 'F'
IMPORTING
selection_id = selid
expressions = texpr
where_clauses = twhere
field_ranges = trange
number_of_active_fields = actnum
TABLES
tables_tab = tabs
fields_tab = fields
fields_not_selected = efields
EXCEPTIONS
fields_incomplete = 01
fields_no_join = 02
field_not_found = 03
no_tables = 04
table_not_found = 05
expression_not_supported = 06
incorrect_expression = 07
illegal_kind = 08
area_not_found = 09
inconsistent_area = 10
kind_f_no_fields_left = 11
kind_f_no_fields = 12
too_many_fields = 13.
IF sy-subrc = 0.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = selid
title = title
IMPORTING
where_clauses = twhere
expressions = texpr
field_ranges = trange
number_of_active_fields = actnum
TABLES
fields_tab = fields
EXCEPTIONS
internal_error = 01
no_action = 02
no_fields_selected = 03
no_tables_selected = 04
selid_not_found = 05.
IF sy-subrc = 0.
CLEAR ds_clauses.
MOVE tabname TO ds_clauses-tablename.
READ TABLE twhere WITH KEY ds_clauses-tablename INTO ds_clauses.
IF sy-subrc 0.
RAISE other_error.
ENDIF.
ELSE.
RAISE other_error.
ENDIF.
ELSE.
RAISE other_error.
ENDIF.
ENDFUNCTION.
Other related links:
FM free_selection_dialog
4 comments:
Yahoo! I made this thing run now and it is cool! Try to check my revised code:
report ZTEST_DYN_SEL_SCR.
TYPE-pools: rsds.
DATA texpr TYPE rsds_texpr.
DATA twhere TYPE rsds_twhere.
DATA trange TYPE rsds_trange.
DATA: tabname TYPE string.
DATA BEGIN OF qcat. "Selections View for
INCLUDE STRUCTURE rsdsqcat. "Free Selectoptions
DATA END OF qcat.
DATA BEGIN OF tabs OCCURS 10.
INCLUDE STRUCTURE rsdstabs.
DATA END OF tabs.
DATA BEGIN OF fields OCCURS 10.
INCLUDE STRUCTURE rsdsfields.
DATA END OF fields.
DATA BEGIN OF efields OCCURS 10.
INCLUDE STRUCTURE rsdsfields.
DATA END OF efields.
DATA selid LIKE rsdynsel-selid.
DATA actnum LIKE sy-tfill.
DATA title LIKE sy-title VALUE 'Selection Screen'.
DATA: maxnum LIKE sy-subrc VALUE '69'.
tabname = 'T001'.
CLEAR tabs.
tabs-prim_tab = tabname.
COLLECT tabs.
DATA: position LIKE dd03l-position.
DATA: keyflag LIKE dd03l-keyflag.
CLEAR fields.
fields-tablename = tabname.
fields-sign = 'I'.
DATA: step LIKE sy-subrc.
SELECT fieldname keyflag position
INTO (fields-fieldname, keyflag, position)
FROM dd03l
WHERE tabname = tabname
AND fieldname NOT LIKE '.INCLU%'
AND datatype NE 'CLNT'
ORDER BY position.
ADD 1 TO step.
CHECK step LE maxnum.
IF keyflag = 'X'.
efields = fields.
APPEND efields.
ENDIF.
APPEND fields.
ENDSELECT.
IF sy-subrc = 0.
RAISE table_not_valid.
ENDIF.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
expressions = texpr
kind = 'F'
IMPORTING
selection_id = selid
expressions = texpr
where_clauses = twhere
field_ranges = trange
number_of_active_fields = actnum
TABLES
tables_tab = tabs
fields_tab = fields
fields_not_selected = efields
EXCEPTIONS
fields_incomplete = 01
fields_no_join = 02
field_not_found = 03
no_tables = 04
table_not_found = 05
expression_not_supported = 06
incorrect_expression = 07
illegal_kind = 08
area_not_found = 09
inconsistent_area = 10
kind_f_no_fields_left = 11
kind_f_no_fields = 12
too_many_fields = 13.
IF sy-subrc = 0.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = selid
title = title
IMPORTING
where_clauses = twhere
expressions = texpr
field_ranges = trange
number_of_active_fields = actnum
TABLES
fields_tab = fields
EXCEPTIONS
internal_error = 01
no_action = 02
no_fields_selected = 03
no_tables_selected = 04
selid_not_found = 05.
IF sy-subrc = 0.
*CLEAR ds_clauses.
*MOVE tabname TO ds_clauses-tablename.
*READ TABLE twhere WITH KEY ds_clauses-tablename INTO ds_clauses.
*IF sy-subrc = 0.
*RAISE other_error.
*ENDIF.
*ELSE.
*RAISE other_error.
*ENDIF.
*ELSE.
*RAISE other_error.
endif.
ENDIF.
This is only a start-up code wherein you can create your logic after the dynamic selection screen. Please let me know guys if you have any improvement with the program. Tnx!
Hi Riv:
thanks for your code, it's really nice. Just a little bug (I think)
IF sy-subrc = 0.
RAISE table_not_valid.
ENDIF. should be <> 0
Best regards
Luis
Hi Luis, I think Raise is used in exception variables and perhaps I havnt shown the declaration in my code. I will try to check this out...
Post a Comment