FI-銷項稅調整程式(開發筆記)
阿新 • • 發佈:2018-12-11
*&---------------------------------------------------------------------*
*& Report ZFIR099
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2018-12-03
*& Program Type : Report
*& Description : 銷項稅調整
*&---------------------------------------------------------------------*
REPORT ZFIR099.
*&---------------------------------------------------------------------*
*& 包含 ZFIR092_TOP
*&---------------------------------------------------------------------*
TABLES:ACDOCA,BKPF
TYPE-POOLS:SLIS ,ICON .
"OOALV-DEFINITION
DATA GO_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA GO_ALV_GRID_SUB TYPE REF TO CL_GUI_ALV_GRID.
DATA LO_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA OK_CODE TYPE SY-UCOMM.
DATA OK_SAVE TYPE SY-UCOMM.
DATA CONTROLS_CREATED.
DATA GT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF GTS_DATA,
AFLAG TYPE C, "選擇列
BUKRS_VF TYPE VBAK-BUKRS_VF, "公司程式碼
KUNNR TYPE VBAK-KUNNR, "客戶
VBELN TYPE VBAK-VBELN, "銷售訂單
WAERK TYPE VBAK-WAERK, "銷售和分銷憑證貨幣
DMKPX TYPE BSEG-DMBTR, "開票銷項稅
DMYSX TYPE BSEG-DMBTR, "預收銷項稅
SAKXX TYPE SKA1-SAKNR, "銷項稅科目
SAKQT TYPE SKA1-SAKNR, "其他應收科目
DMBTR TYPE BSEG-DMBTR, "調整稅額
GZDAT TYPE DATS, "過賬日期
GJAHR TYPE GJAHR, "會計年度
ZKJQJ TYPE NUMC2, "期間
BELNR TYPE ACDOCA-BELNR, "會計憑證號碼
AWKEY TYPE AWKEY, "物件鍵值
VBELN_FV TYPE BSEG-KIDNO, "開票憑證
BUKRS TYPE BSEG-BUKRS, "公司程式碼
BELBS TYPE BSEG-BELNR, "會計憑證號碼
GJABS TYPE BSEG-GJAHR, "財年
BUZEI TYPE BSEG-BUZEI, "會計憑證中的行專案數
DMBBB TYPE BSEG-DMBTR, "本幣金額
SHKZG TYPE BSEG-SHKZG, "借貸標誌
KIDNO TYPE BSEG-KIDNO, "開票憑證
SGTXT TYPE BSEG-SGTXT, "專案文字
END OF GTS_DATA.
DATA: GLAG_N TYPE C .
DATA: GLAG_E TYPE C .
DATA: GT_DATA TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_A TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_B TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_C TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_ZTIR098 TYPE TABLE OF ZTIR098 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME .
PARAMETERS: P_BUKRS LIKE ACDOCA-RBUKRS MODIF ID P1 OBLIGATORY . "公司程式碼
SELECT-OPTIONS: S_KUNNR FOR KNA1-KUNNR MODIF ID S1, "客戶
S_VBELN FOR VBAK-VBELN MODIF ID S1. "銷售訂單
SELECTION-SCREEN END OF BLOCK B1.
*BUKRS BUKRS
*BELNR BELNR_D
*GJAHR GJAHR
*BUZEI BUZEI
*&---------------------------------------------------------------------*
*& 包含 ZFIR098_CLASS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* CLASS DEMO DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS DEMO DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
MAIN.
ENDCLASS.
CLASS DEMO IMPLEMENTATION.
METHOD MAIN.
DATA(OUT) = CL_DEMO_OUTPUT=>NEW( ).
OUT->BEGIN_SECTION( `報錯資訊回執`
)->WRITE( GT_RETURN[] ).
OUT->DISPLAY( ).
ENDMETHOD.
ENDCLASS.
*----------------------------------------------------------------------*
* CLASS cl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
" 宣告單擊事件的方法
METHODS HANDLE_HOTSPOT_CLICK
FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID.
" 宣告雙擊事件方法
METHODS HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
" 宣告TOOLBAR事件方法
METHODS HANDLE_TOOLBAR
FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
IMPORTING E_OBJECT E_INTERACTIVE.
" 宣告USER-COMMAND 事件方法
METHODS HANDLE_COMMAND
FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
IMPORTING E_UCOMM.
" 修改時觸發
METHODS HANDLE_DATA_CHANGED
FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED.
" ENTE時觸發
METHODS HANDLE_ENTE
FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
IMPORTING E_MODIFIED ET_GOOD_CELLS.
PRIVATE SECTION.
ENDCLASS. "CL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
" 單擊事件方法的實現
METHOD HANDLE_HOTSPOT_CLICK.
ENDMETHOD. "HANDLE_HOTSPOT_CLICK
" 雙擊事件方法的實現
METHOD HANDLE_DOUBLE_CLICK.
GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY( ).
ENDMETHOD. "HANDLE_DOUBLE_CLICK
" 實現TOOLBAR事件方法
METHOD HANDLE_TOOLBAR.
DATA: LS_TOOLBAR TYPE STB_BUTTON.
DELETE E_OBJECT->MT_TOOLBAR WHERE FUNCTION = '&PRINT_BACK'.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-BUTN_TYPE = 3. " 分隔符
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'BT_4'. "功能碼
* LS_TOOLBAR-ICON = ICON_SIMULATE. " 圖示名稱
LS_TOOLBAR-TEXT = '全選'. " 按鈕上顯示的文字
LS_TOOLBAR-QUICKINFO = '全選'. " 圖示的提示資訊
LS_TOOLBAR-BUTN_TYPE = 0. " 0表示正常按鈕
LS_TOOLBAR-DISABLED = ''. " X表示灰色,不可用
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'BT_5'. "功能碼
* LS_TOOLBAR-ICON = ICON_ACTIVITY. " 圖示名稱
LS_TOOLBAR-TEXT = '取消全選'. " 按鈕上顯示的文字
LS_TOOLBAR-QUICKINFO = '取消全選'. " 圖示的提示資訊
LS_TOOLBAR-BUTN_TYPE = 0. " 0表示正常按鈕
LS_TOOLBAR-DISABLED = ''. " X表示灰色,不可用
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
* CLEAR: LS_TOOLBAR.
* LS_TOOLBAR-FUNCTION = 'BT_3'. "功能碼
** LS_TOOLBAR-ICON = ICON_ACTIVITY. " 圖示名稱
* LS_TOOLBAR-TEXT = '自動計算銷項稅'. " 按鈕上顯示的文字
* LS_TOOLBAR-QUICKINFO = '自動計算銷項稅'. " 圖示的提示資訊
* LS_TOOLBAR-BUTN_TYPE = 0. " 0表示正常按鈕
* LS_TOOLBAR-DISABLED = ''. " X表示灰色,不可用
* APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'BT_1'. "功能碼
LS_TOOLBAR-ICON = ICON_SIMULATE. " 圖示名稱
LS_TOOLBAR-TEXT = '模擬過賬'. " 按鈕上顯示的文字
LS_TOOLBAR-QUICKINFO = '模擬過賬'. " 圖示的提示資訊
LS_TOOLBAR-BUTN_TYPE = 0. " 0表示正常按鈕
LS_TOOLBAR-DISABLED = ''. " X表示灰色,不可用
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR: LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'BT_2'. "功能碼
LS_TOOLBAR-ICON = ICON_ACTIVITY. " 圖示名稱
LS_TOOLBAR-TEXT = '正式過賬'. " 按鈕上顯示的文字
LS_TOOLBAR-QUICKINFO = '正式過賬'. " 圖示的提示資訊
LS_TOOLBAR-BUTN_TYPE = 0. " 0表示正常按鈕
LS_TOOLBAR-DISABLED = ''. " X表示灰色,不可用
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
ENDMETHOD. "HANDLE_TOOLBAR
" 實現USER-COMMAND 事件方法
METHOD HANDLE_COMMAND.
DATA : LV_STABLE TYPE LVC_S_STBL. "重新整理穩定性
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
CASE E_UCOMM.
WHEN 'BT_1'.
CLEAR GT_RETURN[] .
PERFORM FRM_DATA_POST_T .
WHEN 'BT_2'.
IF GT_DATA_C[] IS NOT INITIAL .
CLEAR GT_RETURN[] .
PERFORM FRM_DATA_POST .
ELSEIF GLAG_N IS NOT INITIAL .
MESSAGE '模擬過賬時出錯!' TYPE 'S' DISPLAY LIKE 'E' .
ELSE .
MESSAGE '請先進行模擬過賬!' TYPE 'S' DISPLAY LIKE 'E' .
ENDIF.
* WHEN 'BT_3'.
WHEN 'BT_4'.
PERFORM FRM_SELECT_ALL .
CALL METHOD GO_ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
WHEN 'BT_5'.
PERFORM FRM_UNSELECT_ALL .
CALL METHOD GO_ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "HANDLE_COMMAND
" 實現DATA_CHANGED 事件方法
METHOD HANDLE_DATA_CHANGED.
ENDMETHOD. "handle_data_changed
" 實現ENTE 事件方法
METHOD HANDLE_ENTE.
DATA GS_LAYOUT_ALV TYPE LVC_S_LAYO.
* GO_ALV_GRID_SUB->REFRESH_TABLE_DISPLAY( ).
DATA : LV_STABLE TYPE LVC_S_STBL. "重新整理穩定性
PERFORM FOM_REFRESH .
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
GS_LAYOUT_ALV-CWIDTH_OPT = 'X'. "優化列寬
CALL METHOD GO_ALV_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT_ALV.
CALL METHOD GO_ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = GO_ALV_GRID.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS. "cl_event_receiver IMPLEMENTATION
**------------------------------------------------------------------------------*
** 類定義-定時重新整理 *
**------------------------------------------------------------------------------*
*CLASS LCL_RECEIVER DEFINITION.
* PUBLIC SECTION.
* METHODS:
* HANDLE_FINISHED FOR EVENT FINISHED OF CL_GUI_TIMER.
*ENDCLASS.
* DATA: RECEIVER TYPE REF TO LCL_RECEIVER,
* TIMER TYPE REF TO CL_GUI_TIMER.
*CLASS LCL_RECEIVER IMPLEMENTATION.
* METHOD HANDLE_FINISHED.
** PERFORM FOM_REFRESH .
* CALL METHOD CL_GUI_CFW=>SET_NEW_OK_CODE "觸發pai ,usercommand裡有重新整理alv的程式碼
* EXPORTING
* NEW_CODE = 'REFRESH'.
** MESSAGE ID 'MO' TYPE 'S' NUMBER 429 .
* CALL METHOD TIMER->RUN.
* ENDMETHOD.
*ENDCLASS.
*
*CREATE OBJECT TIMER.
*CREATE OBJECT RECEIVER.
*SET HANDLER RECEIVER->HANDLE_FINISHED FOR TIMER.
*TIMER->INTERVAL = 600. "10分鐘重新整理一次
*CALL METHOD TIMER->RUN.
*
*PERFORM P_DISPLAY.
*
*CALL METHOD TIMER->RUN.
**------------------------------------------------------------------------------*
** 類定義-定時重新整理 *
**------------------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'PF_0100'.
SET TITLEBAR 'TITLE_0100'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module CREATE_ALV OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE CREATE_ALV OUTPUT.
CHECK CONTROLS_CREATED IS INITIAL.
CALL METHOD CL_GUI_CFW=>FLUSH."觸發SAP GUI更新介面
PERFORM FORM_INIT_0101. "例項化ALV_GRID
CONTROLS_CREATED = 'X'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CANCEL INPUT.
LEAVE PROGRAM .
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
OK_SAVE = SY-UCOMM .
CLEAR SY-UCOMM .
CLEAR OK_CODE .
CASE OK_SAVE.
WHEN 'BACK' .
LEAVE TO SCREEN 0 .
* WHEN 'DL' .
* PERFORM ole_fom .
WHEN OTHERS .
ENDCASE .
ENDMODULE.
*&---------------------------------------------------------------------*
*& 包含 ZFIR098_FOM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_EXCLUDE_OPTION
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_EXCLUDE_OPTION .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_OUTPUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_OUTPUT .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
*根據,螢幕條件、拒絕狀態(ABSTK)不等於C、ZYSBS等於A,取VBAK表相關資料,
*再根據VBRP-AUBEL = 銷售訂單,查詢開票憑證(VBRP-VBELN),刪除找不到的的銷售訂單資料,將找到的開票憑證(VBRP-VBELN)
*再去找BSEG中的資料:BSEG-KIDNO = 開票憑證,BSEG-HKONT=2221010300,取本幣金額(BSEG-DMBTR),借貸標誌(BSEG-SHKZG),
*如果借貸標誌等於H,對本幣金額取負數後再彙總,彙總的本幣金額為開票銷項稅。
CLEAR GT_DATA[] .
SELECT
VBAK~BUKRS_VF
VBAK~KUNNR
VBAK~VBELN
VBAK~WAERK
VBRP~VBELN AS VBELN_FV
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM VBAK
INNER JOIN VBRP ON VBAK~VBELN = VBRP~AUBEL
WHERE VBAK~BUKRS_VF = P_BUKRS
AND VBAK~KUNNR IN S_KUNNR
AND VBAK~VBELN IN S_VBELN
AND VBAK~ABSTK <> 'C'
AND VBAK~ZYSBS = 'A'
AND VBRP~VBELN <> ''
.
LOOP AT GT_DATA.
GT_DATA-SAKXX = '2221010300'.
GT_DATA-SAKQT = '1221090000'.
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
*DATA: GT_DATA_B TYPE TABLE OF GTS_DATA WITH HEADER LINE.
IF GT_DATA[] IS NOT INITIAL .
CLEAR GT_DATA_B[].
SELECT
BSEG~BUKRS
BSEG~BELNR AS BELBS
BSEG~GJAHR AS GJABS
BSEG~BUZEI
BSEG~DMBTR AS DMBBB
BSEG~SHKZG
BSEG~KIDNO AS VBELN_FV
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_B[]
FROM BSEG
FOR ALL ENTRIES IN GT_DATA[]
WHERE BSEG~KIDNO = GT_DATA-VBELN_FV
AND BSEG~HKONT = '2221010300'
.
LOOP AT GT_DATA_B.
READ TABLE GT_DATA WITH KEY VBELN_FV = GT_DATA_B-VBELN_FV .
IF SY-SUBRC = 0.
GT_DATA_B-BUKRS_VF = GT_DATA-BUKRS_VF .
GT_DATA_B-KUNNR = GT_DATA-KUNNR .
GT_DATA_B-VBELN = GT_DATA-VBELN .
GT_DATA_B-WAERK = GT_DATA-WAERK .
GT_DATA_B-SAKXX = GT_DATA-SAKXX .
GT_DATA_B-SAKQT = GT_DATA-SAKQT .
ENDIF.
MODIFY GT_DATA_B.
CLEAR GT_DATA_B.
ENDLOOP.
GT_DATA[] = GT_DATA_B[] .
SORT GT_DATA[] BY BUKRS_VF KUNNR SAKXX SAKQT VBELN .
DELETE ADJACENT DUPLICATES FROM GT_DATA[] COMPARING BUKRS_VF KUNNR SAKXX SAKQT VBELN.
LOOP AT GT_DATA.
CLEAR GT_DATA-DMKPX.
CLEAR GT_DATA-DMBBB.
LOOP AT GT_DATA_B WHERE KUNNR = GT_DATA-KUNNR AND SAKXX = GT_DATA-SAKXX
AND SAKQT = GT_DATA-SAKQT AND VBELN = GT_DATA-VBELN
AND BUKRS_VF = GT_DATA-BUKRS_VF.
IF GT_DATA_B-SHKZG = 'H'.
GT_DATA_B-DMBBB = GT_DATA_B-DMBBB * -1 .
ENDIF.
GT_DATA-DMKPX = GT_DATA-DMKPX + GT_DATA_B-DMBBB .
CLEAR GT_DATA_B .
ENDLOOP.
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
*預收銷項稅(BSEG-DMBTR):
*根據公司程式碼、BSEG-VBEL2 = 銷售訂單、BSEG-HKONT=2221010300,BSEG-SGTXT =預收開票開頭,
*取本幣金額(BSEG-DMBTR),借貸標誌(BSEG-SHKZG),如果借貸標誌等於H,對本幣金額取負數後再彙總,
*彙總的本幣金額為預收銷項稅。如果預收銷項稅為0,則刪除該條目。
CLEAR GT_DATA_B[].
SELECT
BSEG~BUKRS
BSEG~BELNR AS BELBS
BSEG~GJAHR AS GJABS
BSEG~BUZEI
BSEG~DMBTR AS DMBBB
BSEG~SHKZG
BSEG~KIDNO AS VBELN_FV
BSEG~SGTXT
BSEG~VBEL2 AS VBELN
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_B[]
FROM BSEG
FOR ALL ENTRIES IN GT_DATA[]
WHERE BSEG~VBEL2 = GT_DATA-VBELN
AND BSEG~HKONT = '2221010300'
.
LOOP AT GT_DATA_B.
IF GT_DATA_B-SGTXT CS '預收開票<