ITPub博客

动态内表,动态SQL,取表结构信息

原创 作者:hiescy 时间:2009-01-12 14:33:39 0 删除 编辑
动态内表,动态SQL,取表结构信息[@more@]

REPORT z_barry_test .

TYPE-POOLS : abap.
FIELD-SYMBOLS: TYPE STANDARD TABLE,
,
.
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. "get_structure
*---------------------------------------------------------------------*
* 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 .
ASSIGN dy_line->* TO .
ENDFORM. "create_dynamic_itab

*---------------------------------------------------------------------*
* 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
FROM (p_table).
ENDFORM. "get_data
*---------------------------------------------------------------------*
* FORM write_out *
*---------------------------------------------------------------------*
FORM write_out.
LOOP AT INTO .
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE TO .
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ .
ELSE.
WRITE: .
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out

下一篇: 显示程序代码
请登录后发表评论 登录
全部评论
  • 博文量
    6
  • 访问量
    23573