*& Report ZXXXX
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZXXXX.
TABLES:fmcifmfctr.
\" alv 控件 定义处理
data: g_custom_container1001 type ref to cl_gui_custom_container.
data alvgrid1001 type ref to cl_gui_alv_grid.
data gs_layout_alv1001 type LVC_S_LAYO.
data gt_tab1001 type lvc_t_fcat.
data gt_wa1001 type lvc_t_fcat with header line.
data flag1001.\"全局标示。
data x1001 type i.
data y1001 type i.
data select_rows1001 type LVC_s_ROW OCCURS 0 WITH HEADER LINE.
data select_rows1001_get type LVC_s_ROW OCCURS 0 WITH HEADER LINE.
data: BEGIN OF itab OCCURS 0
FUNDS_CTR TYPE BAPI_0050_ITEM-FUNDS_CTR
CMMT_ITEM TYPE BAPI_0050_ITEM-CMMT_ITEM
END OF itab.
data: BEGIN OF alv_out OCCURS 0
FISC_YEAR TYPE BAPI_0050_ITEM-FISC_YEAR
DOCDATE TYPE BAPI_0050_HEADER-DOCDATE
FUNDS_CTR TYPE BAPI_0050_ITEM-FUNDS_CTR
CMMT_ITEM TYPE BAPI_0050_ITEM-CMMT_ITEM
TOTAL_AMOUNT TYPE BAPI_0050_ITEM-TOTAL_AMOUNT
ITEM_TEXT TYPE BAPI_0050_ITEM-ITEM_TEXT
BUDGETING_PERIOD TYPE BAPI_0050_PERIOD-BUDGETING_PERIOD
PERIOD_AMOUNT TYPE BAPI_0050_PERIOD-PERIOD_AMOUNT
belnr TYPE bseg-belnr
state TYPE icon-id
state_txt(30)
END OF alv_out.
data g_FILE LIKE RLGRAP-FILENAME.
DATA: G_MAX_COL TYPE I.
*----------------------------------------------------------------------*
* CLASS cl_event_receiver1001 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class cl_event_receiver1001 definition.
public section.
methods:
handle_toolbar for event toolbar of cl_gui_alv_grid
importing e_obxxxxject e_interactive
handle_user_command for event user_command of cl_gui_alv_grid
importing e_ucomm
handle_double_click
for event double_click of cl_gui_alv_grid
importing e_row e_column.
private section.
endclass. \"cl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class cl_event_receiver1001 implementation.
method handle_toolbar.
data: ls_toolbar type stb_button.
clear ls_toolbar.
move 'POST' to ls_toolbar-function.
move ICON_SYSTEM_OKAY to ls_toolbar-icon.\"
move '单据过账' to ls_toolbar-quickinfo.
move '单据过账' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_obxxxxject->mt_toolbar.
endmethod. \"handle_toolbar
method handle_user_command.
data: lt_rows type lvc_t_row.
case e_ucomm.
when 'POST'.
PERFORM post.
endcase.
endmethod. \"handle_user_command
method handle_double_click.
flag1001 = 'X'.
x1001 = e_row-index.
data:l_row type i
l_field(30).
l_row = e_row-index.
l_field = e_column-fieldname.
\"PERFORM call_tcode USING l_row l_field .
* CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE'
* EXPORTING
* functioncode = 'FLUSH'.
endmethod. \"handle_double_click
endclass. \"cl_event_receiver IMPLEMENTATION
data: event_receiver1001 type ref to cl_event_receiver1001.
start-of-selection.
call SCREEN 1001.
*&---------------------------------------------------------------------*
*& Module STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_1001 OUTPUT.
SET PF-STATUS '1001'.
SET TITLEBAR '1001'.
if g_custom_container1001 is initial.
free gt_tab1001.
clear gt_tab1001.
PERFORM build_cat USING 'STATE' '数据校验' 'X' ''.
PERFORM build_cat USING 'STATE_TXT' '校验结果' 'X' ''.
PERFORM build_cat USING 'FISC_YEAR' '会计年度' '' ''.
PERFORM build_cat USING 'DOCDATE' '凭证日期' '' ''.
PERFORM build_cat USING 'FUNDS_CTR' '基金中心' '' ''.
PERFORM build_cat USING 'CMMT_ITEM' '承诺项目' '' ''.
PERFORM build_cat USING 'TOTAL_AMOUNT' '总金额' '' ''.
PERFORM build_cat USING 'BUDGETING_PERIOD' '预算期间' '' ''.
PERFORM build_cat USING 'PERIOD_AMOUNT' '期间金额' '' ''.
PERFORM build_cat USING 'BELNR' '预算凭证' '' ''.
CREATE obxxxxject g_custom_container1001
EXPORTING
container_name = 'C1001'.
CREATE obxxxxject alvgrid1001
EXPORTING
i_parent = g_custom_container1001.
CREATE obxxxxject event_receiver1001.
set handler event_receiver1001->handle_toolbar for alvgrid1001.
set handler event_receiver1001->handle_double_click for alvgrid1001.
set handler event_receiver1001->handle_user_command for alvgrid1001.
gs_layout_alv1001-no_toolbar = ''.
gs_layout_alv1001-cwidth_opt = 'X'.
gs_layout_alv1001-sel_mode = 'X'.
endif.
CALL METHOD alvgrid1001->set_table_for_first_display
EXPORTING
is_layout = gs_layout_alv1001
* it_toolbar_excluding = pt_exclude
CHANGING
it_fieldcatalog = gt_tab1001
* it_sort = gt_sort_grid[]
it_outtab = alv_out[].
free select_rows1001.
CLEAR select_rows1001.
select_rows1001-INDEX = x1001.
APPEND select_rows1001.
CLEAR select_rows1001.
CALL METHOD alvgrid1001->set_selected_rows
EXPORTING
it_index_rows = select_rows1001[].
ENDMODULE. \" STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1001 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
set SCREEN 0.
when 'UP'.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
MASK = '文本文件(制表符分隔)*.xls'
STATIC = 'X'
CHANGING
FILE_NAME = g_FILE.
PERFORM SUB_GET_MAX_COL USING alv_out[]
CHANGING G_MAX_COL.
PERFORM SUB_IMPORT_XLS_TO_ITAB TABLES alv_out
USING alv_out
g_FILE.
LOOP AT alv_out.
SELECT SINGLE * FROM fmci WHERE FIPEX = alv_out-CMMT_ITEM.
IF sy-subrc <> 0.
alv_out-state = '@0A@'.
CONCATENATE '承诺项目' alv_out-cmmt_item '不存在' INTO alv_out-state_txt.
ENDIF.
SELECT SINGLE * FROM fmfctr WHERE FICTR = alv_out-FUNDS_CTR.
IF sy-subrc <> 0.
alv_out-state = '@0A@'.
CONCATENATE '基金中心' alv_out-cmmt_item '不存在' INTO alv_out-state_txt.
ENDIF.
IF alv_out-TOTAL_AMOUNT <> 0 and alv_out-PERIOD_AMOUNT <> 0.
alv_out-state = '@0A@'.
alv_out-state_txt = '汇总金额和期间金额只能输入一个'.
ENDIF.
IF alv_out-TOTAL_AMOUNT = 0 and alv_out-PERIOD_AMOUNT = 0.
alv_out-state = '@0A@'.
alv_out-state_txt = '汇总金额和期间金额必须输入一个'.
ENDIF.
IF alv_out-state = ''.
alv_out-state = '@01@'.
alv_out-state_txt = '正确'.
ENDIF.
modify alv_out.
CLEAR alv_out.
ENDLOOP.
when 'DOWN'.
DATA: L_OBJDATA TYPE WWWDATATAB
p_subrc TYPE sy-subrc
l_str(200).
CONCATENATE 'C:\\ZHYLFI014\\' SY-DATUM sy-uzeit'.XLS' INTO g_FILE.
SELECT SINGLE RELID OBJID
FROM WWWDATA \"存对象模板的表
INTO CORRESPONDING FIELDS OF L_OBJDATA
WHERE SRTF2 = 0
AND RELID = 'MI' \"有三种类型 HT MI IT
AND OBJID = 'ZHYLFI014.XLS' .
CONDENSE g_FILE NO-GAPS.
CALL FUNCTION 'DOWNLOAD_WEB_obxxxxject'
EXPORTING
KEY = L_OBJDATA
DESTINATION = g_file
IMPORTING
RC = P_SUBRC.
IF p_SUBRC <> 0.
MESSAGE '模板下载失败!' TYPE 'S' DISPLAY LIKE 'E'.
ELSe.
CONCATENATE '模板下载成功,请到' g_file '路径下查看!' INTO l_str.
MESSAGE l_str TYPE 'S' DISPLAY LIKE 'S'.
ENDIF.
when 'FLUSH'.
WHEN OTHERS.
ENDCASE.
ENDMODULE. \" USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_CAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P1 text
* -->P2 text
* -->P3 text
* -->P4 text
*----------------------------------------------------------------------*
FORM BUILD_CAT USING p1 p2 p3 p4.
gt_wa1001-fieldname = p1.
gt_wa1001-coltext = p2.
gt_wa1001-key = p3.
gt_wa1001-HOTSPOT = p4.
append gt_wa1001 to gt_tab1001.
clear gt_wa1001.
ENDFORM. \" BUILD_CAT
*&---------------------------------------------------------------------*
*& Form POST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM POST .
data:HEADER_DATA TYPE BAPI_0050_HEADER
FMAREA TYPE BAPI_0050_FIELDS-FM_AREA
DOCUMENTYEAR TYPE BAPI_0050_FIELDS-DOC_YEAR
DOCUMENTNUMBER TYPE BAPI_0050_FIELDS-DOCUMENT
ITEM_DATA LIKE BAPI_0050_ITEM OCCURS 0 WITH HEADER LINE
PERIOD_DATA LIKE BAPI_0050_PERIOD OCCURS 0 WITH HEADER LINE
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
data: x TYPE i
err type c.
READ TABLE alv_out INDEX 1.
header_data-FM_AREA = 'SRMB'.
header_data-VERSION = '000'.
header_data-DOCDATE = alv_out-DOCDATE.
header_data-DOCTYPE = 'FM01'.
header_data-DOCSTATE = '1'.
header_data-PROCESS = 'ENTR'.
free ITEM_DATA.
CLEAR ITEM_DATA.
free PERIOD_DATA.
CLEAR PERIOD_DATA.
free itab.
CLEAR itab.
LOOP AT alv_out.
itab-FUNDS_CTR = alv_out-FUNDS_CTR.
itab-CMMT_ITEM = alv_out-CMMT_ITEM.
APPEND itab.
CLEAR itab.
ENDLOOP.
SORT itab AS TEXT by FUNDS_CTR CMMT_ITEM.
delete ADJACENT DUPLICATES FROM itab.
x = 0.
LOOP at itab.
x = x + 1.
read TABLE alv_out WITH KEY FUNDS_CTR = itab-FUNDS_CTR
CMMT_ITEM = itab-CMMT_ITEM.
ITEM_DATA-ITEM_NUM = x.
ITEM_DATA-FISC_YEAR = alv_out-FISC_YEAR.
ITEM_DATA-BUDCAT = '9F'.
ITEM_DATA-BUDTYPE = 'YS01'.
ITEM_DATA-FUNDS_CTR = alv_out-FUNDS_CTR.
ITEM_DATA-CMMT_ITEM = alv_out-CMMT_ITEM.
ITEM_DATA-TRANS_CURR = 'RMB'.
if alv_out-TOTAL_AMOUNT <> 0.
ITEM_DATA-TOTAL_AMOUNT = alv_out-TOTAL_AMOUNT.
ITEM_DATA-DISTKEY = '1'.
endif.
ITEM_DATA-ITEM_TEXT = alv_out-item_text.
ITEM_DATA-VALTYPE = 'B1'.
APPEND ITEM_DATA.
CLEAR ITEM_DATA.
endloop.
LOOP at alv_out WHERE TOTAL_AMOUNT = 0.
READ TABLE item_data WITH KEY FUNDS_CTR = alv_out-FUNDS_CTR
CMMT_ITEM = alv_out-CMMT_ITEM.
PERIOD_DATA-ITEM_NUM = item_data-ITEM_NUM.
PERIOD_DATA-BUDGETING_PERIOD = alv_out-BUDGETING_PERIOD.
PERIOD_DATA-PERIOD_AMOUNT = alv_out-PERIOD_AMOUNT.
APPEND PERIOD_DATA.
CLEAR PERIOD_DATA.
endloop.
* LOOP at alv_out.
* x = x + 1.
* ITEM_DATA-ITEM_NUM = x.
* ITEM_DATA-FISC_YEAR = alv_out-FISC_YEAR.
* ITEM_DATA-BUDCAT = '9F'.
* ITEM_DATA-BUDTYPE = 'YS01'.
* ITEM_DATA-FUNDS_CTR = alv_out-FUNDS_CTR.
* ITEM_DATA-CMMT_ITEM = alv_out-CMMT_ITEM.
* ITEM_DATA-TRANS_CURR = 'RMB'.
* if alv_out-TOTAL_AMOUNT <> 0.
* ITEM_DATA-TOTAL_AMOUNT = alv_out-TOTAL_AMOUNT.
* ITEM_DATA-DISTKEY = '1'.
* endif.
* ITEM_DATA-ITEM_TEXT = alv_out-item_text.
* ITEM_DATA-VALTYPE = 'B1'.
* APPEND ITEM_DATA.
* CLEAR ITEM_DATA.
*
* if alv_out-TOTAL_AMOUNT = 0.
* PERIOD_DATA-ITEM_NUM = x.
* PERIOD_DATA-BUDGETING_PERIOD = alv_out-BUDGETING_PERIOD.
* PERIOD_DATA-PERIOD_AMOUNT = alv_out-PERIOD_AMOUNT.
* APPEND PERIOD_DATA.
* CLEAR PERIOD_DATA.
* endif.
*
* endloop.
CALL FUNCTION 'FMKU_0050_CREATE_WITH_COMMIT'
EXPORTING
* LANGUAGE =
HEADER_DATA = HEADER_DATA
* HEADER_DATA_ADD =
TESTRUN = ''
IMPORTING
FMAREA = FMAREA
DOCUMENTYEAR = DOCUMENTYEAR
DOCUMENTNUMBER = DOCUMENTNUMBER
TABLES
ITEM_DATA = ITEM_DATA
* SENDER_ITEM_DATA =
PERIOD_DATA = PERIOD_DATA
* SENDER_PERIOD_DATA =
* LONG_TEXT =
* EXTENSION_IN =
RETURN = RETURN
.
IF return[] IS NOT INITIAL.
LOOP AT return.
IF return-type = 'E'.
err = 'X'.
ENDIF.
MESSAGE return-message TYPE 'I'.
ENDLOOP.
ENDIF.
IF err = 'X' .
ROLLBACK WORK .
EXIT.
else.
LOOP AT alv_out.
alv_out-state = '@08@'.
alv_out-state_txt = '已生成预算凭证'.
alv_out-belnr = DOCUMENTNUMBER.
modify alv_out.
CLEAR alv_out.
ENDLOOP.
CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE'
EXPORTING
functioncode = 'FLUSH'.
ENDIF.
ENDFORM. \" POST
*&---------------------------------------------------------------------*
*& Form SUB_GET_MAX_COL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TABLE text
* -->P_MAX_COL text
*----------------------------------------------------------------------*
FORM SUB_GET_MAX_COL USING P_TABLE TYPE STANDARD TABLE
CHANGING P_MAX_COL.
DATA: LO_ABAP_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR
LO_ABAP_STRUCTDESCR TYPE REF TO CL_ABAP_STRUCTDESCR.
DATA LS_ABAP_COMPDESCR TYPE ABAP_COMPDESCR.
DATA L_LINES TYPE I.
LO_ABAP_TABLEDESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( P_TABLE ).
LO_ABAP_STRUCTDESCR ?= LO_ABAP_TABLEDESCR->GET_TABLE_LINE_TYPE( ).
DESCRIBE TABLE LO_ABAP_STRUCTDESCR->COMPONENTS LINES L_LINES.
P_MAX_COL = L_LINES .
ENDFORM. \" SUB_GET_MAX_COL
*&---------------------------------------------------------------------*
*& Form SUB_IMPORT_XLS_TO_ITAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TABLE text
* -->P_TAB_WA text
* -->P_FPATCH text
*----------------------------------------------------------------------*
FORM SUB_IMPORT_XLS_TO_ITAB TABLES P_TABLE
USING P_TAB_WA
P_FPATCH.
DATA LT_XLS TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA L_ITAB_COL TYPE I.
FIELD-SYMBOLS IF P_FPATCH IS NOT INITIAL. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING FILENAME = P_FPATCH I_BEGIN_COL = 1 I_BEGIN_ROW = 2 I_END_COL = G_MAX_COL I_END_ROW = 65535 TABLES INTERN = LT_XLS EXCEPTIONS INCONSISTENT_PARAMETERS = 1 UPLOAD_OLE = 2 OTHERS = 3. IF SY-SUBRC <> 0. MESSAGE '上传文件失败!' TYPE 'S' DISPLAY LIKE 'E'. STOP. ELSE. LOOP AT LT_XLS. L_ITAB_COL = LT_XLS-COL. ASSIGN COMPONENT L_ITAB_COL OF STRUCTURE P_TAB_WA TO AT END OF ROW. APPEND P_TAB_WA TO P_TABLE. CLEAR: L_ITAB_COL P_TAB_WA. ENDAT. CLEAR LT_XLS. ENDLOOP. ENDIF. ENDIF. ENDFORM. \" SUB_IMPORT_XLS_TO_ITAB 因篇幅问题不能全部显示,请点此查看更多更全内容