建立動態內表

ttn133發表於2008-07-07

本程式利用CL_ALV_TABLE_CREATECREATE_DYNAMIC_TABLE方法建了動態內表,

並利用指往內表中填充資料,最後將內表示。

[@more@]

*&---------------------------------------------------------------------*

*& Report ZCREATE_DYNAMIC_TABLE

*&---------------------------------------------------------------------*

*&

*&---------------------------------------------------------------------*

REPORT ZCREATE_DYNAMIC_TABLE.

TYPE-POOLS: SLIS.

* Field Catalog for List Viewer Control

DATA: GT_FCAT TYPE LVC_T_FCAT,

GH_FCAT LIKE LINE OF GT_FCAT.

DATA: GT_DYN TYPE REF TO DATA.

DATA: GH_LINE TYPE REF TO DATA.

FIELD-SYMBOLS: TYPE ANY TABLE,

TYPE ANY,

TYPE ANY.

*----------------------------------------------------------------------*

* START-OF-SELECTION

*----------------------------------------------------------------------*

START-OF-SELECTION.

* Create Field catalog

GH_FCAT-COL_POS = 1.

GH_FCAT-FIELDNAME = 'ID'.

APPEND GH_FCAT TO GT_FCAT.

GH_FCAT-COL_POS = 2.

GH_FCAT-FIELDNAME = 'NAME'.

APPEND GH_FCAT TO GT_FCAT.

* Create Dynamic Data Table

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = GT_FCAT

IMPORTING

EP_TABLE = GT_DYN.

* Create a new Line with the same structure of the table

ASSIGN GT_DYN->* TO .

CREATE DATA GH_LINE LIKE LINE OF .

ASSIGN GH_LINE->* TO .

* Fill Data Table

ASSIGN COMPONENT 1 OF STRUCTURE TO .

= '001'.

ASSIGN COMPONENT 2 OF STRUCTURE TO .

= 'RAY'.

INSERT INTO TABLE .

* Display Data Table

LOOP AT ASSIGNING .

WRITE: / .

ENDLOOP.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/238575/viewspace-1006911/,如需轉載,請註明出處,否則將追究法律責任。

相關文章