ALV分类汇总[@more@]
REPORT ztest1.
TABLES:mara,mbew.
TYPE- POOLS:slis.
TYPES:BEGIN OF t_itab,
matnr LIKE mara- matnr,
ersda LIKE mara- ersda,
matkl LIKE mara- matkl,
lbkum LIKE mbew- lbkum,
salk3 LIKE mbew- salk3,
END OF t_itab.
DATA:itab TYPE TABLE OF t_itab WITH HEADER LINE.
SELECTION- SCREEN BEGIN OF BLOCK blok WITH FRAME TITLE txt1.
SELECT-OPTIONS:matnr FOR mara- matnr.
SELECTION- SCREEN END OF BLOCK blok.
INITIALIZATION.
txt1 = '请输入选择条件' .
START-OF- SELECTION.
END-OF- SELECTION.
PERFORM getdata.
PERFORM disalv.
*&---------------------------------------------------------------------*
*& Form getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM getdata .
SELECT
mara ~ matnr
mara~ ersda
mara~ matkl
mbew~ lbkum
mbew~ salk3
INTO TABLE itab
FROM mara
JOIN mbew ON ( mara~matnr = mbew~matnr AND mbew~bwkey = '1000' )
WHERE mara~ matnr IN matnr
ORDER BY mara~ matnr
.
ENDFORM. " getdata
*&---------------------------------------------------------------------*
*& Form disalv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM disalv .
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
is_variant LIKE disvariant,
it_events TYPE slis_t_event,
is_layout TYPE slis_layout_alv, "ALV的格式
i_list_comments TYPE slis_t_listheader,
i_callback_program TYPE sy- repid,
title TYPE lvc_title,
it_sort TYPE slis_t_sortinfo_alv
.
PERFORM fieldcat_init USING it_fieldcat."输出列表控件表头
* PERFORM layout_init USING is_layout.
* PERFORM eventtab_build USING it_events.
PERFORM e02_layout_sort_build CHANGING it_sort.
i_callback_program = sy- repid.
title = '测试' .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_callback_program
i_grid_title = title
is_layout = is_layout
it_fieldcat = it_fieldcat
it_events = it_events
it_sort = it_sort[]
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2 .
IF sy-subrc <> 0 .
ENDIF.
ENDFORM. " disalv
*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> P_IT_FIELDCAT text
*----------------------------------------------------------------------*
FORM fieldcat_init USING it_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat -fieldname = 'MATNR' .
ls_fieldcat-reptext_ddic = '物料号' .
ls_fieldcat-no_zero = 'X' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ERSDA' .
ls_fieldcat-reptext_ddic = '创建日期' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATKL' .
ls_fieldcat-reptext_ddic = '物料组' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'LBKUM' .
ls_fieldcat-reptext_ddic = '总评估的库存' .
ls_fieldcat-do_sum = 'X' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SALK3' .
ls_fieldcat-reptext_ddic = '估价的总库存价值' .
ls_fieldcat-do_sum = 'X' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ENDFORM. " fieldcat_init
*&---------------------------------------------------------------------*
*& Form e02_layout_sort_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* P_IT_SORT text
*----------------------------------------------------------------------*
FORM e02_layout_sort_build CHANGING lt_sort TYPE slis_t_sortinfo_alv.
DATA ls_sort TYPE slis_sortinfo_alv.
*
CLEAR ls_sort.
ls_sort -fieldname = 'ERSDA'. "#EC *
ls_sort-spos = 1 .
ls_sort-up = 'X' .
ls_sort-subtot = 'X' .
APPEND ls_sort TO lt_sort.
CLEAR ls_sort.
ls_sort-fieldname = 'MATKL'. "#EC *
ls_sort-spos = 1 .
ls_sort-up = 'X' .
ls_sort-subtot = 'X' .
APPEND ls_sort TO lt_sort.
ENDFORM. " e02_layout_sort_build
TABLES:mara,mbew.
TYPE- POOLS:slis.
TYPES:BEGIN OF t_itab,
matnr LIKE mara- matnr,
ersda LIKE mara- ersda,
matkl LIKE mara- matkl,
lbkum LIKE mbew- lbkum,
salk3 LIKE mbew- salk3,
END OF t_itab.
DATA:itab TYPE TABLE OF t_itab WITH HEADER LINE.
SELECTION- SCREEN BEGIN OF BLOCK blok WITH FRAME TITLE txt1.
SELECT-OPTIONS:matnr FOR mara- matnr.
SELECTION- SCREEN END OF BLOCK blok.
INITIALIZATION.
txt1 = '请输入选择条件' .
START-OF- SELECTION.
END-OF- SELECTION.
PERFORM getdata.
PERFORM disalv.
*&---------------------------------------------------------------------*
*& Form getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM getdata .
SELECT
mara ~ matnr
mara~ ersda
mara~ matkl
mbew~ lbkum
mbew~ salk3
INTO TABLE itab
FROM mara
JOIN mbew ON ( mara~matnr = mbew~matnr AND mbew~bwkey = '1000' )
WHERE mara~ matnr IN matnr
ORDER BY mara~ matnr
.
ENDFORM. " getdata
*&---------------------------------------------------------------------*
*& Form disalv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM disalv .
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
is_variant LIKE disvariant,
it_events TYPE slis_t_event,
is_layout TYPE slis_layout_alv, "ALV的格式
i_list_comments TYPE slis_t_listheader,
i_callback_program TYPE sy- repid,
title TYPE lvc_title,
it_sort TYPE slis_t_sortinfo_alv
.
PERFORM fieldcat_init USING it_fieldcat."输出列表控件表头
* PERFORM layout_init USING is_layout.
* PERFORM eventtab_build USING it_events.
PERFORM e02_layout_sort_build CHANGING it_sort.
i_callback_program = sy- repid.
title = '测试' .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_callback_program
i_grid_title = title
is_layout = is_layout
it_fieldcat = it_fieldcat
it_events = it_events
it_sort = it_sort[]
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2 .
IF sy-subrc <> 0 .
ENDIF.
ENDFORM. " disalv
*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> P_IT_FIELDCAT text
*----------------------------------------------------------------------*
FORM fieldcat_init USING it_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat -fieldname = 'MATNR' .
ls_fieldcat-reptext_ddic = '物料号' .
ls_fieldcat-no_zero = 'X' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ERSDA' .
ls_fieldcat-reptext_ddic = '创建日期' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATKL' .
ls_fieldcat-reptext_ddic = '物料组' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'LBKUM' .
ls_fieldcat-reptext_ddic = '总评估的库存' .
ls_fieldcat-do_sum = 'X' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SALK3' .
ls_fieldcat-reptext_ddic = '估价的总库存价值' .
ls_fieldcat-do_sum = 'X' .
APPEND ls_fieldcat TO it_fieldcat.
CLEAR ls_fieldcat.
ENDFORM. " fieldcat_init
*&---------------------------------------------------------------------*
*& Form e02_layout_sort_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* P_IT_SORT text
*----------------------------------------------------------------------*
FORM e02_layout_sort_build CHANGING lt_sort TYPE slis_t_sortinfo_alv.
DATA ls_sort TYPE slis_sortinfo_alv.
*
CLEAR ls_sort.
ls_sort -fieldname = 'ERSDA'. "#EC *
ls_sort-spos = 1 .
ls_sort-up = 'X' .
ls_sort-subtot = 'X' .
APPEND ls_sort TO lt_sort.
CLEAR ls_sort.
ls_sort-fieldname = 'MATKL'. "#EC *
ls_sort-spos = 1 .
ls_sort-up = 'X' .
ls_sort-subtot = 'X' .
APPEND ls_sort TO lt_sort.
ENDFORM. " e02_layout_sort_build
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/581999/viewspace-903756/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/581999/viewspace-903756/