代码:
*&---------------------------------------------------------------------* *& REPORT ZTRR0180 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* REPORT ztrr0180 MESSAGE-ID zxxxxxx LINE-COUNT 50 "行 MIN=35 LINE-SIZE 132 "列 MIN=124 NO STANDARD PAGE HEADING. *----------------------------------------------------------------------* * <1.1-声明 包含程序> INCLUDE PROGRAMS * *----------------------------------------------------------------------* ***********《所有全局变量、类都写在 DEFINE INCLUDE 程序中》************** INCLUDE ztrr0180_define. ***********《所有查询条件都写在 SEL INCLUDE 程序中》***************** INCLUDE ztrr0180_sel. ***********《所有逻辑代码都写在 F0* INCLUDE 程序中》***************** INCLUDE ztrr0180_f01. ************************************************************************ * <第二部分---声明 过程:即事件> PROCESSING * ************************************************************************ *----------------------------------------------------------------------* * <2.1-用于程序的初始化,在显示选择屏前触发,> * * INITIAL PROCESS BEFORE THE STANDARD SELECTION SCREEN IS CALLED * *----------------------------------------------------------------------* INITIALIZATION. "初始化处理 PERFORM frm_intial. *----------------------------------------------------------------------* * <2.2-选择屏幕事件> * * EVENTS THAT OCCUR WHILE THE SELECTION SCREEN IS BING PROCESSED * *----------------------------------------------------------------------* * 所有选择屏幕数据传送到程序中之后触发的事件 AT SELECTION-SCREEN. *选择屏幕PBO事件,在显示选择屏幕前触发 AT SELECTION-SCREEN OUTPUT. * 当对SELECT-OPTIONS变量有多值输入时 *AT SELECTION-SCREEN ON END OF S_MATKL. * 当选择屏幕的BLOCK向程序传递值时触发{如点击执行,点击多选弹出其它窗口) AT SELECTION-SCREEN ON BLOCK bl01. * 按指定字段按F4触发 *AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_MATNR. * 按指定字段按F1触发 *AT SELECTION-SCREEN ON HELP-REQUEST FOR S_MATKL. * 当选择屏幕的RADIOBUTTON GROUP向程序传递值时触发 *AT SELECTION-SCREEN ON RADIOBUTTON GROUP RG1. * 触发了 FUNCTIONS BACK, EXIT, OR CANCEL AT SELECTION-SCREEN ON EXIT-COMMAND. *----------------------------------------------------------------------* * <2.3-在选择屏幕被处理后触发的事件,程序默认的开始事件> * * EVENT OCCURS AFTER THE SELECTION SCREEN HAS BEEN PROCESSED * *----------------------------------------------------------------------* START-OF-SELECTION. "权限检查 PERFORM frm_authority_check. "输入数据合法性检查 PERFORM frm_validate_check. "获取数据 PERFORM frm_get_data. "处理数据 PERFORM frm_process_data. "调用屏幕 PERFORM frm_call_screen. *----------------------------------------------------------------------* * <2.4-最后被触发的事件> * * THE LAST OF THE EVENTS CALLED BY THE RUNTIME ENVIRONMENT TO OCCUR * *----------------------------------------------------------------------* END-OF-SELECTION. "展示数据 PERFORM frm_show_data. "保存数据 PERFORM frm_save_data. "清空所有全局变量 PERFORM frm_clear_global_data.
*&---------------------------------------------------------------------* *& 包含 ZTRR0180_DEFINE *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* ************************************************************************ * <第一部分---声明程序变量和类> DECLARATION * ************************************************************************ *----------------------------------------------------------------------* * <1.2-声明用户自定义数据类型> LOCAL DATA TYPES IN PROGRAM * *----------------------------------------------------------------------* TYPES: BEGIN OF gty_tab, erdat TYPE zt0180-erdat, "创建日期 ertim TYPE zt0180-ertim, "创建时间 ernam TYPE zt0180-ernam, "创建者 aedat TYPE zt0180-aedat, "更改日期 aetim TYPE zt0180-aetim, "更改时间 aenam TYPE zt0180-aenam, "更改者 END OF gty_tab. *----------------------------------------------------------------------* * <1.3-声明内表、工作区> GLOBAL INTERNAL TABLES 、WORK AREA DECLARATION * *----------------------------------------------------------------------* DATA: gv_tlines TYPE string, "用以计算内表行数 gs_tab TYPE gty_tab, gt_tab TYPE STANDARD TABLE OF gty_tab.
*&---------------------------------------------------------------------* *& 包含 ZTRR0180_SEL *&---------------------------------------------------------------------* *&---------------------------------------------------------------------*
*----------------------------------------------------------------------* * <1-声明表工作区> TABLE_WORK_AREAS DECLARATION* *----------------------------------------------------------------------* TABLES:ZTTR0180,ZTGL0005,ZTAP0011. **----------------------------------------------------------------------* ** <2-声明选择屏幕> SELECTION SCREEN * *----------------------------------------------------------------------* "<定义选择屏幕的编号和标题文字> SELECTION-SCREEN BEGIN OF BLOCK BL01 WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_ZGUID FOR ZTTR0180-ZGUID, "GUID[36位] S_PRCTR FOR ZTTR0180-PRCTR OBLIGATORY, "利润中心 S_ZSSQY FOR ZTGL0005-ZSSQY MATCHCODE OBJECT zh_gl_nodeid_02, " 区域 S_MONAT FOR ZTTR0180-MONAT, "年月 S_YFDH FOR ZTAP0011-YFDH. "应付单号 SELECTION-SCREEN END OF BLOCK BL01.
*&---------------------------------------------------------------------* *& 包含 ZTRR0180_F01 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------*
*&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* *& 获取数据 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_get_data . IF sy-tcode = 'ZTR001'. "获取当月数据 PERFORM frm_get_dydata. ENDIF. IF gt_tab IS INITIAL. "获取所有数据 PERFORM frm_get_alldata. ENDIF. IF gt_tab IS INITIAL. MESSAGE '查询不到符合条件的数据,请重新输入'(002) TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_PROCESS_DATA *&---------------------------------------------------------------------* *& 处理数据 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_process_data . ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_AUTHORITY_CHECK *&---------------------------------------------------------------------* *& 权限检查 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_authority_check . DATA:lv_error TYPE char1. SELECT nodeid, zdate_up, zssqy INTO TABLE @DATA(lt_zt05) FROM zts005 WHERE nodeid IN @s_prctr AND zssqy IN @s_zssqy. CLEAR:lv_error. LOOP AT lt_zt05 INTO DATA(ls_zt05). AUTHORITY-CHECK OBJECT 'Z_SSQY' ID 'Z_SSQY' FIELD ls_zt05-zssqy. IF sy-subrc <> 0. MESSAGE '您没有区域:' && ls_zt05-zssqy && '的权限!' TYPE 'S' DISPLAY LIKE 'E'. lv_error = 'X'. EXIT. ENDIF.
IF lv_error = 'X'. LEAVE LIST-PROCESSING. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& FORM FRM_VALIDATE_CHECK *&---------------------------------------------------------------------* *& 数据合法性检查 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_validate_check . ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_SHOW_DATA *&---------------------------------------------------------------------* *& 展示数据 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_show_data . DATA: lt_fieldcat TYPE lvc_t_fcat, ls_layout TYPE lvc_s_layo. ls_layout-zebra = abap_on. "斑马线显示,颜色隔行交替显示 ls_layout-cwidth_opt = abap_on. "ALV网格(单元格)宽度设置为自动最优化,按输出内容宽度自动调整 ls_layout-info_fname = 'COLOR'. PERFORM frm_add_fieldcat USING: 'ERDAT' 'ZT0180' 'ERDAT' '创建日期'(017) CHANGING lt_fieldcat. PERFORM frm_add_fieldcat USING: 'ERTIM' 'ZT0180' 'ERTIM' '创建时间'(018) CHANGING lt_fieldcat. PERFORM frm_add_fieldcat USING: 'ERNAM' 'ZT0180' 'ERNAM' '创建者'(019) CHANGING lt_fieldcat. PERFORM frm_add_fieldcat USING: 'AEDAT' 'ZT0180' 'AEDAT' '更改日期'(020) CHANGING lt_fieldcat. PERFORM frm_add_fieldcat USING: 'AETIM' 'ZT0180' 'AETIM' '更改时间'(021) CHANGING lt_fieldcat. PERFORM frm_add_fieldcat USING: 'AENAM' 'ZT0180' 'AENAM' '更改者'(022) CHANGING lt_fieldcat. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid "注意点 i_callback_pf_status_set = 'FRM_SET_STATUS' i_callback_user_command = 'FRM_USER_COMMAND' is_layout_lvc = ls_layout it_fieldcat_lvc = lt_fieldcat i_save = 'A' TABLES t_outtab = gt_tab EXCEPTIONS program_error = 1 OTHERS = 2. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_SAVE_DATA *&---------------------------------------------------------------------* *& 保存数据 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_save_data . ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_CLEAR_GLOBAL_DATA *&---------------------------------------------------------------------* *& 清空所有全局变量 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_clear_global_data . ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_CALL_SCREEN *&---------------------------------------------------------------------* *& 调用屏幕 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_call_screen . ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_INTIAL *&---------------------------------------------------------------------* *& 初始化处理 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_intial . ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_ADD_FIELDCAT *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> P_ *& --> P_ *& --> P_ *& --> P_ *& --> P_ *& --> P_ *& --> P_ *& <-- LT_FIELDCAT *&---------------------------------------------------------------------* FORM frm_add_fieldcat USING i_ref_field i_ref_table i_fieldname i_coltext CHANGING ct_fieldcat TYPE lvc_t_fcat. DATA: ls_fieldcat TYPE lvc_s_fcat. CLEAR ls_fieldcat. ls_fieldcat-fieldname = i_fieldname. ls_fieldcat-coltext = i_coltext. ls_fieldcat-ref_field = i_ref_field. ls_fieldcat-ref_table = i_ref_table. APPEND ls_fieldcat TO ct_fieldcat. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_USER_COMMAND *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_user_command USING iv_ucomm LIKE sy-ucomm is_selfield TYPE slis_selfield. DATA: lr_grid TYPE REF TO cl_gui_alv_grid. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lr_grid. CALL METHOD lr_grid->check_changed_data. is_selfield-refresh = 'X'. CASE iv_ucomm . WHEN '&F03' OR '&F12' OR '&F15'. LEAVE TO SCREEN 0. WHEN '&LSSY'. "获取所有数据 PERFORM frm_get_alldata. WHEN '&DYFKJH'.
"获取当月数据 PERFORM frm_get_dydata. ENDCASE. ENDFORM . *&---------------------------------------------------------------------* *& Form FRM_SET_STATUS *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_set_status USING lt_extab TYPE slis_t_extab. SET PF-STATUS 'STATUS'. CLEAR gv_tlines. gv_tlines = lines( gt_tab ). SET TITLEBAR 'TITLE0100' WITH gv_tlines. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_GET_ALLDATA *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_get_alldata . SELECT a~zguid, "GUID(36位) a~monat, "年月 a~prctr, "利润中心 d~ltext, "利润中心描述 c~zssqy, "区域 a~zbm, "项目分期 b~yfdh, "应付单号 a~qdywxtno, "前端业务系统合同G a~reftype, "数据来源 a~ywsqdh, "原始系统申请单据号 a~yqfksj, "要求付款时间 a~ybje, "原币金额 a~yzfje, "已支付金额 a~planzfamount, "当月应付金额 a~skdw, "供应商 a~erdat, "创建日期 a~ertim, "创建时间 a~ernam, "创建者 a~aedat, "更改日期 a~aetim, "更改时间 a~aenam "更改者 FROM zt0180 AS a LEFT JOIN zt011 AS b ON a~zguid = b~zguid LEFT JOIN zt005 AS c ON a~prctr = c~nodeid LEFT JOIN cepct AS d ON d~prctr = a~prctr AND datbi = '99991231' AND spras = @sy-langu WHERE a~zguid IN @s_zguid"GUID[36位] AND a~prctr IN @s_prctr"利润中心 AND c~zssqy IN @s_zssqy" 区域 AND a~monat IN @s_monat"年月 AND b~yfdh IN @s_yfdh"应付单号 AND b~yfdh NE '' AND a~prctr NE '' INTO CORRESPONDING FIELDS OF TABLE @gt_tab. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_GET_DYDATA *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_get_dydata . RANGES:lr_monat FOR zttr0180-monat." DATA:ls_monat LIKE LINE OF lr_monat. ls_monat-sign = 'I'. ls_monat-low = sy-datum+0(6). ls_monat-option = 'EQ'. APPEND ls_monat TO lr_monat. SELECT a~zguid, "GUID(36位) a~monat, "年月 a~prctr, "利润中心 d~ltext, "利润中心描述 c~zssqy, "区域 a~zbm, "项目分期 b~yfdh, "应付单号 a~qdywxtno, "前端业务系统合同G a~reftype, "数据来源 a~ywsqdh, "原始系统申请单据号 a~yqfksj, "要求付款时间 a~ybje, "原币金额 a~yzfje, "已支付金额 a~planzfamount, "当月应付金额 a~skdw, "供应商 a~erdat, "创建日期 a~ertim, "创建时间 a~ernam, "创建者 a~aedat, "更改日期 a~aetim, "更改时间 a~aenam "更改者 FROM zt0180 AS a LEFT JOIN zt011 AS b ON a~zguid = b~zguid LEFT JOIN zt005 AS c ON a~prctr = c~nodeid LEFT JOIN cepct AS d ON d~prctr = a~prctr AND datbi = '99991231' AND spras = @sy-langu WHERE a~zguid IN @s_zguid"GUID[36位] AND a~prctr IN @s_prctr"利润中心 AND c~zssqy IN @s_zssqy" 区域 AND a~monat IN @lr_monat"年月 AND b~yfdh IN @s_yfdh"应付单号 AND b~yfdh NE '' AND a~prctr NE '' INTO CORRESPONDING FIELDS OF TABLE @gt_tab. ENDFORM.