function zbu_rfc_103.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(GJAHR) TYPE GJAHR
*" VALUE(MONAT_BEGIN) TYPE MONAT
*" VALUE(MONAT_END) TYPE MONAT
*" VALUE(ZHSXM) TYPE ZHSXM OPTIONAL
*" VALUE(ZSRPRCTR) TYPE ZSRPRCTR OPTIONAL
*" VALUE(ZZCPRCTR) TYPE ZZCPRCTR OPTIONAL
*" VALUE(ZTABLE) TYPE TABNAME
*" EXPORTING
*" VALUE(ERROR) TYPE CHAR1
*" VALUE(MESSAGE) TYPE CHAR40
*" TABLES
*" IT_STRUC STRUCTURE ZIT_STRUC OPTIONAL
*" IT_DATA STRUCTURE ZBUKCDE_CELLS OPTIONAL
*"----------------------------------------------------------------------
select *
from dd03l
into corresponding fields of table it_struc
where tabname = ztable.
if sy-subrc ne 0.
error = ‘X‘.
message = ‘表名不存在‘.
else.
"定义内表的结构
define create_structure.
WA_STRUCTURE-FIELDNAME = &1." 列名
WA_STRUCTURE-COL_POS = &2. " 表示第几列 ---
WA_STRUCTURE-INTTYPE = &3. " 数据类型
WA_STRUCTURE-INTLEN = &4. " 长度
APPEND WA_STRUCTURE TO IT_STRUCTURE.
end-of-definition.
loop at it_struc.
create_structure it_struc-fieldname it_struc-position it_struc-inttype it_struc-intlen.
endloop.
" 按照定义的内表结构,产生一个内表
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_structure
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
"表类型指针 <dyn_table> 指向 数据对象的内容.
data l_str type string.
"组装条件
l_str = ‘ GJAHR = GJAHR AND MONAT BETWEEN MONAT_BEGIN AND MONAT_END‘.
if zhsxm ne ‘‘.
concatenate l_str ‘ AND ZHSXM = ZHSXM‘ into l_str.
endif.
if zsrprctr ne ‘‘.
concatenate l_str ‘ AND ZSRPRCTR = ZSRPRCTR‘ into l_str.
endif.
if zzcprctr ne ‘‘.
concatenate l_str ‘ AND ZZCPRCTR = ZZCPRCTR‘ into l_str.
endif.
" 向动态内表中写数
select * into corresponding fields of table <dyn_table>
from (ztable)
where (l_str).
" 从动态内表中取数,并写到屏幕
data:wa_new_line type ref to data.
create data wa_new_line like line of <dyn_table>.
* 建立一个与动态内表结构相同的数据对象,且数据对象为是一个结构
assign wa_new_line->* to <dyn_wa>." 用<dyn_wa>指针指向该结构
data i_row type kcd_ex_row_n value 0.
loop at <dyn_table> into <dyn_wa>.
i_row = i_row + 1.
loop at it_structure into wa_structure.
assign component wa_structure-fieldname of structure <dyn_wa>
to <dyn_field>.
*用指针<DYN_FIELD>指向工作区<DYN_WA>中的一个字段,字段名为WA_STRUCTURE-FIELDNAME.
it_data-fieldname = wa_structure-fieldname.
it_data-row = i_row.
it_data-col = wa_structure-col_pos.
it_data-value = <dyn_field>.
CONDENSE it_data-value.
append it_data.
endloop.
endloop.
endif.
endfunction.
原文:http://www.cnblogs.com/MR-FAT/p/5340845.html