4个选择屏幕 执行- 显示查询报表--双击凭证跳转MB03
*&---------------------------------------------------------------------*
*& Report  Z_PROGRAM_ALV_WORK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  Z_PROGRAM_ALV_WORK.
*ALV使用到的类库
TYPE-POOLS: SLIS.
*数据定义
INCLUDE Z_PROGRAM_ALV_WORK_DATADECLARE.
*选择屏幕
INCLUDE Z_ALV_SEARCH.
INCLUDE Z_PROGRAM_ALV_WORK_FORMS.
INCLUDE Z_PROGRAM_ALV_WORK_TABLE.
"CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&  包括                Z_PROGRAM_ALV_WORK_DATADECLARE
*&---------------------------------------------------------------------*
INCLUDE <LIST>.
DATA:  BEGIN OF TA_MSEG OCCURS 0,
MJAHR LIKE MSEG-MJAHR,
MBLNR LIKE MSEG-MBLNR,
ZEILE LIKE MSEG-ZEILE,
BWART LIKE MSEG-BWART,
MAKTX LIKE MAKT-MAKTX,
DMBTR LIKE MSEG-DMBTR,
WERKS LIKE MSEG-WERKS,
LGORT LIKE MSEG-LGORT,
sort out ofCHARG LIKE MSEG-CHARG,
LIGHT(20) TYPE C,
END OF TA_MSEG.
*一列描述
DATA WA_ALV_FIELD TYPE SLIS_FIELDCAT_ALV.
*列描述内表,列清单
DATA WA_ALV_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
*灯的颜
DATA gt_sort TYPE slis_t_sortinfo_alv.
DATA gs_sort TYPE slis_sortinfo_alv.
*DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
*      ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
*      WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
*&---------------------------------------------------------------------*
*&  包括                Z_ALV_SEARCH
*&---------------------------------------------------------------------*
*选择屏幕
TABLES: MSEG.
*物料凭证
SELECT-OPTIONS S_MBLNR FOR MSEG-MBLNR.
*物料凭证年度
SELECT-OPTIONS S_MJAHR FOR MSEG-MJAHR.
*移动类型
SELECT-OPTIONS S_BWART FOR MSEG-BWART.
*物料
SELECT-OPTIONS S_MATNR FOR MSEG-MATNR.
*&---------------------------------------------------------------------*
*&  包括                Z_PROGRAM_ALV_WORK_FORMS
*&---------------------------------------------------------------------*
FORM FRM_GETDATA.
SELECT MSEG~MJAHR MSEG~BWART
MSEG~MBLNR MSEG~ZEILE
MSEG~MATNR MAKT~MAKTX
MSEG~DMBTR MSEG~WERKS
MSEG~LGORT MSEG~CHARG
FROM MSEG
INNER JOIN MAKT
ON MSEG~MATNR = MAKT~MATNR
INTO CORRESPONDING FIELDS OF TABLE TA_MSEG
WHERE
MSEG~MBLNR IN S_MBLNR  AND
MSEG~MJAHR IN S_MJAHR
AND MSEG~BWART IN S_BWART
AND MSEG~MATNR IN S_MATNR.
*排序
*SORT TA_MSEG  DESCENDING BY MBLNR ASCENDING.
ENDFORM.
FORM FRM_PLAYLIST.
LOOP AT TA_MSEG.
*打印图案颜
IF TA_MSEG-DMBTR < 3000.
TA_MSEG-LIGHT = icon_red_light.
ELSEIF TA_MSEG-DMBTR <= 5000.
TA_MSEG-LIGHT = icon_yellow_light.
ELSEIF TA_MSEG-DMBTR > 5000.
TA_MSEG-LIGHT = icon_green_light.
ENDIF.
MODIFY TA_MSEG.
ENDLOOP.
WA_ALV_FIELD-COL_POS = 1.
WA_ALV_FIELD-FIELDNAME = 'MJAHR'.
WA_ALV_FIELD-SELTEXT_M = '年度'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.  "一列描述赋给列描述(列清单)
WA_ALV_FIELD-COL_POS = 3.
WA_ALV_FIELD-FIELDNAME = ' ZEILE'.
WA_ALV_FIELD-SELTEXT_M = '项目'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 4.
WA_ALV_FIELD-FIELDNAME = 'MATNR'.
WA_ALV_FIELD-SELTEXT_M = '物料'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 5.
WA_ALV_FIELD-FIELDNAME = 'MAKTX'.
WA_ALV_FIELD-SELTEXT_M = '物料文本'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 6.
WA_ALV_FIELD-FIELDNAME = 'DMBTR'.
WA_ALV_FIELD-SELTEXT_M = '本位币金额'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 7.
WA_ALV_FIELD-FIELDNAME = 'WERKS'.
WA_ALV_FIELD-SELTEXT_M = '工厂'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 8.
WA_ALV_FIELD-FIELDNAME = 'LGORT'.
WA_ALV_FIELD-SELTEXT_M = '库存地点'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 9.
WA_ALV_FIELD-FIELDNAME = 'CHARG'.
WA_ALV_FIELD-SELTEXT_M = '批次'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 10.
WA_ALV_FIELD-FIELDNAME = 'LIGHT'.
WA_ALV_FIELD-SELTEXT_M = '灯'.
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
WA_ALV_FIELD-COL_POS = 2.
WA_ALV_FIELD-FIELDNAME = 'MBLNR'.
WA_ALV_FIELD-SELTEXT_M = '凭证'.
WA_ALV_FIELD-HOTSPOT = 'X'.        "字段带下划线
APPEND WA_ALV_FIELD TO WA_ALV_FIELDCAT.
clear gs_sort.
gs_sort-fieldname = 'MJAHR'.
gs_sort-up        = 'X'. "the sort direction of this field
gs_sort-subtot    = 'X'. "whether the subtotal will be showed on this field
append gs_sort to gt_sort.  "相当于是把gs_sort这个对象存到gt_这个集合中
clear gs_sort.
gs_sort-fieldname = 'MBLNR'.
gs_sort-up        = 'X'.
gs_sort-subtot    = 'X'.
append gs_sort to gt_sort.
*通过数据字典结构显示ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'    "GRID表示显示的是网格,而TABLE则是表格
EXPORTING
I_CALLBACK_PROGRAM      = SY-REPID
I_CALLBACK_USER_COMMAND = 'FRM_COMMANT'
IT_FIELDCAT = WA_ALV_FIELDCAT          "列描述内表(列清单)赋给IT_FIELDCAT
IT_SORT = gt_sort
TABLES
T_OUTTAB = TA_MSEG.
*IF SY-SUBRC <> 0.
*ENDIF.
ENDFORM.
FORM FRM_COMMANT USING UCOM LIKE SY-UCOMM  SELFD TYPE SLIS_SELFIELD.
CASE UCOM.
*    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
*      LEAVE PROGRAM.
WHEN '&IC1'.
CASE SELFD-FIELDNAME.
WHEN  'MBLNR'.
READ TABLE TA_MSEG INDEX SELFD-TABINDEX.
SET PARAMETER ID 'MBN' FIELD TA_MSEG-MBLNR.
CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN.
WHEN OTHERS.
ENDCASE.
*      SELFD-REFRESH = 'X' . "双击时不让ALV刷新
ENDCASE.
ENDFORM.
*&-----------------------
----------------------------------------------*
* 定义状态条、包括菜单、工具条按钮、系统按钮等
*----------------------------------------------------------------------*
*  MODULE STATUS_0100 OUTPUT.
*      SET PF-STATUS 'STATUS_WORK'.
**    如果窗口还没有创建ALV对象则创建它
*      IF WA_CUSTOM_CONTAINER IS INITIAL.
*        CREATE OBJECT WA_CUSTOM_CONTAINER
*            EXPORTING
*              CONTAINER_NAME = WA_CONTAINER.
*        CREATE OBJECT ALV_GRID
*          EXPORTING
*            I_PARENT = WA_CUSTOM_CONTAINER.
*            CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
*          EXPORTING
*            I_STRUCTURE_NAME = 'MESG'
*          CHANGING
*            IT_OUTTAB = TA_MSEG.
*      ENDIF.
*  ENDMODULE.
*&---------------------------------------------------------------------*
*&  包括                Z_PROGRAM_ALV_WORK_TABLE
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM FRM_GETDATA.
PERFORM FRM_PLAYLIST.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。