abap--动态创建类型和变量的使用程序样例

[复制链接]
查看705 | 回复0 | 2010-8-1 22:16:00 | 显示全部楼层 |阅读模式
1)6.40以前可以使用代码 report z_dyn_attribute line-size 500.. * dynamische attributbeschaffung *================================================================ parameters tabnam(10) type c default 'sflight'. data objekt type ref to data. field-symbols <aber> type any. field-symbols <feld> type any.
和 "abap--动态创建类型和变量的使用程序样例" 有关的编程小帖士: strong>UPPER UPPER函数间返回字符串的大写形式。
data tab type i value 1. *================================================================ start-of-selection. create data objekt type (tabnam). assign objekt->* to <aber>. select * from (tabnam) into <aber>. new-line. tab = 1. do. assign component sy-index of structure <aber> to <feld>. if sy-subrc ne 0. exit. endif. write at tab(10) <feld>. add 11 to tab. enddo. endselect. top-of-page. data struktur type ref to cl_abap_structdescr. data beschrieb type abap_compdescr. struktur ?= cl_abap_typedescr=>describe_by_data( <aber> ). new-line. tab = 1. loop at struktur->components into beschrieb. write at tab(10) beschrieb-name. add 11 to tab. endloop. uline. tab = 1. 2)6.40以后可以使用代码 report zdany_dynamic_select. * we use some parameters to dynamically control the select, this is not very * clever but this is just a test program !! parameter : p_tabnam type tabname default 'sflight', p_selfl1 type edpline default 'carrid', p_selfl2 type edpline default 'connid', p_selfl3 type edpline default 'fldate', p_selfl4 type edpline default 'price', p_selfl5 type edpline default 'currency', p_where1 type edpline default 'price > 300', p_where2 type edpline default 'and currency = ''eur'''. field-symbols : <lt_outtab> type any table, <ls_outtab> type any, <l_fld> type any. data: lt_where type table of edpline, lt_sel_list type table of edpline, lt_group type table of edpline, l_having type string, l_wa_name type string, l_sel_list type edpline, dref type ref to data, itab_type type ref to cl_abap_tabledescr, struct_type type ref to cl_abap_structdescr, elem_type type ref to cl_abap_elemdescr, comp_tab type cl_abap_structdescr=>component_table, comp_fld type cl_abap_structdescr=>component. types: f_count type i. * creation of the output table including a non standard field, f_count * see abap faq #14 for more information on this topic struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ). elem_type ?= cl_abap_elemdescr=>describe_by_name( 'f_count' ). comp_tab = struct_type->get_components( ). * we remove the unnecessary fields loop at comp_tab into comp_fld. if comp_fld-name <> p_selfl1 and comp_fld-name <> p_selfl2 and comp_fld-name <> p_selfl3 and comp_fld-name <> p_selfl4 and comp_fld-name <> p_selfl5. delete table comp_tab with table key name = comp_fld-name. endif. endloop. comp_fld-name = 'f_count'. comp_fld-type = elem_type. append comp_fld to comp_tab. struct_type = cl_abap_structdescr=>create( comp_tab ). itab_type = cl_abap_tabledescr=>create( struct_type ). l_wa_name = 'l_wa'. create data dref type handle itab_type. assign dref->* to <lt_outtab>. create data dref type handle struct_type. assign dref->* to <ls_outtab>. * creation of the selection fields and the "group by" clause append p_selfl1 to lt_sel_list. append p_selfl1 to lt_group. append p_selfl2 to lt_sel_list. append p_selfl2 to lt_group. append p_selfl3 to lt_sel_list. append p_selfl3 to lt_group. append p_selfl4 to lt_sel_list. append p_selfl4 to lt_group. append p_selfl5 to lt_sel_list. append p_selfl5 to lt_group. append 'count(*) as f_count' to lt_sel_list. * creation of the "where" clause append p_where1 to lt_where. append p_where2 to lt_where. * creation of the "having" clause l_having = 'count(*) >= 1'. * the dynamic select select (lt_sel_list) from (p_tabnam) into corresponding fields of table <lt_outtab> where (lt_where) group by (lt_group) having (l_having) order by (lt_group). * display of the results loop at <lt_outtab> assigning <ls_outtab>. loop at comp_tab into comp_fld. assign component comp_fld-name of structure <ls_outtab> to <l_fld>. write: <l_fld>. endloop. skip. endloop. ms sql大值数据类型varchar(max)、nvarchar(max)、varbinary(max) abap--动态创建局部类型的变量
您需要登录后才可以回帖 登录 | 注册哦

本版积分规则