您好,登录后才能下订单哦!
以表MARDH为例,来开发ALV报表。
一、最简单的ALV报表
先来做一个最简单的ALV报表。源码如下:
REPORT zquy_alv_test_01.
TYPE-POOLS slis.
TABLES : mardh.
DATA :it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
BEGIN OF wa_data,
check TYPE c,
matnr TYPE matnr,
lgort TYPE lgort_d,
labst TYPE labst,
END OF wa_data,
wt_data LIKE wa_data OCCURS 100 WITH HEADER LINE.
PARAMETERS : p_lfgja TYPE lfgja OBLIGATORY,
p_lfmon TYPE lfmon OBLIGATORY.
START-OF-SELECTION.
PERFORM. get_data.
PERFORM. set_alv_layout.
PERFORM. dis_alv_grid.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* 填充数据
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM. get_data .
SELECT * INTO CORRESPONDING FIELDS OF TABLE wt_data FROM mardh WHERE lfgja = p_lfgja AND lfmon = p_lfmon AND labst > 1000.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form set_alv_layout
*&---------------------------------------------------------------------*
* 设置数据的显示格式
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM. set_alv_layout .
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'matnr'.
wa_fieldcat-seltext_m = '物料编码'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'lgort'.
wa_fieldcat-seltext_m = '库区'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'labst'.
wa_fieldcat-seltext_m = '非限制使用库存'.
APPEND wa_fieldcat TO it_fieldcat.
ENDFORM. " set_alv_layout
*&---------------------------------------------------------------------*
*& Form dis_alv_grid
*&---------------------------------------------------------------------*
* 输出ALV列表
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM. dis_alv_grid .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
it_fieldcat = 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
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = wt_data
* 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. " dis_alv_grid
OK,运行程序后,输出如下:
二、设置ALV输出的格式
定义格式对象:
DATA:
lth_layout TYPE slis_layout_alv.
lth_layout-box_fieldname = 'CHECK'. //设置全选字段,别忘了在数据结构中加入此字段。
lth_layout-colwidth_optimize = 'X'. //设置列的宽度自动调整。
lth_layout-zebra = 'X'. // 设置间隔行颜色交替。
调用ALV显示控件:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = lth_layout
it_fieldcat = it_fieldcat
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = wt_data
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2.
做好调整后,运行程序,输出如下:
三、求和求平均值
wa_fieldcat-do_sum = 'A' //求这列的最大值。
wa_fieldcat-do_sum = 'B' //求这列的最小值。
wa_fieldcat-do_sum = 'C'. //求平均值,必须为大写。
按物料进行小计:
定义排序条件:
DATA : lt_sort TYPE slis_t_sortinfo_alv.
.......
START-OF-SELECTION.
PERFORM. get_data.
PERFORM. sort_build.
PERFORM. set_alv_layout.
PERFORM. dis_alv_grid.
FORM. sort_build .
DATA lwa_sort TYPE slis_sortinfo_alv.
lwa_sort-fieldname = 'MATNR'.
lwa_sort-up = 'X'.
lwa_sort-subtot = 'X'.
APPEND lwa_sort TO lt_sort.
ENDFORM. " SORT_BUILD
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = lth_layout
it_fieldcat = it_fieldcat
IT_SORT = lt_sort
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = wt_data
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
如图:
11.jpg
22.jpg
33.jpg
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。