本课我们将通过一个实例来了解ALV Report的基本实现方法。
(注:前期将主要通过Function实现ALV )
功能需求说明: 通过ALV显示Table MAKT中的物料主数据描述。可限定最多输出行数,指定物料编码范围,选择List View 或者 Grid View两种输出方式.
代码如下:
*&---------------------------------------------------------------------*
*& Report ZTRAIN_ALV1
*&
*&---------------------------------------------------------------------*
*& 应用ALV显示Table:MAKT 物料主数据
*&
*&---------------------------------------------------------------------*
REPORT ZTRAIN_ALV1.
Tables: MAKT .
DATA ITAB_MAKT LIKE MAKT OCCURS 0 WITH HEADER LINE.
SELECT-OPTIONS : S_MATNR FOR MAKT-MATNR.
PARAMETERS : P_MAX(4) TYPE N DEFAULT '200',
P_RD1 RADIOBUTTON GROUP R1, " LIST VIEW
P_RD2 RADIOBUTTON GROUP R1. " GRID VIEW
START-OF-SELECTION.
PERFORM GET_DATA.
END-OF-SELECTION.
PERFORM OUTPUT_DATA.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
* 选择数据
SELECT * FROM MAKT INTO TABLE ITAB_MAKT UP TO P_MAX ROWS “限定最大数据量
WHERE MATNR IN S_MATNR .
IF ITAB_MAKT[] IS INITIAL.
MESSAGE 'NO DATA FOUND' TYPE 'E'.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form OUTPUT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM OUTPUT_DATA .
DATA : L_FUNAME TYPE RS38L_FNAM. " LIKE HEADER_FB-NAME.
IF P_RD2 IS INITIAL. “ 设定显示方式 LIST / GRID所需Function名称
L_FUNAME = 'REUSE_ALV_LIST_DISPLAY' .
ELSE.
L_FUNAME = 'REUSE_ALV_GRID_DISPLAY'.
ENDIF.
CALL FUNCTION L_FUNAME
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 = 'MAKT'
* Internal output table structure name - 输出内表的结果名
* IS_LAYOUT =
* IT_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 = ITAB_MAKT
* Table with data to be displayed – 准备显示的内表名
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.
ENDFORM. " OUTPUT_DATA
先来看一下选择屏幕界面:
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/581999/viewspace-903127/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/581999/viewspace-903127/