ABAP动态内表使用的例子
更新时间:2023-09-22 00:23:01 阅读量: 工程科技 文档下载
- ABAP动态内表推荐度:
- 相关推荐
关键技巧: 1,
创建动态内表:
a, 动态内表的结构的定义.
动态内表表结构的定义必须使用表结构与 table type: lvc_t_fcat一样的内表.
一般情况下,我们都内表的所有列定义成字符型.
b, 根据表结构生成内表.
系统提供了一个标准的method来产生动态表,使用方法如下:
2, 动态内表的赋值:
a, 获取指定的字段 b, 给指定的字段赋值
3, 读取动态内表的值:
a, 获取指定的字段 b, 读取指定的字段值
REPORT zdyn_test.
FIELD-SYMBOLS:
DATA: dy_table TYPE REF TO data, dy_line TYPE REF TO data,
it_structure TYPE lvc_t_fcat, wa_structure TYPE lvc_s_fcat.
START-OF-SELECTION.
PERFORM create_structure. \定义内表的结构
PERFORM create_dynamic_table. \按照定义的内表结构,产生一个内表
PERFORM write_data_to_dyntable. \向动态内表中写数
PERFORM output_dyntable_data. \从动态内表中取数,并写到屏幕
*&---------------------------------------------------------------------* *& Form create_structure
*&---------------------------------------------------------------------* FORM create_structure .
wa_structure-fieldname = 'COL1'. \第一列列名
wa_structure-col_pos = 1. \表示第一列 --- 可心省略,默认情况下,第一行对应到生产内表的第一列,如果指定,则按指定的列顺序生成内表
wa_structure-inttype = 'C'. \数据类型 wa_structure-intlen = 6. \长度 APPEND wa_structure TO it_structure.
wa_structure-fieldname = 'COL2'. \第二列列名
wa_structure-col_pos = 2. \表示第二列--- 可心省略,默认情况下,第一行对应到生产内表的第一列,如果指定,则按指定的列顺序生成内表
wa_structure-inttype = 'C'. \数据类型 wa_structure-intlen = 6. \长度 APPEND wa_structure TO it_structure.
wa_structure-fieldname = 'COL3'. \第三列名
wa_structure-col_pos = 3. \表示第三列 --- 可心省略,默认情况下,第一行对应到生产内表的第一列,如果指定,则按指定的列顺序生成内表
wa_structure-inttype = 'C'. \数据类型 wa_structure-intlen = 6. \长度 APPEND wa_structure TO it_structure.
ENDFORM. \
*&---------------------------------------------------------------------* *& Form create_dynamic_table
*&---------------------------------------------------------------------* FORM create_dynamic_table .
CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING
it_fieldcatalog = it_structure IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO
*&---------------------------------------------------------------------* *& Form write_data_to_dyntable
*&---------------------------------------------------------------------* FORM write_data_to_dyntable .
DATA:wa_new_line TYPE REF TO data. DATA:i TYPE n. DATA:j TYPE n.
CREATE DATA wa_new_line LIKE LINE OF
\用
LOOP AT it_structure INTO wa_structure. j = j + 1.
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
CONCATENATE i j INTO
APPEND
ENDFORM. \
*&---------------------------------------------------------------------* *& Form output_dyntable_data
*&---------------------------------------------------------------------* FORM output_dyntable_data .
LOOP AT it_structure INTO wa_structure. WRITE: wa_structure-fieldname(5). ENDLOOP.
LOOP AT
LOOP AT it_structure INTO wa_structure.
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
ENDFORM. \
案例分析
REPORT Y_TEST_BY_KB.
DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE. FIELD-SYMBOLS:
用指针
DATA: DY_TABLE TYPE REF TO DATA, DY_LINE TYPE REF TO DATA. DATA: LI_FIELDCAT TYPE LVC_T_FCAT. *界面上输入要显示的表的名称
PARAMETER:P_TBNAM LIKE DD02L-TABNAME. START-OF-SELECTION. * 获取表的field category
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING
I_STRUCTURE_NAME = P_TBNAM CHANGING
CT_FIELDCAT = LI_FIELDCAT. * 根据获取的fieldcategory来创建动态内部表
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE EXPORTING
IT_FIELDCATALOG = LI_FIELDCAT IMPORTING
EP_TABLE = DY_TABLE. * 设定
ASSIGN DY_TABLE->* TO
* 下面这句建立了一个
* 同理设定指针 本程序内此变量无用 ASSIGN DY_LINE->* TO
SELECT *
FROM (P_TBNAM)
INTO CORRESPONDING FIELDS OF TABLE
* Create Instance
CALL METHOD CL_SALV_TABLE=>FACTORY IMPORTING
R_SALV_TABLE = GR_TABLE CHANGING
T_TABLE =
GR_TABLE->DISPLAY( ).
REPORT z_barry_test . TYPE-POOLS : abap.
FIELD-SYMBOLS:
DATA: dy_table TYPE REF TO data, dy_line TYPE REF TO data, xfc TYPE lvc_s_fcat, ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME. PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'. SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION. PERFORM get_structure.
PERFORM create_dynamic_itab. PERFORM get_data. PERFORM write_out.
*---------------------------------------------------------------------* * FORM get_structure * *---------------------------------------------------------------------* FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab, xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr. ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ). idetails[] = ref_table_des->components[]. LOOP AT idetails INTO xdetails. CLEAR xfc.
xfc-fieldname = xdetails-name . * xfc-datatype = xdetails-type_kind. xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length + xdetails-decimals. xfc-decimals = xdetails-decimals. APPEND xfc TO ifc. ENDLOOP.
ENDFORM. \
*---------------------------------------------------------------------* * FORM create_dynamic_itab * *---------------------------------------------------------------------* FORM create_dynamic_itab.
CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING
it_fieldcatalog = ifc IMPORTING
ep_table = dy_table. ASSIGN dy_table->* TO
CREATE DATA dy_line LIKE LINE OF
ENDFORM. \
*---------------------------------------------------------------------* * FORM get_data *
*---------------------------------------------------------------------* FORM get_data.
DATA: BEGIN OF itab OCCURS 0 .
INCLUDE STRUCTURE spfli. DATA: END OF itab.
SELECT * INTO CORRESPONDING FIELDS OF TABLE
ENDFORM. \
*---------------------------------------------------------------------* * FORM write_out * *---------------------------------------------------------------------* FORM write_out.
LOOP AT
ASSIGN COMPONENT sy-index
OF STRUCTURE
IF sy-index = 1.
WRITE:/
WRITE:
ENDLOOP.
ENDFORM. \
ABAP 动态内表构建 Dynamic internal table
要求根据用户输入的工资项(T512W-LGART)查找数据,并输出到ALV,要求是输出跟着输入变。由于工资项的配置信息可能会变,因此用于存储要显示的数据的内表就不能预先知道,因此不得不寻求动态内表的构建方法。
其实网上的例子也有不少,但是都缺少说明,折腾了一上午才弄明白一些,写出来与大家分享。 REPORT Z_DT2.
type-pools : abap. *以t512w为例,构建一个动态内表 tables: t512w.
*field-symbols是一个标志,你可以理解为一个指针,将来创建的内表就要通过它们来访问 field-symbols: [小于号]dyn_table> type standard table, [小于号]dyn_wa>, [小于号]dyn_field>.
* 这里定义了一个 dy_table 和一个 dy_line 类型是引用,但 to data 未能理解是什么意思,我觉得应该是说指向为空的意思 data: dy_table type ref to data, dy_line type ref to data, *用于存储即将构建的动态内表结构 ifc type lvc_t_fcat, xfc type lvc_s_fcat.
data: begin of t_lgart occurs 0, LGART like t512w-lgart,
end of t_lgart.
select-options: S_LGART FOR t512w-lgart.
start-of-selection.
*首先从数据库中把符合用户输入的LGART填入内表,将来构建的动态内表每一列就是LGART中的每一行。 select lgart into t_lgart-lgart from t512w where lgart in s_lgart and MOLGA = '28'. append t_lgart. endselect.
*循环读取内表t_lgart,对于每行构建内表 loop at t_lgart.
*这里偷了个懒,因为工资项中会有/103这样的数据,而/是不能用左列明的,大家可以自己写一个替换逻辑,把/替换成_之类的字符。 check t_lgart-lgart+0(1) ne '/'. *列名就用lgart值
xfc-fieldname = t_lgart-lgart. xfc-datatype = 'C'. xfc-inttype = 'C'. xfc-intlen = 6. xfc-decimals = 0. append xfc to ifc. endloop.
*此处调用一个方法,这个方法用于构建动态内表,输入的就是要构建的结构,输出的就是一个dy_table,之前定义过,但是并不能直接访问。 call method cl_alv_table_create=>create_dynamic_table EXPORTING
it_fieldcatalog = ifc IMPORTING
ep_table = dy_table.
*设定
*下面这句建立了一个
assign dy_line->* to
于是便动态的建立了一个内表和一个工作区,由于此方法建立的内表没有header line,所以需要一个工作区。
下面是取数或者赋值的方法:
*此行中的xxxx1就是列名
ASSIGN COMPONENT xxxx1 OF STRUCTURE
*用Append就可以把该行添加到表中了 APPEND
ABAP-动态内表
2009-09-22 19:03:19| 分类: SAP开发 | 标签: |字号大中小 订阅
动态内表的创建和使用主要有以下几点:
1.动态内表的创建,首先要定义动态结构,然后再根据定义的动态结构利用系统一个标准的method:”cl_alv_table_create=>create_dynamic_table“生成动态内表。
2.动态内表的赋值,遍历动态结构,获取指定的字段,然后给指定的字段赋值。
3.动态内表的读取显示,与赋值相似,遍历动态结构,获取指定的字段,然后读取对应字段的值。 具体实现方法如下所示: 定义:
FIELD-SYMBOLS:
DATA: dy_table TYPE REF TO data, dy_line TYPE REF TO data, it_structure TYPE lvc_t_fcat, wa_structure TYPE lvc_s_fcat. 实现步骤:
1.PERFORM create_structure.\定义内表的结构 FORM create_structure. CLEAR it_structure. DATA:l_pos TYPE i. l_pos = 5.
wa_structure-fieldname = 'MANUFACTURER'.\第一列名
wa_structure-col_pos = 1. \表示第1列 --- wa_structure-ref_table = 'PLAF'. ”字段参照的内表名字 wa_structure-ref_field = 'FLIEF'. “字段参照的字段名字 APPEND wa_structure TO it_structure.
wa_structure-fieldname = 'NAME'. wa_structure-col_pos = 2. wa_structure-ref_table = 'lfa1'. wa_structure-ref_field = 'NAME1'. APPEND wa_structure TO it_structure.
wa_structure-fieldname = 'DESCRIPTION'. wa_structure-col_pos = 3. wa_structure-ref_table = 'MAKT'. wa_structure-ref_field = 'MAKTX'. APPEND wa_structure TO it_structure. wa_structure-fieldname = 'MM#'. wa_structure-col_pos = 4. wa_structure-ref_table = 'MAKT'. wa_structure-ref_field = 'MATNR'.
\第二 列名
\表示第2列 --- \第三列名
\表示第3列 ---
APPEND wa_structure TO it_structure.
\是根据选择屏幕的起始时间和结束时间得到的两个日期之间的月份,以下遍历所得到的月份并写入结构。 LOOP AT it_month INTO wa_month. wa_structure-fieldname = wa_month-pedtr. wa_structure-col_pos = l_pos. wa_structure-inttype = 'P'. \ = 7.
APPEND wa_structure TO it_structure. l_pos = l_pos + 1. ENDLOOP.
ENDFORM. \
2.PERFORM create_dynamic_table.\按照定义的内表结构,产生一个内表 利用系统 的一个标准方法根据结构生成动态内表 FORM create_dynamic_table.
CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING
it_fieldcatalog = it_structure IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO
\表类型指针
3.PERFORM write_data_to_dyntable.\向动态内表中写数 FORM write_data_to_dyntable . DATA:wa_new_line TYPE REF TO data. DATA:l_index2 TYPE i.
CREATE DATA wa_new_line LIKE LINE OF
*建立一个与动态内表结构相同的数据对象,且数据对象为是一个结构 ASSIGN wa_new_line->* TO
LOOP AT it_structure INTO wa_structure.
READ TABLE it_plaf_out INTO wa_plaf_out INDEX l_index2. IF wa_structure-fieldname = 'MANUFACTURER'.
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
\用指针
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
ELSEIF wa_structure-fieldname = 'DESCRIPTION'.
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
ELSEIF wa_structure-fieldname = wa_plaf_out-pedtr.
ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
APPEND
CLEAR
ENDFORM. \PERFORM output_dyntable_data.\从动态内表中取数,并写到屏幕 * LOOP AT it_structure INTO wa_structure. * WRITE: wa_structure-fieldname(5). * ENDLOOP.
* LOOP AT
* LOOP AT it_structure INTO wa_structure.
* ASSIGN COMPONENT wa_structure-fieldname OF STRUCTURE
**用指针
若要通过ALV显示的话。
利用wa_alv_field定义对应结构的ALV,然后即可显示 g_repid = sy-repid.
wa_layout-colwidth_optimize = 'X'. wa_layout-zebra = 'X'.
\ lt_layout-box_fieldname = 'SEL'. DATA:l_colpos TYPE i. l_colpos = 5. \
wa_alv_field-col_pos = 1.
wa_alv_field-fieldname = 'MANUFACTURER'. wa_alv_field-seltext_m = 'MANUFACTURER'. wa_alv_field-no_zero = 'X'. APPEND wa_alv_field TO lit_fcat. wa_alv_field-col_pos = 2. wa_alv_field-fieldname = 'NAME'. wa_alv_field-seltext_m = 'NAME'. APPEND wa_alv_field TO lit_fcat. wa_alv_field-col_pos = 3.
DATA: dyn_table TYPE REF TO data. DATA: dyn_wa TYPE REF TO data.
FIELD-SYMBOLS:
*创建动态表结构
CREATE DATA dyn_table TYPE TABLE OF (p_name). *创建动态内表
ASSIGN dyn_table->* TO
CREATE DATA dyn_wa LIKE LINE OF
ASSIGN dyn_wa->* TO
*从动态表中取数到动态内表中
SELECT * INTO CORRESPONDING FIELDS OF TABLE
LOOP AT
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING
i_structure_name = p_name TABLES
t_outtab =
program_error = 1 OTHERS = 2. IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
wa_alv_field-fieldname = 'DESCRIPTION'. wa_alv_field-seltext_m = 'DESCRIPTION'. APPEND wa_alv_field TO lit_fcat. wa_alv_field-col_pos = 4. wa_alv_field-fieldname = 'MM#'. wa_alv_field-seltext_m = 'MM#'. wa_alv_field-no_zero = 'X'. APPEND wa_alv_field TO lit_fcat. LOOP AT it_month INTO wa_month. wa_alv_field-col_pos = l_colpos.
wa_alv_field-fieldname = wa_month-pedtr. wa_alv_field-seltext_m = wa_month-pedtr. APPEND wa_alv_field TO lit_fcat. l_colpos = l_colpos + 1. ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 关键技巧:
1, 创建动态内表: a, 动态内表的结构的定义.
动态内表表结构的定义必须使用表结构与 table type: lvc_t_fcat一样的内表. 一般情况下,我们都内表的所有列定义成字符型. b, 根据表结构生成内表.
系统提供了一个标准的method来产生动态表,使用方法如下: 2, 动态内表的赋值: a, 获取指定的字段 b, 给指定的字段赋值 3, 读取动态内表的值: a, 获取指定的字段 b, 读取指定的字段值
*&---------------------------------------------------------------------* *& Report YDYN_TEST
*&---------------------------------------------------------------------* REPORT YDYN_TEST.
FIELD-SYMBOLS:
DATA: DY_TABLE TYPE REF TO DATA, DY_LINE TYPE REF TO DATA, IT_STRUCTURE TYPE LVC_T_FCAT, WA_STRUCTURE TYPE LVC_S_FCAT. START-OF-SELECTION.
PERFORM CREATE_STRUCTURE.\定义内表的结构
PERFORM CREATE_DYNAMIC_TABLE.\按照定义的内表结构,产生一个内表 PERFORM WRITE_DATA_TO_DYNTABLE.\向动态内表中写数
PERFORM OUTPUT_DYNTABLE_DATA.\从动态内表中取数,并写到屏幕 *&---------------------------------------------------------------------* *& Form CREATE_STRUCTURE
*----------------------------------------------------------------------* FORM CREATE_STRUCTURE.
WA_STRUCTURE-FIELDNAME = 'COL1'.\第列名 WA_STRUCTURE-COL_POS = 1. \表示第三列 --- WA_STRUCTURE-INTTYPE = 'C'. \数据类型 WA_STRUCTURE-INTLEN = 6. \长度
APPEND WA_STRUCTURE TO IT_STRUCTURE. WA_STRUCTURE-FIELDNAME = 'COL2'.\第 列名 WA_STRUCTURE-COL_POS = 2. \表示第三列 --- WA_STRUCTURE-INTTYPE = 'C'. \数据类型 WA_STRUCTURE-INTLEN = 6. \长度 APPEND WA_STRUCTURE TO IT_STRUCTURE. WA_STRUCTURE-FIELDNAME = 'COL3'.\第三列名 WA_STRUCTURE-COL_POS = 3. \表示第三列 --- WA_STRUCTURE-INTTYPE = 'C'. \数据类型 WA_STRUCTURE-INTLEN = 6. \长度 APPEND WA_STRUCTURE TO IT_STRUCTURE. ENDFORM. \*&---------------------------------------------------------------------* *& Form CREATE_DYNAMIC_TABLE
*----------------------------------------------------------------------* FORM CREATE_DYNAMIC_TABLE.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE EXPORTING
IT_FIELDCATALOG = IT_STRUCTURE IMPORTING
EP_TABLE = DY_TABLE.
ASSIGN DY_TABLE->* TO
*&---------------------------------------------------------------------* *& Form write_data_to_dyntable
*&---------------------------------------------------------------------* FORM WRITE_DATA_TO_DYNTABLE . DATA:WA_NEW_LINE TYPE REF TO DATA. DATA:I TYPE N. DATA:J TYPE N.
CREATE DATA WA_NEW_LINE LIKE LINE OF
CLEAR J.
LOOP AT IT_STRUCTURE INTO WA_STRUCTURE. J = J + 1.
ASSIGN COMPONENT WA_STRUCTURE-FIELDNAME OF STRUCTURE
* \用指针
APPEND
ENDFORM. \*&---------------------------------------------------------------------* *& Form OUTPUT_DYNTABLE_DATA
*----------------------------------------------------------------------* FORM OUTPUT_DYNTABLE_DATA.
LOOP AT IT_STRUCTURE INTO WA_STRUCTURE. WRITE: WA_STRUCTURE-FIELDNAME(5). ENDLOOP.
LOOP AT
LOOP AT IT_STRUCTURE INTO WA_STRUCTURE.
ASSIGN COMPONENT WA_STRUCTURE-FIELDNAME OF STRUCTURE
*用指针
ENDFORM. \
1.使用modify (p_tabname) from
2.如果使用UPDATE进行更新,对于非主键字段的改变还是可以的,但是对于主键字段,只能用MODIFY了。直接对SAP数据做UPDATE
和MODIFY是很危险的,不到万不得已,最好不要做这些操作。如果万一出问题,会很严重的。这里就不用更新和删除程序作为测试程序了,直接做一个动态内表ALV显示的测试程序,道理和更新与删除差不多,希望对有这方面需求的朋友有所帮助!
3.最近从同事程序中发现另一种创建动态内表的简便方法,附3中为测试代码。觉得这个方法更简单些……
附1:
REPORT ZCL_TEST026.
TYPE-POOLS:abap.
PARAMETERS p_name TYPE tabname.
DATA lt_table TYPE TABLE OF dfies. \字段结构表 DATA ls_table TYPE dfies.
DATA lr_struc TYPE REF TO cl_abap_structdescr. DATA lr_table TYPE REF TO cl_abap_tabledescr. DATA lr_type TYPE REF TO cl_abap_typedescr. DATA lr_data TYPE REF TO cl_abap_datadescr.
DATA lt_comp TYPE abap_component_tab. DATA ls_comp LIKE LINE OF lt_comp. DATA dyn_wa TYPE REF TO data. DATA dyn_table TYPE REF TO data. DATA l_string TYPE string.
FIELD-SYMBOLS:
CALL FUNCTION 'DDIF_NAMETAB_GET' EXPORTING
tabname = p_name TABLES
dfies_tab = lt_table EXCEPTIONS
not_found = 1 OTHERS = 2. IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
LOOP AT lt_table INTO ls_table.
CONCATENATE ls_table-tabname '-' ls_table-fieldname INTO l_string. ls_comp-name = ls_table-fieldname. *读取字段类型
CALL METHOD cl_abap_datadescr=>describe_by_name EXPORTING
p_name = l_string RECEIVING
p_descr_ref = lr_type EXCEPTIONS
type_not_found = 1 OTHERS = 2. IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
ls_comp-type ?= lr_type. APPEND ls_comp TO lt_comp. CLEAR ls_comp. ENDLOOP.
*根据字段目录创建动态结构类型
CALL METHOD cl_abap_structdescr=>create EXPORTING
p_components = lt_comp RECEIVING
p_result = lr_struc. *根据动态结构创建动态内表类型
CALL METHOD cl_abap_tabledescr=>create EXPORTING
p_line_type = lr_struc RECEIVING
p_result = lr_table.
*参照动态结构类型和动态内表类型创建内表与工作区 CREATE DATA dyn_wa TYPE HANDLE lr_struc. CREATE DATA dyn_table TYPE HANDLE lr_table. *指定内表与工作区到字段符号
ASSIGN dyn_wa->* TO
ASSIGN dyn_table->* TO
*从动态表中取数到动态内表中
SELECT * INTO CORRESPONDING FIELDS OF TABLE
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING
i_structure_name = p_name TABLES
t_outtab =
program_error = 1 OTHERS = 2. IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. 附2:
REPORT ZCL_TEST027.
TYPE-POOLS:abap.
PARAMETERS p_name TYPE tabname.
DATA: d_ref TYPE REF TO data,
lt_alv_cat TYPE TABLE OF lvc_s_fcat, ls_alv_cat LIKE LINE OF lt_alv_cat.
DATA: lt_table LIKE TABLE OF dntab. DATA: ls_table TYPE dntab.
FIELD-SYMBOLS :
CALL FUNCTION 'NAMETAB_GET' EXPORTING
langu = sy-langu tabname = p_name TABLES
nametab = lt_table EXCEPTIONS
no_texts_found = 1.
*根据取出的字段目录生成参考字段目录
LOOP AT lt_table INTO ls_table.
ls_alv_cat-fieldname = ls_table-fieldname. ls_alv_cat-ref_table = p_name.
ls_alv_cat-ref_field = ls_table-fieldname. APPEND ls_alv_cat TO lt_alv_cat. CLEAR ls_alv_cat. ENDLOOP. *内表创建
CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING
it_fieldcatalog = lt_alv_cat IMPORTING
ep_table = d_ref. *指定生成的内表到字段符号
ASSIGN d_ref->* TO
SELECT * INTO CORRESPONDING FIELDS OF TABLE
*显示内表中的数据
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING
i_structure_name = p_name TABLES
t_outtab =
program_error = 1 OTHERS = 2. IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. 附3:
REPORT ZCL_TEST028.
PARAMETERS p_name TYPE tabname.
正在阅读:
ABAP动态内表使用的例子09-22
ITO透明导电薄膜替代品发展现状04-26
天然药物化学各章复习题06-01
广西民族学院理学院2014-2015第一学期课程教学大纲之数据库系统教学大纲11-02
数列文科2009年全国高考题01-14
广东省中山市教育联合体2018届九年级下学期3月联考质量检测英语05-23
庆“六一”班会发言稿02-25