用abap写一个ALV程序
时间: 2023-11-28 19:05:29 浏览: 123
以下是一个简单的ABAP程序,用于创建ALV报表。该程序会读取SFLIGHT表中的数据,并将其显示在ALV列表中。
REPORT ZALV_REPORT.
TABLES: SFLIGHT.
DATA: ITAB_SFLIGHT TYPE STANDARD TABLE OF SFLIGHT,
WA_SFLIGHT TYPE SFLIGHT.
* Select data from SFLIGHT table
SELECT * FROM SFLIGHT INTO TABLE ITAB_SFLIGHT.
* Create ALV object
DATA: O_ALV TYPE REF TO CL_GUI_ALV_GRID.
CREATE OBJECT O_ALV EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.
* Define field catalog
DATA: FIELDCAT TYPE LVC_T_FCAT,
FIELD TYPE LVC_S_FCAT.
FIELD-FIELDNAME = 'CARRID'.
FIELD-TABNAME = 'SFLIGHT'.
FIELD-OUTPUTLEN = 3.
APPEND FIELD TO FIELDCAT.
CLEAR FIELD.
FIELD-FIELDNAME = 'CONNID'.
FIELD-TABNAME = 'SFLIGHT'.
FIELD-OUTPUTLEN = 4.
APPEND FIELD TO FIELDCAT.
CLEAR FIELD.
FIELD-FIELDNAME = 'FLDATE'.
FIELD-TABNAME = 'SFLIGHT'.
FIELD-OUTPUTLEN = 10.
APPEND FIELD TO FIELDCAT.
CLEAR FIELD.
FIELD-FIELDNAME = 'PRICE'.
FIELD-TABNAME = 'SFLIGHT'.
FIELD-OUTPUTLEN = 10.
APPEND FIELD TO FIELDCAT.
CLEAR FIELD.
* Set ALV properties
O_ALV->SET_TABLE_FOR_FIRST_DISPLAY(
EXPORTING
IS_LAYOUT = VALUE #( SEL_MODE = 'A' )
IT_FIELDCAT = FIELDCAT
CHANGING
IT_OUTTAB = ITAB_SFLIGHT
).
* Display ALV list
O_ALV->DISPLAY( ).
阅读全文