前一段时间花了几天重新设计了一下银行对账功能,其中用到了 abap 的 OO 事件处理方法,及alv 的一些用法和大家分享一下,这次的修改更贴合实际业务操作.
doc 档下载: http://fangkailove.download.csdn.net/银行对账功能-开发.doc
银行对账功能:
功能简价:基本功能,导入银行对账单,企业明细账和银行明细账核对,打印余额调节表.
增加了一些辅助功能:对于第一次对账的科目允许单边确认,对账过程中调整银行对账单等...
基本操作流程:
开发设计:
1.数据模型
程序源代码(不包含屏幕的设计)
*&------------------------------------------------------------------
*& PROGRAM NAME: Z_FI_ENH_003_V2 ( old name : Z_FI_ENH_003)
*& T-CODE: (ZFIE003)
*& PORGRAM TYPE: REPORT
*& DESCRIPTION: 银行对帐功能
*&------------------------------------------------------------------
*& AUTHOR: LONGXU
*& EMAIL: [email protected]
*& DATE: 2009.03.12
*&------------------------------------------------------------------
*&
*&-------------------------------------------------------------------
*& Modification Log:
*& Version Date Author DESCRIPTION CHANGE REQUEST
*& -------- ---------- ----------- ------------- -----------------
*& V1.0 2008.3.15 longxu 初始设计
*& V1.1 2008.4.14 longxu 增加打印余调节表功能
*& V1.2 2008.4.23 longxu 修改自动对账逻辑( 按 票号 金额 全等 且不能为空 ).
*& V2.0 2009.3.12 longxu 重构功能并从命名 Z_FI_ENH_003_V2
*&
*&-------------------------------------------------------------------
*& REFRENCE OBJECT :
*& NAME TYPE DESC
*& --------------------- ----------------- -----------------------
*& ZFIE003_ACT table 对账事务表
*& ZFIE003_BKDOC table 银行对账单明细账
*& ZFIE003_EMAT table 银行对账单已匹配
*& ZFIE003_BMAT table 企业明细账已匹配
*& ZFIE003_ENMAT table 银行对账单未匹配
*& ZFIE003_BNMAT table 企业明细账未匹配
*& ZFIE003_ACTNO 号码对象 对账事务号
*& ZFIE003_DOCNO 号码对象 银行对账单行项号
*& ZFIE003_MATNO 号码对象 对账匹配确认号
*& ZFIE003_S_NMAT structure 余额调节表结构
*& ZFIE003_SM_NMAT smartforms 余额调节表报表
*&
*&-------------------------------------------------------------------
Report Z_FI_ENH_003_V2.
* ALV
TYPE-POOLS: slis.
CONSTANTS startDate type D VALUE '20090101'.
TABLES:ZFIE003_ENMAT,ZFIE003_BNMAT,ZFIE003_ACT,ZFIE003_BKDOC,ZFIE003_EMAT,ZFIE003_BMAT,SKB1,BSIS.
*Select Screen
PARAMETERS: p_BUKRS LIKE ZFIE003_ACT-BUKRS OBLIGATORY MEMORY ID buk ," CHAR 4 0 公司代码
p_SAKNR LIKE ZFIE003_ACT-SAKNR OBLIGATORY. " CHAR 10 0 总帐科目编号
"###############################
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA:i_ZFIE003_ACT LIKE TABLE OF ZFIE003_ACT WITH HEADER LINE.
DATA:wa_CurrentAct LIKE LINE OF i_ZFIE003_ACT.
DATA:wa_PreAct LIKE LINE OF i_ZFIE003_ACT.
DATA:i_ZFIE003_BKDOC LIKE TABLE OF ZFIE003_BKDOC WITH HEADER LINE.
"=======================
"Screen 150 variable
"=======================
DATA:FCODE_150 LIKE SY-UCOMM.
data: grid_150_1 type ref to cl_gui_alv_grid,
con_150_1 type ref to cl_gui_custom_container.
"=============================================================
"=======================
"Screen 250 varialbe
"=======================
DATA:FCODE_250 LIKE SY-UCOMM.
data: grid_250_1 type ref to cl_gui_alv_grid,
grid_250_2 type ref to cl_gui_alv_grid,
con_250_1 type ref to cl_gui_custom_container.
DATA splitter TYPE REF TO cl_gui_splitter_container.
DATA container_1 TYPE REF TO cl_gui_container.
DATA container_2 TYPE REF TO cl_gui_container.
DATA: TBX_250_1 type P DECIMALS 2,
TBX_250_2 TYPE P DECIMALS 2.
"=============================================================
data event_receiver type ref to lcl_event_receiver.
DATA: BEGIN OF I_BSIS OCCURS 0 .
INCLUDE STRUCTURE bsis.
DATA: SELEC(1),
END OF I_BSIS.
DATA:BEGIN OF I_EMAT OCCURS 0,
MATNO LIKE ZFIE003_EMAT-MATNO,
ACTNO LIKE ZFIE003_EMAT-ACTNO,
BUKRS LIKE ZFIE003_EMAT-BUKRS,
GJAHR LIKE ZFIE003_EMAT-GJAHR,
BELNR LIKE ZFIE003_EMAT-BELNR,
BUZEI LIKE ZFIE003_EMAT-BUZEI,
MONAT LIKE BSIS-MONAT,
BLDAT LIKE BSIS-BLDAT,
BUDAT LIKE BSIS-BUDAT,
SHKZG LIKE BSIS-SHKZG,
DMBTR LIKE BSIS-DMBTR,
WAERS LIKE BSIS-WAERS,
WRBTR LIKE BSIS-WRBTR,
SGTXT LIKE BSIS-SGTXT,
ZUONR LIKE BSIS-ZUONR,
SELEC LIKE ZFIE003_BKDOC-SELEC,
END OF I_EMAT.
DATA:BEGIN OF I_BMAT OCCURS 0,
MATNO LIKE ZFIE003_BMAT-MATNO,
ACTNO LIKE ZFIE003_BMAT-ACTNO,
DOCNO LIKE ZFIE003_BMAT-DOCNO,
BLDAT LIKE ZFIE003_BKDOC-BLDAT,
SHKZG LIKE ZFIE003_BKDOC-SHKZG,
DMBTR LIKE ZFIE003_BKDOC-DMBTR,
BALAC LIKE ZFIE003_BKDOC-BALAC,
WAERS LIKE ZFIE003_BKDOC-WAERS,
BKITM LIKE ZFIE003_BKDOC-BKITM,
PINFO LIKE ZFIE003_BKDOC-PINFO,
SDOCNO LIKE ZFIE003_BKDOC-SDOCNO,
SELEC LIKE ZFIE003_BKDOC-SELEC,
END OF I_BMAT.
"$ Region Class Definition and implementation
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_event_receiver: local class to
* define and handle own functions.
*
* Definition:
* ~~~~~~~~~~~
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
CLASS-METHODS grid_250_1_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
CLASS-METHODS grid_250_1_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
CLASS-METHODS grid_250_2_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
CLASS-METHODS grid_250_2_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
CLASS-METHODS handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid
IMPORTING e_object e_ucomm.
CLASS-METHODS handle_user_after_user_command FOR EVENT after_user_command OF cl_gui_alv_grid.
CLASS-METHODS handle_user_befor_user_command FOR EVENT before_user_command OF cl_gui_alv_grid.
CLASS-METHODS Handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
PRIVATE SECTION.
ENDCLASS.
*
* lcl_event_receiver (Definition)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class lcl_event_receiver (Implementation)
*
*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD grid_250_1_toolbar.
data:gs_toolbar TYPE stb_button.
data:icount type i.
IF wa_CurrentAct-EDDAT <> '00000000'.
"MESSAGE '当前事务已经被关账过,不可再修改!' type 'E'.
EXIT.
ENDIF.
DESCRIBE TABLE i_ZFIE003_ACT LINES icount.
IF icount > 1.
"MESSAGE '当前不是第一次对账,不能无条件单边确认' type 'E'.
EXIT.
ENDIF.
CLEAR gs_toolbar.
MOVE 'IniMat' TO gs_toolbar-function.
MOVE ICON_TRANSPORT TO gs_toolbar-icon.
MOVE '无条件企业单边确认'(200) TO gs_toolbar-quickinfo.
MOVE space TO gs_toolbar-disabled.
APPEND gs_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD grid_250_1_user_command.
CASE e_ucomm.
WHEN 'IniMat'.
data: f_MATNO like ZFIE003_EMAT-MATNO.
data: wa_BSIS LIKE LINE OF I_BSIS.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '01'
OBJECT = 'ZSN_MATNO'
QUANTITY = '1'
IMPORTING
NUMBER = f_MATNO
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
MESSAGE '取对账成功确认号错误!' type 'E'.
EXIT.
ENDIF.
LOOP AT I_BSIS INTO wa_BSIS WHERE SELEC = 'X'.
ZFIE003_EMAT-MATNO = f_MATNO.
ZFIE003_EMAT-ACTNO = wa_CurrentAct-ACTNO.
ZFIE003_EMAT-BUKRS = wa_BSIS-BUKRS.
ZFIE003_EMAT-GJAHR = wa_BSIS-GJAHR.
ZFIE003_EMAT-BELNR = wa_BSIS-BELNR.
ZFIE003_EMAT-BUZEI = wa_BSIS-BUZEI.
INSERT INTO ZFIE003_EMAT VALUES ZFIE003_EMAT .
ENDLOOP.
IF sy-subrc <> 0.
ROLLBACK WORK.
exit.
else.
COMMIT WORK.
PERFORM GetBsisFromDb.
clear tbx_250_1.
CALL METHOD grid_250_1->refresh_table_display.
ENDIF.
ENDCASE.
ENDMETHOD.
METHOD grid_250_2_toolbar.
** § 2.At event TOOLBAR define a toolbar element of type 1 by using
** event paramenter E_OBJECT. Remember its function code.
**.......
** Part I: Define a menu button including a function code that
** is evaluated in 'handle_MENU_BUTTON
**.......
*
*
** append a separator to normal toolbar
* CLEAR gs_toolbar.
* MOVE 3 TO gs_toolbar-butn_type.
* APPEND gs_toolbar TO e_object->mt_toolbar.
*
**...................
** append a menu with default button (Type 1)
** The function code of the default button is the same as
** the one for the menu.
** If the user klicks on the default button ALV raises
** directly event BEFORE_USER_COMMAND
** (then USER_COMMAND, AFTER_USER_COMMAND).
** If the user klicks on the menu button ALV raises event MENU_BUTTON.
*
data:gs_toolbar TYPE stb_button.
IF wa_CurrentAct-EDDAT <> '00000000'.
"MESSAGE '当前事务已经被关账过,不可再修改!' type 'E'.
EXIT.
ENDIF.
CLEAR gs_toolbar.
MOVE 'DELETE' TO gs_toolbar-function.
* --> This function code is evaluated in 'handle_menu_button'
MOVE ICON_DELETE_ROW TO gs_toolbar-icon.
MOVE '删除选取中行'(200) TO gs_toolbar-quickinfo.
"MOVE 1 TO gs_toolbar-butn_type.
MOVE space TO gs_toolbar-disabled.
APPEND gs_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD grid_250_2_user_command.
CASE e_ucomm.
WHEN 'DELETE'.
data: wa_ZFIE003_BKDOC like LINE OF i_ZFIE003_BKDOC.
LOOP AT i_ZFIE003_BKDOC INTO wa_ZFIE003_BKDOC.
IF wa_ZFIE003_BKDOC-selec = 'X'.
DELETE FROM ZFIE003_BKDOC where docno = wa_ZFIE003_BKDOC-DocNO.
"delete TABLE i_ZFIE003_BKDOC FROM wa_ZFIE003_BKDOC.
ENDIF.
ENDLOOP.
PERFORM GetBKDocFromDb.
clear tbx_250_2.
CALL METHOD grid_250_2->refresh_table_display.
ENDCASE.
ENDMETHOD. "grid_250_2_user_command
*--------------------------------------------------------------------
METHOD handle_user_after_user_command .
"BREAK-POINT.
ENDMETHOD.
METHOD handle_user_befor_user_command .
"BREAK-POINT.
ENDMETHOD.
METHOD handle_menu_button.
** § 3.At event MENU_BUTTON query your function code and define a
** menu in the same way as a context menu.
**..........
** Part II: Evaluate 'e_ucomm' to see which menu button of the toolbar
** has been clicked on.
** Define then the corresponding menu.
** The menu contains function codes that are evaluated
** in 'grid_250_2_user_command'.
**...........
*
** query e_ucomm to find out which menu button has been clicked on
* IF e_ucomm = 'TO_SFLIGHT'.
* CALL METHOD e_object->add_function
* EXPORTING fcode = 'TO_SPFLI'
* text = text-100. "Overview
** § 3a.) choose a default function and define the same function code
** as used for the menu.
* CALL METHOD e_object->add_function
* EXPORTING fcode = 'TO_SFLIGHT'
* text = text-200. "Flights
*
* ENDIF.
ENDMETHOD.
METHOD handle_data_changed.
"BREAK-POINT.
ENDMETHOD.
*---------------------------------------------------------------------
ENDCLASS.
*
* lcl_event_receiver (Implementation)
*===================================================================
"$ Endregion Class Definition and implementation
"$ Region Main proc
START-OF-SELECTION.
IF sy-UNAME = 'HS014'.
data: clear(5).
"重新初始化对账系统可以进入调试模式 将 clear 值设为 'HS014'.
BREAK-POINT.
IF clear = 'HS014'.
PERFORM ClearAllUserTableData.
ENDIF.
ENDIF.
SELECT SINGLE * FROM SKB1 WHERE BUKRS = p_BUKRS AND SAKNR = p_SAKNR .
IF sy-subrc <> 0.
MESSAGE '科目不存在!' type 'I'.
else.
call screen '0150'.
ENDIF.
"$ Endregion Main proc
"###############################
FORM ClearAllUserTableData.
*& ZFIE003_ACT table 对账事务表
delete from ZFIE003_ACT.
*& ZFIE003_BKDOC table 银行对账单明细账
delete from ZFIE003_BKDOC.
*& ZFIE003_EMAT table 银行对账单已匹配
delete from ZFIE003_EMAT.
*& ZFIE003_BMAT table 企业明细账已匹配
delete from ZFIE003_BMAT.
*& ZFIE003_ENMAT table 银行对账单未匹配
delete from ZFIE003_ENMAT.
*& ZFIE003_BNMAT table 企业明细账未匹配
delete from ZFIE003_BNMAT.
ENDFORM.
"###############################
"$ region screen 150
*********************************************
FORM S150_ALV_INI.
data: gt_fieldcat type lvc_t_fcat.
data: gs_layout type lvc_s_layo.
data: gs_variant type disvariant.
if con_150_1 is initial.
create object con_150_1
exporting container_name = 'CON_150_1'.
create object grid_150_1
exporting
i_parent = con_150_1.
endif.
"定义grid格式
clear gs_layout.
gs_layout-smalltitle = ''.
gs_layout-grid_title = ''.
gs_layout-detailtitl = '细节信息'(003).
gs_layout-zebra = 'X'."定义GRID的样式如斑马条式
gs_layout-sel_mode = 'B'.
gs_layout-cwidth_opt = 'X'.
gs_layout-no_toolbar = ''.
"gs_layout-BOX_FNAME = 'MARK'.
"定义列
DATA: ls_fieldcat like line of gt_fieldcat.
CLEAR gt_fieldcat[].
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ACTNO'.
ls_fieldcat-coltext = 'ID'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUKRS'.
ls_fieldcat-coltext = '公司代码'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SAKNR'.
ls_fieldcat-coltext = '总帐科目编号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'STEXT'.
ls_fieldcat-coltext = '科目描述'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BEDAT'.
ls_fieldcat-coltext = '开启事务时间'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'EDDAT'.
ls_fieldcat-coltext = '结束事务时间'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUDAT'.
ls_fieldcat-coltext = '对账截止日期'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ETBLC'.
ls_fieldcat-coltext = '企业余额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BKBLC'.
ls_fieldcat-coltext = '银行余额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS'.
ls_fieldcat-coltext = '科目币别'.
APPEND ls_fieldcat TO gt_fieldcat.
gs_variant-report = sy-repid. "指定保存变式的程序名.
call method grid_150_1->set_table_for_first_display
exporting
is_variant = gs_variant
is_layout = gs_layout"采用自定义的格式
I_SAVE = 'A'
I_DEFAULT = 'X'
changing
it_outtab = i_ZFIE003_ACT[]
it_fieldcatalog = gt_fieldcat[].
ENDFORM.
FORM UpdateCurrentActToDB.
UPDATE ZFIE003_ACT
SET BUDAT = wa_CurrentAct-BUDAT
EDDAT = wa_CurrentAct-EDDAT
ETBLC = wa_CurrentAct-ETBLC
BKBLC = wa_CurrentAct-BKBLC
WHERE ACTNO = wa_CurrentAct-ACTNO.
ENDFORM.
FORM GetActorFromDB.
SELECT * INTO TABLE I_ZFIE003_ACT FROM ZFIE003_ACT WHERE BUKRS = p_BUKRS AND SAKNR = p_SAKNR.
ENDFORM.
FORM CreateActor.
"DATA: FACTNO LIKE I_ZFIE003_ACT-ACTNO.
SELECT SINGLE * FROM ZFIE003_ACT WHERE BUKRS = p_BUKRS AND SAKNR = p_SAKNR AND EDDAT = '00000000'.
IF sy-subrc = 0.
MESSAGE '科目已开启了一个对账事务' type 'E'.
exit.
ENDIF.
data: l_answer.
CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
defaultoption = 'N'
diagnosetext1 = '开启一个新的对账事物,'
textline1 = '确定继续?'
titel = '询问'
IMPORTING
answer = l_answer.
IF l_answer <> 'J'.
EXIT.
ENDIF.
CLEAR wa_CurrentAct.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '01'
OBJECT = 'ZSN_ACTNO'
QUANTITY = '1'
IMPORTING
NUMBER = wa_CurrentAct-ACTNO
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
MESSAGE '取对账事务号错误!' type 'E'.
EXIT.
ENDIF.
wa_CurrentAct-BUKRS = p_BUKRS.
wa_CurrentAct-SAKNR = p_SAKNR.
wa_CurrentAct-BUDAT = sy-datum.
wa_CurrentAct-BEDAT = sy-datum.
wa_CurrentAct-WAERS = SKB1-WAERS.
select SINGLE TXT50 INTO wa_CurrentAct-STEXT from skat inner join t001 on t001~BUKRS = p_BUKRS and t001~KTOPL = skat~KTOPL where SAKNR = p_SAKNR AND skat~SPRAS = '1'.
SELECT SINGLE * FROM SKB1 WHERE BUKRS = p_BUKRS AND SAKNR = p_SAKNR .
PERFORM GetAccountBalance USING wa_CurrentAct-bukrs
wa_CurrentAct-SAKNR
wa_CurrentAct-BUDAT
wa_CurrentAct-WAERS
CHANGING wa_CurrentAct-ETBLC.
MOVE wa_CurrentAct to ZFIE003_ACT.
INSERT ZFIE003_ACT.
IF SY-SUBRC NE 0.
ROLLBACK work.
else.
commit work.
ENDIF.
"todo 将上期未匹配数据 copy 到本次银行对账明细表中....
DATA: preActNo like ZFIE003_ACT-ACTNO.
data: lc type i.
preActNo = 0.
DESCRIBE TABLE i_ZFIE003_ACT lines lc.
IF lc > 0.
LOOP AT i_ZFIE003_ACT.
IF preActNo < i_ZFIE003_ACT-ACTNO .
preActNo = i_ZFIE003_ACT-ACTNO .
ENDIF.
ENDLOOP.
ENDIF.
CLEAR I_ZFIE003_BKDOC[].
IF preActNo > 0.
SELECT
*
INTO CORRESPONDING FIELDS OF TABLE I_ZFIE003_BKDOC
FROM ZFIE003_BKDOC
INNER JOIN ZFIE003_BNMAT ON ZFIE003_BKDOC~DOCNO = ZFIE003_BNMAT~DOCNO
WHERE ZFIE003_BKDOC~ACTNO = preActNo.
IF sy-subrc = 0.
LOOP AT I_ZFIE003_BKDOC.
I_ZFIE003_BKDOC-ACTNO = wa_CurrentAct-ACTNO.
"取序号码
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '01'
OBJECT = 'ZSN_DOCNO'
QUANTITY = '1'
IMPORTING
NUMBER = I_ZFIE003_BKDOC-DOCNO
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
MESSAGE '取银行对账行号码错误!' type 'I'.
EXIT.
ENDIF.
INSERT INTO ZFIE003_BKDOC VALUES I_ZFIE003_BKDOC.
ENDLOOP.
ENDIF.
ENDIF.
IF SY-SUBRC NE 0.
ROLLBACK work.
else.
commit work.
ENDIF.
ENDFORM.
FORM OpenActor.
DATA:gi_index_rows TYPE lvc_t_row WITH HEADER LINE.
DATA:l_lines type i.
CALL METHOD grid_150_1->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows[].
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
MESSAGE '请选中一个对账事务!' type 'E'.
EXIT.
ENDIF.
CLEAR wa_CurrentAct .
READ TABLE gi_index_rows INDEX 1.
READ TABLE I_ZFIE003_ACT INDEX gi_index_rows-index into wa_CurrentAct .
PERFORM GetBKDocFromDb.
PERFORM GetBsisFromDb.
IF wa_CurrentAct-EDDAT = '00000000'. "没结账前更新余额.
PERFORM GetAccountBalance USING wa_CurrentAct-bukrs
wa_CurrentAct-SAKNR
wa_CurrentAct-BUDAT
wa_CurrentAct-WAERS
CHANGING wa_CurrentAct-ETBLC.
PERFORM UpdateCurrentActToDB.
ENDIF.
ENDFORM.
FORM GetAccountBalance USING bukrs like i_ZFIE003_ACT-BUKRS
saknr like i_ZFIE003_ACT-SAKNR
budat like i_ZFIE003_ACT-BUDAT
WAERS like i_ZFIE003_ACT-WAERS
CHANGING rlt like i_ZFIE003_ACT-ETBLC.
DATA: i_ACCOUNT_BALANCES LIKE BAPI3006_4 OCCURS 0.
DATA: i_line LIKE LINE OF i_ACCOUNT_BALANCES.
DATA: i_bsis like bsis OCCURS 0 WITH HEADER LINE.
DATA: CURR LIKE BAPI3006_5-CURR_TYPE.
DATA: count type i.
*
*
* CALL FUNCTION 'BAPI_GL_ACC_GETPERIODBALANCES'
* EXPORTING
*
* COMPANYCODE = bukrs
* GLACCT = saknr
* FISCALYEAR = budat(4)
* CURRENCYTYPE = '00'
* TABLES
* ACCOUNT_BALANCES = i_ACCOUNT_BALANCES.
*
* DESCRIBE TABLE i_ACCOUNT_BALANCES LINES count.
*
* IF count = 0.
* CALL FUNCTION 'BAPI_GL_ACC_GETPERIODBALANCES'
* EXPORTING
*
* COMPANYCODE = bukrs
* GLACCT = saknr
* FISCALYEAR = budat(4)
* CURRENCYTYPE = '10'
* TABLES
* ACCOUNT_BALANCES = i_ACCOUNT_BALANCES.
* ENDIF.
*
*
* READ TABLE i_ACCOUNT_BALANCES INDEX budat+4(2) INTO i_line .
*
* IF sy-subrc <> 0.
* exit.
* ENDIF.
*
* rlt = i_line-BALANCE.
DATA: SPSWBT like bsis-PSWBT,
HPSWBT LIKE bsis-PSWBT.
IF WAERS = 'RMB'.
select sum( dmbtr ) into SPSWBT FROM bsis where bsis~bukrs = bukrs and bsis~HKONT = SAKNR and bsis~budat <= budat and bsis~SHKZG = 'S'.
select sum( dmbtr ) into HPSWBT FROM bsis where bsis~bukrs = bukrs and bsis~HKONT = SAKNR and bsis~budat <= budat and bsis~SHKZG = 'H'.
ELSE.
select sum( wrbtr ) into SPSWBT FROM bsis where bsis~bukrs = bukrs and bsis~HKONT = SAKNR and bsis~budat <= budat and bsis~SHKZG = 'S'.
select sum( wrbtr ) into HPSWBT FROM bsis where bsis~bukrs = bukrs and bsis~HKONT = SAKNR and bsis~budat <= budat and bsis~SHKZG = 'H'.
ENDIF.
* LOOP AT i_bsis.
* IF i_bsis-SHKZG = 'S'.
* rlt = rlt - i_bsis-PSWBT .
* ELSE.
* rlt = rlt + i_bsis-PSWBT .
* ENDIF.
* ENDLOOP.
rlt = SPSWBT - HPSWBT .
ENDFORM.
DATA: f_bsis like bsis." OCCURS 0 WITH HEADER LINE.
FORM LOOP_OUTPUT.
MOVE-CORRESPONDING f_bsis to I_BSIS.
IF I_BSIS-SHKZG = 'H'.
I_BSIS-dmbtr = - I_BSIS-dmbtr.
I_BSIS-wrbtr = - I_BSIS-wrbtr.
modify table I_BSIS.
ENDIF.
APPEND I_BSIS.
ENDFORM.
FORM GetBsisFromDb.
CLEAR I_BSIS[].
IF wa_CurrentAct-EDDAT = '00000000'. "没结账前从bsis取数
"对当前表检索出不存于另一表的数据 , 用open sql 效率较低,采用 native sql (oracle)
EXEC SQL PERFORMING LOOP_OUTPUT.
SELECT *
INTO :f_bsis
FROM BSIS
WHERE bsis.bukrs = :wa_CurrentAct-bukrs
and bsis.HKONT = :wa_CurrentAct-SAKNR
and bsis.budat <= :wa_CurrentAct-budat
and bsis.budat >= :startDate
and bsis.MANDT = :SY-MANDT
and NOT EXISTS (select *
from ZFIE003_EMAT
where ZFIE003_EMAT.BUKRS = bsis.bukrs
and ZFIE003_EMAT.GJAHR = bsis.GJAHR
and ZFIE003_EMAT.BELNR = bsis.BELNR
and ZFIE003_EMAT.BUZEI = bsis.BUZEI
and ZFIE003_EMAT.MANDT = :SY-MANDT )
ENDEXEC.
ELSE. " 关账后只取未核对数据表 zfie003_enmat
"BREAK-POINT.
EXEC SQL PERFORMING LOOP_OUTPUT.
SELECT
bsis.*
INTO :f_bsis
FROM BSIS
INNER JOIN ZFIE003_ENMAT ON ZFIE003_ENMAT.BUKRS = bsis.bukrs
and ZFIE003_ENMAT.GJAHR = bsis.GJAHR
and ZFIE003_ENMAT.BELNR = bsis.BELNR
and ZFIE003_ENMAT.BUZEI = bsis.BUZEI
and ZFIE003_ENMAT.MANDT = bsis.MANDT
and ZFIE003_ENMAT.ACTNO = :wa_CurrentAct-ActNO
and bsis.MANDT = :SY-MANDT
ENDEXEC.
ENDIF.
ENDFORM.
"DATA: f_bsis like bsis." OCCURS 0 WITH HEADER LINE.
FORM LOOP_BKDOC.
APPEND I_ZFIE003_BKDOC.
ENDFORM.
FORM GetBKDocFromDb.
CLEAR I_ZFIE003_BKDOC[].
"对当前表检索出不存于另一表的数据 , 用open sql 效率较低,采用 native sql (oracle)
EXEC SQL PERFORMING LOOP_BKDOC.
SELECT *
INTO :I_ZFIE003_BKDOC
FROM ZFIE003_BKDOC
WHERE ZFIE003_BKDOC.ACTNO = :wa_CurrentAct-ACTNO
and ZFIE003_BKDOC.MANDT = :SY-MANDT
and NOT EXISTS (select *
from ZFIE003_BMAT
where ZFIE003_BMAT.ACTNO = :wa_CurrentAct-ACTNO
and ZFIE003_BMAT.DOCNO = ZFIE003_BKDOC.DOCNO
and ZFIE003_BMAT.MANDT = :SY-MANDT )
ENDEXEC.
ENDFORM.
"PROCESS BEFORE OUTPUT.
MODULE STATUS_0150 OUTPUT.
set pf-status 'G150'.
set TITLEBAR 'T150'.
PERFORM GetActorFromDB .
PERFORM S150_ALV_INI.
ENDMODULE.
"PROCESS AFTER INPUT.
MODULE USER_COMMAND_0150 INPUT.
" BREAK-POINT.
case FCODE_150.
when 'BACK'.
Clear FCODE_150.
LEAVE to screen 0 .
when 'EXIT'.
Clear FCODE_150.
LEAVE PROGRAM.
when 'CANCEL'.
Clear FCODE_150.
leave to screen 0 .
WHEN 'NEW'.
Clear FCODE_150.
PERFORM CreateActor .
PERFORM GetActorFromDB .
CALL METHOD grid_150_1->refresh_table_display.
When 'OPEN'.
"BREAK-POINT.
Clear FCODE_150.
PERFORM OpenActor.
call SCREEN '0250'.
CALL METHOD grid_150_1->refresh_table_display.
endcase.
ENDMODULE.
"$ endregion screen 150.
"###############################
"###############################
"$ Region screen 250
FORM RefreshSelectAmont.
CALL METHOD grid_250_1->check_changed_data.
CALL METHOD grid_250_2->check_changed_data.
TBX_250_1 = 0.
DATA: wa_BSIS LIKE LINE OF I_BSIS,
wa_ZFIE003_BKDOC LIKE LINE OF I_ZFIE003_BKDOC.
IF wa_CurrentAct-WAERS = 'RMB'.
LOOP AT I_BSIS INTO wa_BSIS WHERE SELEC = 'X'.
TBX_250_1 = TBX_250_1 + wa_BSIS-dmbtr.
ENDLOOP.
ELSE.
LOOP AT I_BSIS INTO wa_BSIS WHERE SELEC = 'X'.
TBX_250_1 = TBX_250_1 + wa_BSIS-wrbtr.
ENDLOOP.
ENDIF.
TBX_250_2 = 0.
LOOP AT I_ZFIE003_BKDOC INTO wa_ZFIE003_BKDOC WHERE SELEC = 'X'.
TBX_250_2 = TBX_250_2 + wa_ZFIE003_BKDOC-DMBTR.
ENDLOOP.
ENDFORM.
"检查余额调节表是否平衡。
FORM CheckBalance CHANGING IsOK TYPE C.
DATA: wa_BSIS LIKE LINE OF I_BSIS,
wa_ZFIE003_BKDOC LIKE LINE OF I_ZFIE003_BKDOC.
DATA: b1 type P DECIMALS 2, "企业余额
b2 TYPE P DECIMALS 2. "银行余额
IF wa_CurrentAct-WAERS = 'RMB'.
LOOP AT I_BSIS INTO wa_BSIS .
b1 = b1 + wa_BSIS-dmbtr.
ENDLOOP.
ELSE.
LOOP AT I_BSIS INTO wa_BSIS .
b1 = b1 + wa_BSIS-wrbtr.
ENDLOOP.
ENDIF.
b2 = 0.
LOOP AT I_ZFIE003_BKDOC INTO wa_ZFIE003_BKDOC .
b2 = b2 + wa_ZFIE003_BKDOC-DMBTR.
ENDLOOP.
b1 = b1 + wa_CurrentAct-BKBLC. " 余业余额+企业未达
b2 = b2 + wa_CurrentAct-ETBLC. " 银行余额_银行未达
IsOK = ''.
IF b1 = b2.
IsOK = 'X'.
ENDIF.
ENDFORM.
FORM S250_ALV_INI.
data: gt_fieldcat type lvc_t_fcat.
data: gs_layout type lvc_s_layo.
data: gs_variant type disvariant.
data:gt_toolbar_excluding Type UI_FUNCTIONS.
if con_250_1 is initial.
create object con_250_1
exporting container_name = 'CON_250_1'.
CREATE OBJECT splitter
EXPORTING parent = con_250_1
rows = 1
ALIGN = 15
columns = 2.
CALL METHOD splitter->get_container
EXPORTING row = 1
column = 1
RECEIVING container = container_1.
CALL METHOD splitter->get_container
EXPORTING row = 1
column = 2
RECEIVING container = container_2.
create object grid_250_1
exporting
i_parent = container_1.
create object grid_250_2
exporting
i_parent = container_2.
"$ "$ Region grid1
"定义 gird toolbar
CLEAR gt_toolbar_excluding.
APPEND:
cl_gui_alv_grid=>MC_FC_PRINT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_DRAG_DROP_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_NO_DELETE_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_NO_INSERT_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_TO_OFFICE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_ABC to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CHAIN to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CRBATCH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CRWEB to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_LINEITEMS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_MASTER_DATA to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_MORE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_REPORT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_XINT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_XXL to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CHECK to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_MB_EXPORT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_GRAPH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_HELP to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_HTML to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_INFO to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_PC_FILE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_VIEWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_APPEND_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_COPY to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_COPY_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_CUT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_DELETE_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_MOVE_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_PASTE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_PASTE_NEW_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_REFRESH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_UNDO to gt_toolbar_excluding
.
"定义grid格式
clear gs_layout.
gs_layout-smalltitle = ''.
gs_layout-grid_title = ''.
gs_layout-zebra = 'X'."定义GRID的样式如斑马条式
gs_layout-sel_mode = 'B'.
gs_layout-no_toolbar = ''.
gs_layout-NO_ROWMARK = 'X'.
gs_layout-EDIT_MODE = ''.
"定义列
DATA: ls_fieldcat like line of gt_fieldcat.
CLEAR gt_fieldcat[].
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SELEC'.
ls_fieldcat-coltext = '选择'.
ls_fieldcat-outputlen = 2.
ls_fieldcat-checkbox = 'X'.
"ls_fieldcat-input = 'X'.
ls_fieldcat-edit = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CONCATENATE sy-repid 'left' into gs_variant-report . "指定保存变式的程序名.
call method grid_250_1->set_table_for_first_display
exporting
is_variant = gs_variant
is_layout = gs_layout"采用自定义的格式
it_toolbar_excluding = gt_toolbar_excluding
i_structure_name = 'BSIS'
I_SAVE = 'A'
I_DEFAULT = 'X'
changing
it_outtab = i_bsis[]
it_fieldcatalog = gt_fieldcat[].
.
"$ Endregion grid1
"$ "$ Region grid2
"定义 gird toolbar
CLEAR gt_toolbar_excluding.
APPEND:
cl_gui_alv_grid=>MC_FC_PRINT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_DRAG_DROP_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_NO_DELETE_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_NO_INSERT_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_TO_OFFICE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_ABC to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CHAIN to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CRBATCH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CRWEB to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_LINEITEMS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_MASTER_DATA to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_MORE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_REPORT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_XINT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_XXL to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CHECK to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_MB_EXPORT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_GRAPH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_HELP to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_HTML to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_INFO to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_PC_FILE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_VIEWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_APPEND_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_COPY to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_COPY_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_CUT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_DELETE_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_MOVE_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_PASTE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_PASTE_NEW_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_REFRESH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_UNDO to gt_toolbar_excluding
.
"定义grid格式
clear gs_layout.
gs_layout-smalltitle = ''.
gs_layout-grid_title = ''.
gs_layout-zebra = 'X'."定义GRID的样式如斑马条式
gs_layout-sel_mode = 'B'.
gs_layout-no_toolbar = ''.
gs_layout-NO_ROWMARK = 'X'.
gs_layout-EDIT_MODE = ''.
"定义列
CLEAR gt_fieldcat[].
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SELEC'.
ls_fieldcat-coltext = '选择'.
ls_fieldcat-outputlen = 2.
ls_fieldcat-checkbox = 'X'.
"ls_fieldcat-input = 'X'.
ls_fieldcat-edit = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DOCNO'.
ls_fieldcat-coltext = '行号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ACTNO'.
ls_fieldcat-coltext = '事务ID'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BLDAT'.
ls_fieldcat-coltext = '日期'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SHKZG'.
ls_fieldcat-coltext = '借方/贷方标识'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DMBTR'.
ls_fieldcat-coltext = '发生金额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BALAC'.
ls_fieldcat-coltext = '余额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS'.
ls_fieldcat-coltext = '货币'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BKITM'.
ls_fieldcat-coltext = '传票号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'PINFO'.
ls_fieldcat-coltext = '对方信息'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SDOCNO'.
ls_fieldcat-coltext = '复制行号'.
APPEND ls_fieldcat TO gt_fieldcat.
CONCATENATE sy-repid 'right' into gs_variant-report . "指定保存变式的程序名.
call method grid_250_2->set_table_for_first_display
exporting
is_variant = gs_variant
is_layout = gs_layout"采用自定义的格式
it_toolbar_excluding = gt_toolbar_excluding
I_SAVE = 'A'
I_DEFAULT = 'X'
changing
it_outtab = i_ZFIE003_BKDOC[]
it_fieldcatalog = gt_fieldcat[].
SET HANDLER event_receiver->grid_250_1_user_command
event_receiver->grid_250_1_toolbar FOR grid_250_1 .
CALL METHOD grid_250_1->set_toolbar_interactive.
SET HANDLER event_receiver->grid_250_2_user_command
event_receiver->grid_250_2_toolbar FOR grid_250_2 .
CALL METHOD grid_250_2->set_toolbar_interactive.
"$ Endregion grid2
endif.
IF sy-ucomm = 'OPEN'.
clear tbx_250_1.
clear tbx_250_2.
CALL METHOD grid_250_1->refresh_table_display.
CALL METHOD grid_250_2->refresh_table_display.
* else.
*
* DATA: l_valid(1) TYPE c.
*
* CALL METHOD grid_250_1->check_changed_data
* CHANGING
* c_refresh = l_valid.
* IF l_valid = 'X'.
* CALL METHOD grid_250_1->refresh_table_display.
* ENDIF.
*
* CALL METHOD grid_250_2->check_changed_data
* CHANGING
* c_refresh = l_valid.
* IF l_valid = 'X'.
* CALL METHOD grid_250_2->refresh_table_display.
* ENDIF.
clear sy-ucomm.
ENDIF.
ENDFORM.
*PROCESS BEFORE OUTPUT.
MODULE STATUS_0250 OUTPUT.
set pf-status 'G250'.
set TITLEBAR 'T250'.
PERFORM S250_ALV_INI.
ENDMODULE.
*PROCESS AFTER INPUT.
MODULE USER_COMMAND_0250 INPUT.
"BREAK-POINT.
case FCODE_250.
when 'BACK'.
CLEAR FCODE_250.
LEAVE to screen 0 .
when 'EXIT'.
CLEAR FCODE_250.
LEAVE PROGRAM.
when 'CANCEL'.
CLEAR FCODE_250.
LEAVE to screen 0 .
when 'REFRESH'.
CLEAR FCODE_250.
PERFORM RefreshSelectAmont.
when 'MAT'.
CLEAR FCODE_250.
IF wa_CurrentAct-EDDAT <> '00000000'.
MESSAGE '当前事务已经被关账过,不可再修改!' type 'E'.
EXIT.
ENDIF.
PERFORM RefreshSelectAmont.
IF TBX_250_1 <> TBX_250_2.
MESSAGE '选择的金额不匹配!' type 'E'.
ELSE.
data: f_MATNO like ZFIE003_EMAT-MATNO.
data: wa_BSIS LIKE LINE OF I_BSIS.
data: wa_ZFIE003_BKDOC LIKE LINE OF I_ZFIE003_BKDOC.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '01'
OBJECT = 'ZSN_MATNO'
QUANTITY = '1'
IMPORTING
NUMBER = f_MATNO
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
MESSAGE '取对账成功确认号错误!' type 'E'.
EXIT.
ENDIF.
LOOP AT I_BSIS INTO wa_BSIS WHERE SELEC = 'X'.
ZFIE003_EMAT-MATNO = f_MATNO.
ZFIE003_EMAT-ACTNO = wa_CurrentAct-ACTNO.
ZFIE003_EMAT-BUKRS = wa_BSIS-BUKRS.
ZFIE003_EMAT-GJAHR = wa_BSIS-GJAHR.
ZFIE003_EMAT-BELNR = wa_BSIS-BELNR.
ZFIE003_EMAT-BUZEI = wa_BSIS-BUZEI.
insert ZFIE003_EMAT.
ENDLOOP.
LOOP AT I_ZFIE003_BKDOC INTO wa_ZFIE003_BKDOC.
if wa_ZFIE003_BKDOC-SELEC = 'X'.
ZFIE003_BMAT-MATNO = f_MATNO.
ZFIE003_BMAT-ACTNO = wa_CurrentAct-ACTNO.
ZFIE003_BMAT-DOCNO = wa_ZFIE003_BKDOC-DOCNO.
insert ZFIE003_BMAT.
endif.
ENDLOOP.
IF sy-subrc <> 0.
ROLLBACK WORK.
exit.
else.
COMMIT WORK.
PERFORM GetBsisFromDb.
PERFORM GetBKDocFromDb.
clear tbx_250_1.
clear tbx_250_2.
CALL METHOD grid_250_1->refresh_table_display.
CALL METHOD grid_250_2->refresh_table_display.
ENDIF.
ENDIF.
when 'SMAT'.
CLEAR FCODE_250.
PERFORM GetMatFromDb.
CALL SCREEN '0350'.
PERFORM GetBsisFromDb.
PERFORM GetBKDocFromDb.
CALL METHOD grid_250_1->refresh_table_display.
CALL METHOD grid_250_2->refresh_table_display.
when 'UPL'.
CLEAR FCODE_250.
IF wa_CurrentAct-EDDAT <> '00000000'.
MESSAGE '当前事务已经被关账过,不可再修改!' type 'E'.
EXIT.
ENDIF.
call screen '0010' starting at 30 5 ending at 80 10.
PERFORM GetBKDocFromDb.
clear tbx_250_2.
CALL METHOD grid_250_2->refresh_table_display.
when 'SNMAT'.
CLEAR FCODE_250.
DATA: I_ZFIE003_S_NMAT LIKE ZFIE003_S_NMAT OCCURS 0 WITH HEADER LINE.
DATA: wa_ZFIE003_S_NMAT LIKE LINE OF I_ZFIE003_S_NMAT,
wa2_ZFIE003_S_NMAT LIKE LINE OF I_ZFIE003_S_NMAT.
DATA: ln like ZFIE003_S_NMAT-LINNO,
ln2 like ZFIE003_S_NMAT-LINNO.
ln = 1.
* IF wa_CurrentAct-EDDAT = '00000000'.
* MESSAGE '当前事务未关账,最终打印余额调节表!' type 'W'.
* "EXIT.
* ENDIF.
CLEAR I_ZFIE003_S_NMAT[].
CLEAR wa2_ZFIE003_S_NMAT.
wa2_ZFIE003_S_NMAT-TEXT_A = '调整后(银行存款)余额'.
wa2_ZFIE003_S_NMAT-TEXT_B = '调整后(银行对账单)余额'.
wa2_ZFIE003_S_NMAT-DMBTR_A = wa_CurrentAct-ETBLC.
wa2_ZFIE003_S_NMAT-DMBTR_B = wa_CurrentAct-BKBLC.
CLEAR I_ZFIE003_S_NMAT.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_A = '银行存款日记账余额'.
I_ZFIE003_S_NMAT-BLDAT = wa_CurrentAct-BUDAT.
I_ZFIE003_S_NMAT-DMBTR_A = wa_CurrentAct-ETBLC.
I_ZFIE003_S_NMAT-TEXT_B = '银行对账单余额'.
I_ZFIE003_S_NMAT-BUDAT = wa_CurrentAct-BLDAT.
I_ZFIE003_S_NMAT-DMBTR_B = wa_CurrentAct-BKBLC.
APPEND I_ZFIE003_S_NMAT.
ln = ln + 1.
CLEAR I_ZFIE003_S_NMAT.
CLEAR wa_ZFIE003_S_NMAT.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_A = ' 加:银行已收,企业未收'.
"I_ZFIE003_S_NMAT-BLDAT = ''.
I_ZFIE003_S_NMAT-DMBTR_A = 0.
I_ZFIE003_S_NMAT-TEXT_B = ' 加:企业已收,银行未收'.
"I_ZFIE003_S_NMAT-BUDAT = ''.
I_ZFIE003_S_NMAT-DMBTR_B = 0.
MOVE I_ZFIE003_S_NMAT to wa_ZFIE003_S_NMAT. "暂存,求了汇总后再添加
ln = ln + 1.
ln2 = ln.
LOOP AT I_ZFIE003_BKDOC WHERE SHKZG = 'S'.
CLEAR I_ZFIE003_S_NMAT.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_A = I_ZFIE003_BKDOC-PINFO.
I_ZFIE003_S_NMAT-BLDAT = I_ZFIE003_BKDOC-BLDAT .
I_ZFIE003_S_NMAT-DMBTR_A = I_ZFIE003_BKDOC-DMBTR.
wa_ZFIE003_S_NMAT-DMBTR_A = wa_ZFIE003_S_NMAT-DMBTR_A + I_ZFIE003_S_NMAT-DMBTR_A.
APPEND I_ZFIE003_S_NMAT.
ln = ln + 1.
ENDLOOP.
LOOP AT I_BSIS WHERE SHKZG = 'S'.
CLEAR I_ZFIE003_S_NMAT.
IF ln2 < ln.
READ TABLE I_ZFIE003_S_NMAT with key LINNO = ln2.
"I_ZFIE003_S_NMAT-LINNO = ln2.
I_ZFIE003_S_NMAT-TEXT_B = I_BSIS-SGTXT.
I_ZFIE003_S_NMAT-BUDAT = I_BSIS-BLDAT .
I_ZFIE003_S_NMAT-DMBTR_B = I_BSIS-DMBTR.
I_ZFIE003_S_NMAT-BELNR = I_BSIS-BELNR.
I_ZFIE003_S_NMAT-BUZEI = I_BSIS-BUZEI.
wa_ZFIE003_S_NMAT-DMBTR_B = wa_ZFIE003_S_NMAT-DMBTR_B + I_ZFIE003_S_NMAT-DMBTR_B.
modify I_ZFIE003_S_NMAT TRANSPORTING TEXT_B BUDAT DMBTR_B BELNR BUZEI where LINNO = ln2 .
ln2 = ln2 + 1.
ELSE.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_B = I_BSIS-SGTXT.
I_ZFIE003_S_NMAT-BUDAT = I_BSIS-BLDAT .
I_ZFIE003_S_NMAT-DMBTR_B = I_BSIS-DMBTR.
I_ZFIE003_S_NMAT-BELNR = I_BSIS-BELNR.
I_ZFIE003_S_NMAT-BUZEI = I_BSIS-BUZEI.
wa_ZFIE003_S_NMAT-DMBTR_B = wa_ZFIE003_S_NMAT-DMBTR_B + I_ZFIE003_S_NMAT-DMBTR_B.
APPEND I_ZFIE003_S_NMAT.
ln = ln + 1.
ENDIF.
ENDLOOP.
wa2_ZFIE003_S_NMAT-DMBTR_A = wa2_ZFIE003_S_NMAT-DMBTR_A + wa_ZFIE003_S_NMAT-DMBTR_A.
wa2_ZFIE003_S_NMAT-DMBTR_B = wa2_ZFIE003_S_NMAT-DMBTR_B + wa_ZFIE003_S_NMAT-DMBTR_B.
move wa_ZFIE003_S_NMAT to I_ZFIE003_S_NMAT.
APPEND I_ZFIE003_S_NMAT. "添加汇总行
CLEAR I_ZFIE003_S_NMAT.
CLEAR wa_ZFIE003_S_NMAT.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_A = ' 减:银行已付,企业未付'.
"I_ZFIE003_S_NMAT-BLDAT = ''.
I_ZFIE003_S_NMAT-DMBTR_A = 0.
I_ZFIE003_S_NMAT-TEXT_B = ' 减:企业已付,银行未付'.
"I_ZFIE003_S_NMAT-BUDAT = ''.
I_ZFIE003_S_NMAT-DMBTR_B = 0.
MOVE I_ZFIE003_S_NMAT to wa_ZFIE003_S_NMAT. "暂存,求了汇总后再添加
ln = ln + 1.
ln2 = ln.
LOOP AT I_ZFIE003_BKDOC WHERE SHKZG = 'H'.
CLEAR I_ZFIE003_S_NMAT.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_A = I_ZFIE003_BKDOC-PINFO.
I_ZFIE003_S_NMAT-BLDAT = I_ZFIE003_BKDOC-BLDAT .
I_ZFIE003_S_NMAT-DMBTR_A = I_ZFIE003_BKDOC-DMBTR.
wa_ZFIE003_S_NMAT-DMBTR_A = wa_ZFIE003_S_NMAT-DMBTR_A + I_ZFIE003_S_NMAT-DMBTR_A.
APPEND I_ZFIE003_S_NMAT.
ln = ln + 1.
ENDLOOP.
LOOP AT I_BSIS WHERE SHKZG = 'H'.
CLEAR I_ZFIE003_S_NMAT.
IF ln2 < ln.
READ TABLE I_ZFIE003_S_NMAT with key LINNO = ln2.
"I_ZFIE003_S_NMAT-LINNO = ln2.
I_ZFIE003_S_NMAT-TEXT_B = I_BSIS-SGTXT.
I_ZFIE003_S_NMAT-BUDAT = I_BSIS-BLDAT .
I_ZFIE003_S_NMAT-DMBTR_B = I_BSIS-DMBTR.
I_ZFIE003_S_NMAT-BELNR = I_BSIS-BELNR.
I_ZFIE003_S_NMAT-BUZEI = I_BSIS-BUZEI.
wa_ZFIE003_S_NMAT-DMBTR_B = wa_ZFIE003_S_NMAT-DMBTR_B + I_ZFIE003_S_NMAT-DMBTR_B.
modify I_ZFIE003_S_NMAT TRANSPORTING TEXT_B BUDAT DMBTR_B BELNR BUZEI where LINNO = ln2 .
ln2 = ln2 + 1.
ELSE.
I_ZFIE003_S_NMAT-LINNO = ln.
I_ZFIE003_S_NMAT-TEXT_B = I_BSIS-SGTXT.
I_ZFIE003_S_NMAT-BUDAT = I_BSIS-BLDAT .
I_ZFIE003_S_NMAT-DMBTR_B = I_BSIS-DMBTR.
I_ZFIE003_S_NMAT-BELNR = I_BSIS-BELNR.
I_ZFIE003_S_NMAT-BUZEI = I_BSIS-BUZEI.
wa_ZFIE003_S_NMAT-DMBTR_B = wa_ZFIE003_S_NMAT-DMBTR_B + I_ZFIE003_S_NMAT-DMBTR_B.
APPEND I_ZFIE003_S_NMAT.
ln = ln + 1.
ENDIF.
ENDLOOP.
wa2_ZFIE003_S_NMAT-DMBTR_A = wa2_ZFIE003_S_NMAT-DMBTR_A + wa_ZFIE003_S_NMAT-DMBTR_A.
wa2_ZFIE003_S_NMAT-DMBTR_B = wa2_ZFIE003_S_NMAT-DMBTR_B + wa_ZFIE003_S_NMAT-DMBTR_B.
move wa_ZFIE003_S_NMAT to I_ZFIE003_S_NMAT.
APPEND I_ZFIE003_S_NMAT. "添加汇总行
wa2_ZFIE003_S_NMAT-LINNO = ln .
move wa2_ZFIE003_S_NMAT to I_ZFIE003_S_NMAT.
APPEND I_ZFIE003_S_NMAT. "添加汇总行
sort I_ZFIE003_S_NMAT by LINNO.
data:BUTXT like t001-BUTXT.
select SINGLE BUTXT INTO BUTXT From T001 Where BUKRS = p_BUKRS.
* DATA: FYEAR LIKE BKPF-GJAHR,
* FMONT LIKE BKPF-MONAT,
data: FM_NAME TYPE TDSFNAME.
* FYEAR = p_BLDAT-HIGH+0(4).
* FMONT = p_BLDAT-HIGH+4(2).
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZFIE003_SM_NMAT'
IMPORTING
FM_NAME = FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
CASE SY-SUBRC.
WHEN 0.
CALL FUNCTION FM_NAME
EXPORTING
STEXT = wa_CurrentAct-STEXT
MT = wa_CurrentAct-BUDAT(6)
BUTXT = BUTXT
TABLES
NMAT = I_ZFIE003_S_NMAT
EXCEPTIONS
FORMATTING_ERROR = 1
INTERVAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
MY_EXCEPTION = 5
OTHERS = 6.
WHEN OTHERS.
MESSAGE '窗体调用错误!' type 'E'.
ENDCASE.
when 'FINI'.
CLEAR FCODE_250.
IF wa_CurrentAct-EDDAT <> '00000000'.
MESSAGE '当前事务已经被关账过,不可再关账!' type 'E'.
EXIT.
ENDIF.
Data isok(1).
PERFORM CheckBalance CHANGING isok.
IF isok = ''.
MESSAGE '余额调节表不平,请检查...!' type 'E'.
EXIT.
ENDIF.
data:l_answer .
CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
defaultoption = 'N'
diagnosetext1 = '对当前事务关账,'
textline1 = '确定继续?'
titel = '询问'
IMPORTING
answer = l_answer.
IF l_answer <> 'J'.
EXIT.
ENDIF.
LOOP AT I_BSIS.
CLEAR ZFIE003_ENMAT.
ZFIE003_ENMAT-ACTNO = wa_CurrentAct-ACTNO.
ZFIE003_ENMAT-BUKRS = I_BSIS-BUKRS.
ZFIE003_ENMAT-GJAHR = I_BSIS-GJAHR.
ZFIE003_ENMAT-BELNR = I_BSIS-BELNR.
ZFIE003_ENMAT-BUZEI = I_BSIS-BUZEI.
insert ZFIE003_ENMAT.
ENDLOOP.
LOOP AT I_ZFIE003_BKDOC.
CLEAR ZFIE003_BNMAT.
ZFIE003_BNMAT-ACTNO = wa_CurrentAct-ACTNO.
ZFIE003_BNMAT-DOCNO = I_ZFIE003_BKDOC-DOCNO.
INSERT ZFIE003_BNMAT.
ENDLOOP.
wa_CurrentAct-EDDAT = sy-datum.
PERFORM UpdateCurrentActToDB.
IF sy-subrc = 0.
COMMIT WORK.
else.
ROLLBACK WORK.
ENDIF.
CALL METHOD grid_250_1->refresh_table_display.
CALL METHOD grid_250_2->refresh_table_display.
ENDCASE.
ENDMODULE.
MODULE OnBudatChanged_0250 INPUT .
IF FCODE_250 = 'OK'.
CLEAR FCODE_250.
IF wa_CurrentAct-EDDAT <> '00000000'.
MESSAGE '当前事务已经被关账过,不可再修改!' type 'E'.
EXIT.
ENDIF.
PERFORM GetAccountBalance USING wa_CurrentAct-bukrs
wa_CurrentAct-SAKNR
wa_CurrentAct-BUDAT
wa_CurrentAct-WAERS
CHANGING wa_CurrentAct-ETBLC.
PERFORM GetBsisFromDb.
clear tbx_250_1.
CALL METHOD grid_250_1->refresh_table_display.
TBX_250_1 = 0.
PERFORM UpdateCurrentActToDB.
ENDIF.
ENDMODULE.
"$ Endregion screen 250
"###############################
"###############################
"$ Region screen 0010
DATA:FCODE_010 LIKE SY-UCOMM.
DATA:TXT_FILEPATH TYPE STRING.
FORM UpLoadBankDoc USING fileName TYPE STRING.
data: sign(1) type c.
data: isifr type i value 0,
zname(40) type c,
kawrt_e like konv-kawrt,
g_lfilename type string,
isdel(1) type c.
data: begin of I_BKDOC occurs 0,
BLDAT like ZFIE003_BKDOC-bldat, " 日期
DMBTR1 like ZFIE003_BKDOC-DMBTR, " 借记金额
DMBTR2 like ZFIE003_BKDOC-DMBTR, " 贷记金额
BALAC like ZFIE003_BKDOC-BALAC, " 余额
WAERS like ZFIE003_BKDOC-WAERS, " 货币
BKITM like ZFIE003_BKDOC-BKITM, " 传票号
PINFO like ZFIE003_BKDOC-PINFO, " 对方信息
end of I_BKDOC.
data: wa_ZFIE003_BKDOC LIKE ZFIE003_BKDOC.
call function 'GUI_UPLOAD'
exporting
filename = filename
filetype = 'ASC'
has_field_separator = 'X'
ignore_cerr = abap_false
tables
data_tab = I_BKDOC
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
if sy-subrc <> 0.
message e899(bd) with
'不能打开文件' fileName '.错误代码:' sy-subrc.
EXIT.
ENDIF.
"BREAK-POINT.
LOOP AT I_BKDOC.
MOVE-CORRESPONDING I_BKDOC TO wa_ZFIE003_BKDOC.
"取序号码
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '01'
OBJECT = 'ZSN_DOCNO'
QUANTITY = '1'
IMPORTING
NUMBER = wa_ZFIE003_BKDOC-DOCNO
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
MESSAGE '取银行对账行号码错误!' type 'E'.
EXIT.
ENDIF.
wa_ZFIE003_BKDOC-SDOCNO = wa_ZFIE003_BKDOC-DOCNO.
wa_ZFIE003_BKDOC-ACTNO = wa_CurrentAct-ACTNO.
IF I_BKDOC-DMBTR1 IS INITIAL AND NOT I_BKDOC-DMBTR2 IS INITIAL.
wa_ZFIE003_BKDOC-DMBTR = I_BKDOC-DMBTR2.
wa_ZFIE003_BKDOC-SHKZG = 'S'.
ENDIF.
IF I_BKDOC-DMBTR2 IS INITIAL AND NOT I_BKDOC-DMBTR1 IS INITIAL.
wa_ZFIE003_BKDOC-DMBTR = I_BKDOC-DMBTR1 * ( -1 ).
wa_ZFIE003_BKDOC-SHKZG = 'H'.
ENDIF.
MOVE wa_ZFIE003_BKDOC to ZFIE003_BKDOC.
INSERT ZFIE003_BKDOC.
AT LAST.
wa_CurrentAct-BKBLC = wa_ZFIE003_BKDOC-BALAC.
wa_CurrentAct-BLDAT = wa_ZFIE003_BKDOC-BLDAT.
PERFORM UpdateCurrentActToDB.
ENDAT.
ENDLOOP.
if sy-subrc = 0.
commit work.
free:wa_ZFIE003_BKDOC,ZFIE003_BKDOC,I_BKDOC,I_BKDOC[].
MESSAGE '银行对账单导入成功!' type 'I'.
else.
rollback work.
endif.
endform.
*PROCESS BEFORE OUTPUT.
MODULE STATUS_0010 OUTPUT.
set pf-status 'G010'.
ENDMODULE.
*
*PROCESS AFTER INPUT.
MODULE USER_COMMAND_0010 INPUT.
"BREAK-POINT.
case FCODE_010.
when 'OK'.
PERFORM UpLoadBankDoc USING TXT_FILEPATH.
CLEAR FCODE_010.
LEAVE to screen 0 .
when 'CANCEL'.
CLEAR FCODE_010.
LEAVE to screen 0 .
ENDCASE.
ENDMODULE.
module FilePath_F4_0010 input.
*将本地文件上载到服务器
call function 'WS_FILENAME_GET'
exporting
def_filename = ' '
def_path = ' '
mask = ',*.TXT.'
mode = 'O'
title = '银行对账单导入文件(txt)'
importing
filename = TXT_FILEPATH
exceptions
others = 1.
check sy-subrc is initial.
endmodule. " FilePath_F4 INPUT
"$ Endregion screen 0010
"###############################
"###############################
"$ Region Screen 350
DATA:FCODE_350 like sy-ucomm.
data: grid_350_1 type ref to cl_gui_alv_grid,
grid_350_2 type ref to cl_gui_alv_grid,
con_350_1 type ref to cl_gui_custom_container.
DATA splitter_350 TYPE REF TO cl_gui_splitter_container.
DATA container_350_1 TYPE REF TO cl_gui_container.
DATA container_350_2 TYPE REF TO cl_gui_container.
form GetMatFromDb .
SELECT
ZFIE003_EMAT~MATNO
ZFIE003_EMAT~ACTNO
ZFIE003_EMAT~BUKRS
ZFIE003_EMAT~GJAHR
ZFIE003_EMAT~BELNR
ZFIE003_EMAT~BUZEI
BSIS~MONAT
BSIS~BLDAT
BSIS~BUDAT
BSIS~SHKZG
BSIS~DMBTR
BSIS~WAERS
BSIS~WRBTR
BSIS~SGTXT
BSIS~ZUONR
INTO CORRESPONDING FIELDS OF TABLE I_EMAT
FROM BSIS
INNER JOIN ZFIE003_EMAT ON ZFIE003_EMAT~BUKRS = BSIS~BUKRS
AND ZFIE003_EMAT~GJAHR = BSIS~GJAHR
AND ZFIE003_EMAT~BELNR = BSIS~BELNR
AND ZFIE003_EMAT~BUZEI = BSIS~BUZEI
WHERE ZFIE003_EMAT~ACTNO = wa_CurrentAct-ACTNO.
LOOP AT I_EMAT.
IF I_EMAT-SHKZG = 'H'.
I_EMAT-dmbtr = - I_EMAT-dmbtr.
I_EMAT-wrbtr = - I_EMAT-wrbtr.
modify table I_EMAT.
ENDIF.
ENDLOOP.
SELECT
ZFIE003_BMAT~MATNO
ZFIE003_BMAT~ACTNO
ZFIE003_BMAT~DOCNO
ZFIE003_BKDOC~BLDAT
ZFIE003_BKDOC~SHKZG
ZFIE003_BKDOC~DMBTR
ZFIE003_BKDOC~BALAC
ZFIE003_BKDOC~WAERS
ZFIE003_BKDOC~BKITM
ZFIE003_BKDOC~PINFO
ZFIE003_BKDOC~SDOCNO
ZFIE003_BKDOC~SELEC
INTO CORRESPONDING FIELDS OF TABLE I_BMAT
FROM ZFIE003_BMAT
INNER JOIN ZFIE003_BKDOC ON ZFIE003_BMAT~ACTNO = ZFIE003_BKDOC~ACTNO
AND ZFIE003_BMAT~DOCNO = ZFIE003_BKDOC~DOCNO
WHERE ZFIE003_BMAT~ACTNO = wa_CurrentAct-ACTNO.
endform. " GetMatFromDb
FORM S350_ALV_INI.
data: gt_fieldcat type lvc_t_fcat.
data: gs_layout type lvc_s_layo.
data: gs_variant type disvariant.
data: gt_toolbar_excluding Type UI_FUNCTIONS.
if con_350_1 is initial.
create object con_350_1
exporting container_name = 'CON_350_1'.
CREATE OBJECT splitter_350
EXPORTING parent = con_350_1
rows = 1
columns = 2.
CALL METHOD splitter_350->get_container
EXPORTING row = 1
column = 1
RECEIVING container = container_350_1.
CALL METHOD splitter_350->get_container
EXPORTING row = 1
column = 2
RECEIVING container = container_350_2.
create object grid_350_1
exporting
i_parent = container_350_1.
create object grid_350_2
exporting
i_parent = container_350_2.
CLEAR gt_toolbar_excluding.
APPEND:
cl_gui_alv_grid=>MC_FC_PRINT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_DRAG_DROP_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_NO_DELETE_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_LYSTYLE_NO_INSERT_ROWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_TO_OFFICE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_ABC to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CHAIN to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CRBATCH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_CRWEB to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_LINEITEMS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_MASTER_DATA to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_MORE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_REPORT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_XINT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CALL_XXL to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_CHECK to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_MB_EXPORT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_GRAPH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_HELP to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_HTML to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_INFO to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_PC_FILE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_VIEWS to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_APPEND_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_COPY to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_COPY_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_CUT to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_DELETE_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_MOVE_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_PASTE to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_PASTE_NEW_ROW to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_REFRESH to gt_toolbar_excluding,
cl_gui_alv_grid=>MC_FC_LOC_UNDO to gt_toolbar_excluding
.
"$ "$ Region grid1
"定义grid格式
clear gs_layout.
gs_layout-smalltitle = ''.
gs_layout-grid_title = ''.
gs_layout-zebra = 'X'."定义GRID的样式如斑马条式
gs_layout-sel_mode = 'B'.
gs_layout-no_toolbar = ''.
gs_layout-NO_ROWMARK = 'X'.
gs_layout-EDIT_MODE = ''.
"定义列
DATA: ls_fieldcat like line of gt_fieldcat.
CLEAR gt_fieldcat[].
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SELEC'.
ls_fieldcat-coltext = '选择'.
ls_fieldcat-outputlen = 2.
ls_fieldcat-checkbox = 'X'.
"ls_fieldcat-input = 'X'.
ls_fieldcat-edit = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATNO'.
ls_fieldcat-coltext = '对账号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BELNR'.
ls_fieldcat-coltext = '凭证号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUZEI'.
ls_fieldcat-coltext = '凭证行'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BLDAT'.
ls_fieldcat-coltext = '凭证日期'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
IF wa_CurrentAct-WAERS = 'RMB'.
ls_fieldcat-fieldname = 'DMBTR'.
ELSE.
ls_fieldcat-fieldname = 'WRBTR'.
ENDIF.
ls_fieldcat-coltext = '金额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SGTXT'.
ls_fieldcat-coltext = '文本'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ZUONR'.
ls_fieldcat-coltext = '分配'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ACTNO'.
ls_fieldcat-coltext = '事务号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUKRS'.
ls_fieldcat-coltext = '公司代码'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'GJAHR'.
ls_fieldcat-coltext = '会计年度'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MONAT'.
ls_fieldcat-coltext = '期间'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUDAT'.
ls_fieldcat-coltext = '过账日期'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SHKZG'.
ls_fieldcat-coltext = '借贷标识'.
APPEND ls_fieldcat TO gt_fieldcat.
CONCATENATE sy-repid '350_left' into gs_variant-report . "指定保存变式的程序名.
call method grid_350_1->set_table_for_first_display
exporting
is_variant = gs_variant
is_layout = gs_layout"采用自定义的格式
it_toolbar_excluding = gt_toolbar_excluding
"i_structure_name = 'BSIS'
I_SAVE = 'A'
I_DEFAULT = 'X'
changing
it_outtab = I_EMAT[]
it_fieldcatalog = gt_fieldcat[].
.
"$ Endregion grid1
"$ "$ Region grid2
"定义grid格式
clear gs_layout.
gs_layout-smalltitle = ''.
gs_layout-grid_title = ''.
gs_layout-zebra = 'X'."定义GRID的样式如斑马条式
gs_layout-sel_mode = 'B'.
gs_layout-no_toolbar = ''.
gs_layout-NO_ROWMARK = 'X'.
gs_layout-EDIT_MODE = ''.
"定义列
CLEAR gt_fieldcat[].
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SELEC'.
ls_fieldcat-coltext = '选择'.
ls_fieldcat-outputlen = 2.
ls_fieldcat-checkbox = 'X'.
"ls_fieldcat-input = 'X'.
ls_fieldcat-edit = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATNO'.
ls_fieldcat-coltext = '对账号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BLDAT'.
ls_fieldcat-coltext = '日期'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DMBTR'.
ls_fieldcat-coltext = '发生金额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BKITM'.
ls_fieldcat-coltext = '传票号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'PINFO'.
ls_fieldcat-coltext = '对方信息'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DOCNO'.
ls_fieldcat-coltext = '行号'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ACTNO'.
ls_fieldcat-coltext = '事务ID'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BALAC'.
ls_fieldcat-coltext = '余额'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS'.
ls_fieldcat-coltext = '货币'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SHKZG'.
ls_fieldcat-coltext = '借方/贷方标识'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SDOCNO'.
ls_fieldcat-coltext = '复制行号'.
APPEND ls_fieldcat TO gt_fieldcat.
CONCATENATE sy-repid '350_right' into gs_variant-report . "指定保存变式的程序名.
call method grid_350_2->set_table_for_first_display
exporting
is_variant = gs_variant
is_layout = gs_layout"采用自定义的格式
it_toolbar_excluding = gt_toolbar_excluding
I_SAVE = 'A'
I_DEFAULT = 'X'
changing
it_outtab = I_BMAT[]
it_fieldcatalog = gt_fieldcat[].
"$ Endregion grid2
else.
CALL METHOD grid_350_1->refresh_table_display.
CALL METHOD grid_350_2->refresh_table_display.
endif.
ENDFORM.
"PROCESS BEFORE OUTPUT.
MODULE STATUS_0350 OUTPUT.
set pf-status 'G350'.
set TITLEBAR 'T350'.
PERFORM S350_ALV_INI.
ENDMODULE.
"PROCESS AFTER INPUT.
MODULE USER_COMMAND_0350 INPUT.
case FCODE_350.
when 'BACK'.
Clear FCODE_350.
LEAVE to screen 0 .
when 'EXIT'.
Clear FCODE_350.
LEAVE PROGRAM.
when 'CANCEL'.
Clear FCODE_350.
leave to screen 0 .
WHEN 'DEMAT'.
IF wa_CurrentAct-EDDAT <> '00000000'.
MESSAGE '当前事务已经被关账过,不可再修改!' type 'E'.
EXIT.
ENDIF.
CALL METHOD grid_350_1->check_changed_data.
CALL METHOD grid_350_2->check_changed_data.
LOOP AT I_BMAT WHERE SELEC = 'X'.
delete from zfie003_bmat where matno = I_BMAT-MATNO.
delete from zfie003_emat where matno = I_BMAT-MATNO.
ENDLOOP.
LOOP AT I_EMAT WHERE SELEC = 'X'.
delete from zfie003_bmat where matno = I_EMAT-MATNO.
delete from zfie003_emat where matno = I_EMAT-MATNO.
ENDLOOP.
PERFORM GetMatFromDb.
CALL METHOD grid_350_1->refresh_table_display.
CALL METHOD grid_350_2->refresh_table_display.
endcase.
ENDMODULE.
"$ Endregion Screen 350
"###############################