FI-預收款(開發筆記)
阿新 • • 發佈:2018-12-11
*&---------------------------------------------------------------------*
*& Report ZFIR098
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2018-11-30
*& Program Type : Report
*& Description : 預收款
*&---------------------------------------------------------------------*
REPORT ZFIR098.
*&---------------------------------------------------------------------*
*& 包含 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, "客戶
NAME1 TYPE KNA1-NAME1, "客戶名稱
VBELN TYPE VBAK-VBELN, "銷售訂單
WAERK TYPE VBAK-WAERK, "貨幣
UMSKZ TYPE T074-UMSKZ, "SGL標誌
SKONT TYPE T074-SKONT, "預收科目
WRBYS TYPE BSEG-WRBTR, "預收款
SAKYH TYPE SKA1-SAKNR, "銀行科目
TXT20 TYPE SKAT-TXT20, "銀行科目描述
FSFNS TYPE C, "是否繳稅
WRBXX TYPE BSEG-WRBTR, "銷項稅
SAKXX TYPE SKA1-SAKNR, "銷項稅科目
RACQT TYPE SKA1-SAKNR, "其他應收科目
GZDAT TYPE DATS, "過賬日期
GJAHR TYPE GJAHR, "會計年度
ZKJQJ TYPE NUMC2, "期間
BELNR TYPE ACDOCA-BELNR, "會計憑證號碼
AWKEY TYPE AWKEY, "物件鍵值
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_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.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME .
PARAMETERS: P_CBOX1 AS CHECKBOX DEFAULT '' MODIF ID 01. "已預收SO
SELECTION-SCREEN END OF BLOCK B2.
*&---------------------------------------------------------------------*
*& 包含 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 .
CLEAR GT_DATA[] .
SELECT
VBAK~BUKRS_VF
VBAK~KUNNR
VBAK~VBELN
VBAK~WAERK
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM VBAK
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'
.
*如果螢幕沒有勾選checkbox:根據公司程式碼、客戶、銷售訂單取自建表資料,排除這些銷售訂單。
IF P_CBOX1 IS INITIAL.
CLEAR GT_ZTIR098[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_ZTIR098[] FROM ZTIR098
WHERE BUKRS_VF = P_BUKRS
AND KUNNR IN S_KUNNR
AND VBELN IN S_VBELN
.
LOOP AT GT_DATA.
LOOP AT GT_ZTIR098 WHERE BUKRS_VF = GT_DATA-BUKRS_VF AND KUNNR = GT_DATA-KUNNR AND VBELN = GT_DATA-VBELN.
DELETE GT_DATA .
EXIT .
ENDLOOP.
ENDLOOP.
ENDIF.
LOOP AT GT_DATA.
**------------------------------
* GT_DATA-SAKYH = '6603010100' .
* GT_DATA-WRBYS = '300' .
* GT_DATA-WRBXX = '36' .
* GT_DATA-GZDAT = '20181203' .
**------------------------------
GT_DATA-FSFNS = 'X' .
GT_DATA-UMSKZ = 'A' .
GT_DATA-SAKXX = '2221010300' .
GT_DATA-RACQT = '1221090000' .
SELECT SINGLE
T074~SKONT
INTO GT_DATA-SKONT
FROM T074
INNER JOIN KNB1 ON T074~HKONT = KNB1~AKONT
WHERE KNB1~KUNNR = GT_DATA-KUNNR
AND KNB1~BUKRS = GT_DATA-BUKRS_VF
AND T074~KTOPL = 'CP11'
AND T074~KOART = 'D'
AND T074~UMSKZ = GT_DATA-UMSKZ
.
SELECT SINGLE NAME1 INTO GT_DATA-NAME1 FROM KNA1
WHERE KUNNR = GT_DATA-KUNNR
* AND SPRAS = 1
.
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_INIT_0101
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FORM_INIT_0101 .
DATA L_FCAT_CACHE TYPE LVC_T_FCAT.
DATA WA_LAYOUT_CACHE TYPE LVC_S_LAYO.
DATA WA_FIELD TYPE LVC_S_FCAT.
DATA LO_EVENT TYPE REF TO CL_EVENT_RECEIVER.
CREATE OBJECT LO_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONT01'.
CREATE OBJECT GO_ALV_GRID
EXPORTING
I_PARENT = LO_CONTAINER.
DEFINE FILL_FIELD.
wa_field-fieldname = &1.
wa_field-coltext = &2.
IF wa_field-fieldname = 'FSFNS'
OR wa_field-fieldname = 'AFLAG'
.
wa_field-checkbox = 'X'.
wa_field-edit = 'X'.
ENDIF.
IF wa_field-fieldname = 'UMSKZ'
OR wa_field-fieldname = 'WRBYS'
OR wa_field-fieldname = 'SAKYH'
OR wa_field-fieldname = 'WRBXX'
OR wa_field-fieldname = 'GZDAT'
.
wa_field-edit = 'X'.
ENDIF.
IF wa_field-fieldname = 'GZDAT'.
wa_field-ref_table = 'VBAK'.
wa_field-ref_field = 'ERDAT'.
ENDIF.
IF wa_field-fieldname = 'SAKYH'.
wa_field-ref_table = 'SKA1'.
wa_field-ref_field = 'SAKNR'.
ENDIF.
IF wa_field-fieldname = 'WRBYS'
OR wa_field-fieldname = 'WRBXX'.
wa_field-ref_table = 'BSEG'.
wa_field-REF_FIELD = 'WRBTR'.
ENDIF.
*BSEG-WRBTR
APPEND wa_field TO l_fcat_cache .
CLEAR wa_field.
END-OF-DEFINITION.
FILL_FIELD :
'AFLAG' '選擇',
'BUKRS_VF' '公司程式碼',
'KUNNR' '客戶',
'NAME1' '客戶名稱',
'VBELN' '銷售訂單',
'WAERK' '貨幣',
'UMSKZ' 'SGL標誌',
'SKONT' '預收科目',
'WRBYS' '預收款',
'SAKYH' '銀行科目',
'TXT20' '銀行科目描述',
'FSFNS' '是否繳稅',
'WRBXX' '銷項稅',