ABAP-动态控制选择屏幕
DATA:l_objtype TYPE objtype VALUE 'T'.
DATA:lt_objtype LIKE TABLE OF se16n_seltab WITH HEADER LINE.
DATA l_selid TYPE rsdynsel-selid.
DATA: field_tab TYPE TABLE OF rsdsfields,
ls_field TYPE rsdsfields.
DATA table_tab TYPE TABLE OF rsdstabs.
DATA table LIKE LINE OF table_tab.
DATA:field_ranges TYPE rsds_trange,
lw_rsds_r TYPE rsds_range,
lw_rsds TYPE rsds_frange,
lw_selopt TYPE rsdsselopt.
DATA: where_clauses TYPE rsds_twhere,
dref TYPE REF TO data.
FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
<where> LIKE LINE OF where_clauses.
table-prim_tab = 'MARA'.
APPEND table TO table_tab.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
ref_table_des ?= cl_abap_tabledescr=>describe_by_name( 'MARA' ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails FROM 2 TO 10.
ls_field-tablename = 'MARA'.
ls_field-fieldname = xdetails-name.
APPEND ls_field TO field_tab.
ENDLOOP.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
kind = l_objtype
IMPORTING
selection_id = l_selid
TABLES
tables_tab = table_tab
fields_tab = field_tab
EXCEPTIONS
OTHERS = 4.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = l_selid
title = '选择条件'
as_window = ' '
IMPORTING
* field_ranges = field_ranges
where_clauses = where_clauses
TABLES
fields_tab = field_tab
EXCEPTIONS
OTHERS = 4.
*LOOP AT field_ranges INTO lw_rsds_r.
* LOOP AT lw_rsds_r-frange_t INTO lw_rsds.
* lt_objtype-field = lw_rsds-fieldname.
* LOOP AT lw_rsds-selopt_t INTO lw_selopt.
* lt_objtype-sign = lw_selopt-sign.
* lt_objtype-option = lw_selopt-option.
* lt_objtype-low = lw_selopt-low.
* lt_objtype-high = lw_selopt-high.
* APPEND lt_objtype.
* ENDLOOP.
* CLEAR lt_objtype.
* ENDLOOP.
*ENDLOOP.
ASSIGN where_clauses[ tablename = 'MARA' ] TO <where>.
CREATE DATA dref TYPE TABLE OF ('MARA').
ASSIGN dref->* TO <table>.
TRY.
IF <where> IS ASSIGNED AND <where>-where_tab IS NOT INITIAL.
SELECT *
FROM mara
WHERE (<where>-where_tab)
INTO TABLE @<table> UP TO 10 ROWS.
ELSE.
SELECT *
FROM mara
INTO TABLE @<table> UP TO 10 ROWS.
ENDIF.
CATCH cx_sy_dynamic_osql_error.
MESSAGE 'NOT DATA' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
"显示数据
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(i_table)
CHANGING
t_table = <table>
).
i_table->display( ).
CATCH cx_salv_msg.
MESSAGE 'Error in ALV display' TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
- 点赞
- 收藏
- 关注作者
评论(0)