特别注意点:wa_alv_field-fieldname = 'EMPID'.这个地方 EMPID一定要大写否则会在运行时报错。
*&---------------------------------------------------------------------**& Report ZTBALV1*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT ztbalv1.*ALV使用到的类库TYPE-POOLS: slis.*一列描述DATA wa_alv_field TYPE slis_fieldcat_alv.*描述内表,列清单DATA wa_alv_fieldcat TYPE slis_t_fieldcat_alv.*定义内表 , 赋值DATA wa_emp LIKE TABLE OF ztbemp WITH HEADER LINE.SELECT * INTO TABLE wa_emp FROM ztbemp.wa_alv_field-col_pos = 1."*定义对应字段 wa_alv_field-fieldname = 'EMPID'.wa_alv_field-seltext_m = '员工号'.APPEND wa_alv_field TO wa_alv_fieldcat.wa_alv_field-col_pos = 2."*定义对应字段wa_alv_field-fieldname = 'EMPNAME'.wa_alv_field-seltext_m = '员工姓名'.APPEND wa_alv_field TO wa_alv_fieldcat. wa_alv_field-col_pos = 3."*定义对应字段 wa_alv_field-fieldname = 'AGE'. wa_alv_field-seltext_m = '员工年龄'. APPEND wa_alv_field to wa_alv_fieldcat. wa_alv_field-col_pos = 4."*定义对应字段 wa_alv_field-fieldname = 'EMAIL'. wa_alv_field-seltext_m = '员工邮箱'. APPEND wa_alv_field to wa_alv_fieldcat. wa_alv_field-col_pos = 5."*定义对应字段 wa_alv_field-fieldname = 'TEL'. wa_alv_field-seltext_m = '员工电话'. APPEND wa_alv_field to wa_alv_fieldcat. wa_alv_field-col_pos = 6."*定义对应字段 wa_alv_field-fieldname = 'ADDR'. wa_alv_field-seltext_m = '员工地址'. APPEND wa_alv_field to wa_alv_fieldcat. wa_alv_field-col_pos = 7."*定义对应字段 wa_alv_field-fieldname = 'GRAD'. wa_alv_field-seltext_m = '员工标志'. APPEND wa_alv_field to wa_alv_fieldcat. wa_alv_field-col_pos = 8."*定义对应字段 wa_alv_field-fieldname = 'UNAME'. wa_alv_field-seltext_m = '员工登陆名'. APPEND wa_alv_field to wa_alv_fieldcat.CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER =* I_BUFFER_ACTIVE = ' '* I_CALLBACK_PROGRAM = ' '* I_CALLBACK_PF_STATUS_SET = ' '* I_CALLBACK_USER_COMMAND = ' '* I_STRUCTURE_NAME =* IS_LAYOUT = it_fieldcat = wa_alv_fieldcat* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* IR_SALV_LIST_ADAPTER =* IT_EXCEPT_QINFO =* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = wa_emp* EXCEPTIONS* 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.运行