TOP.
DATA:gt_table TYPE TABLE OF zfi_zcfz,
gs_table TYPE zfi_zcfz.
DATA: gt_fieldcat_lvc TYPE lvc_t_fcat,
gs_layout_lvc TYPE lvc_s_layo,
gs_fieldcat_lvc TYPE lvc_s_fcat.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
"设置fildcat
DEFINE set_fieldfcat.
gs_fieldcat_lvc-fieldname = &1. "字段名
gs_fieldcat_lvc-coltext = &2. "字段描述
gs_fieldcat_lvc-scrtext_l = &2.
gs_fieldcat_lvc-scrtext_m = &2.
gs_fieldcat_lvc-scrtext_s = &2.
gs_fieldcat_lvc-ref_table = &3.
gs_fieldcat_lvc-ref_field = &4.
gs_fieldcat_lvc-edit = &5.
gs_fieldcat_lvc-outputlen = &6. "列宽
gs_fieldcat_lvc-just = &7. "显示位置
gs_fieldcat_lvc-no_out = &8.
APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
CLEAR gs_fieldcat_lvc.
END-OF-DEFINITION.
CLASS.
*&---------------------------------------------------------------------*
*& 包含 ZFI_ZCFZ_CLS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED
*----------------------------------------------------------------------*
* LCL_EVENT_RECEIVER
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA gv_flg TYPE char01.
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* lcl_event_receiver的类定义:
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_modify
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified
et_good_cells.
METHODS:
handle_f4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify.
LOOP AT et_good_cells INTO DATA(ls_modi).
READ TABLE gt_table ASSIGNING FIELD-SYMBOL(<ls_tab>) INDEX ls_modi-row_id.
IF sy-subrc = 0 .
IF ls_modi-fieldname = 'ZZZSL'.
IF ls_modi-value IS INITIAL .
<ls_tab>-zzzje = <ls_tab>-zzcjz.
ELSE.
IF <ls_tab>-zzsl IS INITIAL .
MESSAGE '总数量不能为空' TYPE 'E'.
ELSE.
<ls_tab>-zzzje = <ls_tab>-zzcjz * ls_modi-value / <ls_tab>-zzsl.
ENDIF.
ENDIF.
<ls_tab>-zsyje = <ls_tab>-zzcjz - <ls_tab>-zzzje .
ENDIF.
IF ls_modi-fieldname = 'ZZSL'.
IF <ls_tab>-zzzsl IS NOT INITIAL AND ls_modi-value IS NOT INITIAL .
<ls_tab>-zzzje = <ls_tab>-zzcjz * <ls_tab>-zzzsl / <ls_tab>-zzsl.
<ls_tab>-zsyje = <ls_tab>-zzcjz - <ls_tab>-zzzje .
ENDIF.
ENDIF.
ENDIF.
CLEAR ls_modi.
ENDLOOP.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
ENDMETHOD. "HANDLE_MODIFY
METHOD handle_f4.
DATA: lt_return TYPE TABLE OF ddshretval,
ls_return TYPE ddshretval..
* IF e_fieldname = 'ZGC'.
* READ TABLE gt_table INTO gs_table INDEX es_row_no-row_id.
* IF sy-subrc = 0.
*
* CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
* EXPORTING
* retfield = 'FEVOR' "筛选内表里面的字段
* dynpprog = sy-repid
* dynpnr = sy-dynnr
* dynprofield = 'GS_TAB-FEVOR' "ALV内表字段
* value_org = 'S'
* " CALLBACK_PROGRAM = SY-REPID
* TABLES
* value_tab = lt_gc[] "需要显示帮助的值内表
* return_tab = lt_return "返回值
* EXCEPTIONS
* parameter_error = 1
* no_values_found = 2
* OTHERS = 3.
* ENDIF.
*
* READ TABLE lt_return INTO ls_return INDEX 1.
* gs_table-zgc = ls_return-fieldval.
* MODIFY gt_table FROM gs_table INDEX es_row_no-row_id TRANSPORTING zgc.
*
* ENDIF.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
ENDMETHOD. "HANDLE_F4
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
FORM refresh_table_alv .
lr_grid->set_frontend_layout( is_layout = gs_layout_lvc ).
lr_grid->refresh_table_display( is_stable = VALUE lvc_s_stbl( row = 'X' col = 'X' ) ).
ENDFORM.
主体。
INCLUDE zfi_zcfz_top.
INCLUDE zfi_zcfz_scr.
INCLUDE zfi_zcfz_cls.
INCLUDE zfi_zcfz_frm.
INITIALIZATION.
PERFORM frm_init.
START-OF-SELECTION.
IF p_cj = 'X'.
PERFORM frm_get_data.
ELSE.
PERFORM frm_get_data1.
ENDIF.
IF gt_table IS INITIAL .
MESSAGE '未查询到数据' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
PERFORM frm_alv_dis.
FORM.
*&---------------------------------------------------------------------*
*& 包含 ZFI_ZCFZ_FRM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_data .
SELECT
pspid,
posid,
zzcqd,
zsbjz,
zjahj,
zggft,
zzcjz
INTO TABLE @DATA(lt_fzgc)
FROM zfi_zcfzgc
WHERE pspid = @p_pspid.
SORT lt_fzgc BY pspid posid zzcqd.
DELETE ADJACENT DUPLICATES FROM lt_fzgc COMPARING pspid posid zzcqd.
IF lt_fzgc IS INITIAL .
MESSAGE '未取到资产赋值过程数据' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
"取型号
SELECT
posid,
xref3,
zzcqd
INTO TABLE @DATA(lt_tdgz)
FROM zfi_tsftgz
FOR ALL ENTRIES IN @lt_fzgc
WHERE posid = @lt_fzgc-posid
AND zzcqd = @lt_fzgc-zzcqd.
SORT lt_tdgz BY posid zzcqd.
"取资产卡片
SELECT
zzcqd,
anln1
INTO TABLE @DATA(lt_zcsz)
FROM zfi_zcsz
FOR ALL ENTRIES IN @lt_fzgc
WHERE zzcqd = @lt_fzgc-zzcqd.
SORT lt_zcsz BY zzcqd.
CLEAR gt_table.
LOOP AT lt_fzgc INTO DATA(ls_fzgc).
MOVE-CORRESPONDING ls_fzgc TO gs_table.
READ TABLE lt_tdgz INTO DATA(ls_tdgz) WITH KEY posid = ls_fzgc-posid zzcqd = ls_fzgc-zzcqd BINARY SEARCH.
IF sy-subrc = 0.
gs_table-xref3 = ls_tdgz-xref3.
CLEAR ls_tdgz.
ENDIF.
READ TABLE lt_zcsz INTO DATA(ls_zcsz) WITH KEY zzcqd = ls_fzgc-zzcqd BINARY SEARCH.
IF sy-subrc = 0.
gs_table-anln1 = ls_zcsz-anln1.
CLEAR ls_zcsz.
ENDIF.
gs_table-zsyje = gs_table-zzcjz .
APPEND gs_table TO gt_table.
CLEAR gs_table.
CLEAR ls_fzgc.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DIS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_alv_dis .
DATA: ls_events TYPE slis_alv_event,
lt_event TYPE slis_t_event.
ls_events-name = 'CALLER_EXIT'.
ls_events-form = 'FM_BUTTON'.
APPEND ls_events TO lt_event.
* 设置fieldcat
CLEAR gt_fieldcat_lvc.
PERFORM frm_set_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'F_SET_STATUS'
i_callback_user_command = 'F_USER_COMMAND'
* i_grid_settings = ls_grid_settings
is_layout_lvc = gs_layout_lvc
it_fieldcat_lvc = gt_fieldcat_lvc
it_events = lt_event
* i_save = 'A'
TABLES
t_outtab = gt_table
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM f_set_status USING p_extab TYPE slis_t_extab.
DATA lt_tab TYPE TABLE OF sy-ucomm WITH HEADER LINE .
CLEAR lt_tab[].
* IF p_psphi IS NOT INITIAL .
* APPEND 'DEL' TO lt_tab.
* ENDIF.
SET PF-STATUS 'F_SET_STATUS' EXCLUDING lt_tab[].
ENDFORM.
FORM f_user_command USING p_ucomm TYPE sy-ucomm
p_selfield TYPE slis_selfield .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
CASE sy-ucomm.
WHEN 'SAVE'.
PERFORM frm_save.
WHEN OTHERS.
ENDCASE.
"REFRESH
CALL METHOD lr_grid->set_frontend_layout
EXPORTING
is_layout = gs_layout_lvc.
lr_grid->refresh_table_display( is_stable = VALUE lvc_s_stbl( row = 'X'
col = 'X' ) ).
ENDFORM.
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
DATA: lv_event_receiver TYPE REF TO lcl_event_receiver,
lt_f4 TYPE lvc_t_f4,
ls_f4 TYPE lvc_s_f4.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.
* 设置enter事件
CALL METHOD lr_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
CREATE OBJECT lv_event_receiver.
SET HANDLER lv_event_receiver->handle_modify FOR lr_grid.
* 设置f4事件
* CHECK gv_flg IS INITIAL.
*
* gv_flg = 'X'.
*
* ls_f4-fieldname = 'ZSJCS'. "窗口时间参数(需要定义F4帮助按钮的字段)
* ls_f4-register = 'X'.
* ls_f4-getbefore = 'X'.
* ls_f4-chngeafter = 'X'.
* INSERT ls_f4 INTO TABLE lt_f4.
*
* CREATE OBJECT lv_event_receiver.
* SET HANDLER lv_event_receiver->handle_f4 FOR tem_grid.
*
* CALL METHOD tem_grid->register_f4_for_fields
* EXPORTING
* it_f4 = lt_f4[].
ENDFORM. "FM_BUTTON
*&---------------------------------------------------------------------*
*& Form FRM_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_init .
gs_layout_lvc-zebra = 'X'.
gs_layout_lvc-cwidth_opt = 'X'.
gs_layout_lvc-sel_mode = 'A'.
gs_layout_lvc-no_toolbar = 'X'.
* gs_layout_lvc-stylefname = 'STYLE'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat .
set_fieldfcat 'POSID' 'WBS编号' '' '' '' '' '' ''.
set_fieldfcat 'ZZCQD' '资产清单' '' '' '' '' '' ''.
set_fieldfcat 'ANLN1' '资产卡片' '' '' '' '' '' ''.
set_fieldfcat 'ZSBJZ' '设备金额' '' '' '' '' '' ''.
set_fieldfcat 'XREF3' '型号' '' '' '' '' '' ''.
set_fieldfcat 'ZJAHJ' '建安合计金额' '' '' '' '' '' ''.
set_fieldfcat 'ZGGFT' '公共分摊' '' '' '' '' '' ''.
set_fieldfcat 'ZZCJZ' '资产总价值' '' '' '' '' '' ''.
set_fieldfcat 'ZZSL' '总数量' 'MSEG' 'MENGE' 'X' '' '' ''.
set_fieldfcat 'ZZZSL' '转资数量' 'MSEG' 'MENGE' 'X' '' '' ''.
set_fieldfcat 'ZZZJE' '转资金额' '' '' '' '' '' ''.
set_fieldfcat 'ZSYJE' '剩余金额' '' '' '' '' '' ''.
set_fieldfcat 'PSPID' '项目号' '' '' '' '' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SAVE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_save .
DATA :lt_fz TYPE TABLE OF zfi_zcfz,
ls_fz TYPE zfi_zcfz.
CLEAR lt_fz.
LOOP AT gt_table INTO gs_table.
MOVE-CORRESPONDING gs_table TO ls_fz.
APPEND ls_fz TO lt_fz.
CLEAR ls_fz.
CLEAR gs_table.
ENDLOOP.
IF lt_fz IS NOT INITIAL .
MODIFY zfi_zcfz FROM TABLE lt_fz.
IF sy-subrc = 0.
COMMIT WORK.
MESSAGE '保存成功' TYPE 'S' .
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA1
*&---------------------------------------------------------------------*
* text
FORM frm_get_data1 .
SELECT
*
INTO TABLE gt_table
FROM zfi_zcfz
WHERE pspid = p_pspid.
ENDFORM.