1. 程式人生 > 實用技巧 >模擬會計憑證審批 OO ALV(螢幕跳轉、定位行資料、審批按鈕)

模擬會計憑證審批 OO ALV(螢幕跳轉、定位行資料、審批按鈕)

根據選定的單、多行會計憑證進行審批,雙擊單個會計憑證跳轉會計訂單明細。將審批的憑證記錄在一張自定義表中

*&---------------------------------------------------------------------*
*& Report  ZFI_SP
*&---------------------------------------------------------------------*
*&參考FB03
*&---------------------------------------------------------------------*
REPORT zfi_sp. TYPE-POOLS:slis,icon. TABLES:t001,bkpf,skat. DATA: ok_code LIKE sy-ucomm, save_ok LIKE ok_code. INCLUDE zfi_sp_alldata. "會計編號的詳細會計科目的資料型別 DATA gt_fieldcat TYPE slis_t_fieldcat_alv. DATA gs_fieldcat TYPE slis_fieldcat_alv. "表字段 DATA gs_layout TYPE slis_layout_alv. "佈局 DATA gt_events TYPE
slis_t_event. DATA gs_event TYPE slis_alv_event. "事件 TYPES:BEGIN OF ty_type, sel TYPE c, "選擇按鈕列 bukrs TYPE bukrs, belnr TYPE belnr_d, "會計憑證編號 gjahr TYPE gjahr, blart TYPE blart, "型別` bldat TYPE bldat, "憑證中的憑證日期 budat TYPE budat, "憑證中的過帳日期 bktxt TYPE bktxt, "
文字 sp TYPE c, END OF ty_type. DATA:gt_itab TYPE TABLE OF ty_type WITH HEADER LINE. DATA:wa_insert TYPE zfi_sp_table, wa_itab TYPE ty_type. DATA:fi_itab TYPE TABLE OF zfi_sp_table WITH HEADER LINE. DATA:fieldcat TYPE lvc_t_fcat, "1001 螢幕資料定義 grid TYPE REF TO cl_gui_alv_grid, g_container TYPE scrfname VALUE 'CONT1', g_custom_container TYPE REF TO cl_gui_custom_container. DATA: gt_fieldcat02 TYPE lvc_t_fcat, gs_variant02 TYPE disvariant, gs_layout02 TYPE lvc_s_layo. SELECTION-SCREEN BEGIN OF BLOCK blk_001 WITH FRAME TITLE blk_001 . SELECT-OPTIONS:t_bukrs FOR t001-bukrs OBLIGATORY. PARAMETERS:b_gjahr LIKE bkpf-gjahr DEFAULT sy-datum(4) OBLIGATORY. SELECT-OPTIONS:b_belnr FOR bkpf-belnr , b_bldat FOR bkpf-bldat, b_budat FOR bkpf-budat, b_blart FOR bkpf-blart, s_txt50 FOR skat-txt50, b_usnam FOR bkpf-usnam. PARAMETERS:a_check AS CHECKBOX. **PARAMETERS:b_check AS CHECKBOX DEFAULT 'X'. SELECTION-SCREEN END OF BLOCK blk_001. AT SELECTION-SCREEN. "新增公司許可權物件檢查 PERFORM frm_authority_check. START-OF-SELECTION. IF a_check = ''. IF b_blart = ''. SELECT bkpf~bukrs "公司程式碼 bkpf~belnr "憑證編號 bkpf~gjahr "年度 bkpf~blart "憑證型別 bkpf~budat "過帳日期 bkpf~bldat "憑證日期 bkpf~bktxt "抬頭文字 z~sp "審批標識 INTO CORRESPONDING FIELDS OF TABLE gt_itab FROM bkpf LEFT JOIN zfi_sp_table AS z ON z~belnr = bkpf~belnr AND z~belnr = bkpf~belnr AND z~bukrs = bkpf~bukrs WHERE bkpf~bukrs IN t_bukrs "公司程式碼 AND bkpf~belnr IN b_belnr "憑證編號 AND bkpf~gjahr = b_gjahr "會計年度 AND bkpf~bldat IN b_bldat "憑證日期 AND bkpf~budat IN b_budat "過帳日期 AND bkpf~blart IN ('SA','AB','AA','RV','DZ','RE','KZ') "憑證型別 AND bkpf~usnam IN b_usnam. "製作人 ELSE. SELECT bkpf~bukrs "公司程式碼 bkpf~belnr "憑證編號 bkpf~gjahr "年度 bkpf~blart "憑證型別 bkpf~budat "過帳日期 bkpf~bldat "憑證日期 bkpf~bktxt "抬頭文字 z~sp "審批標識 INTO CORRESPONDING FIELDS OF TABLE gt_itab FROM bkpf LEFT JOIN zfi_sp_table AS z ON z~belnr = bkpf~belnr AND z~belnr = bkpf~belnr AND z~bukrs = bkpf~bukrs WHERE bkpf~bukrs IN t_bukrs "公司程式碼 AND bkpf~belnr IN b_belnr "憑證編號 AND bkpf~gjahr = b_gjahr "會計年度 AND bkpf~bldat IN b_bldat "憑證日期 AND bkpf~budat IN b_budat "過帳日期 AND bkpf~blart IN b_blart "憑證型別 AND bkpf~usnam IN b_usnam. "製作人 ENDIF. DELETE gt_itab WHERE sp = 'X'. PERFORM all_data. PERFORM set_event. ELSE. SELECT * FROM zfi_sp_table INTO CORRESPONDING FIELDS OF TABLE fi_itab WHERE bukrs IN t_bukrs "公司程式碼 AND belnr IN b_belnr "憑證編號 AND gjahr = b_gjahr "會計年度 AND zerdt IN b_bldat "憑證日期 AND blart IN b_blart "憑證型別 AND uname IN b_usnam. "稽核人 ENDIF. PERFORM set_layout. PERFORM set_fieldname. PERFORM result_alv. *&---------------------------------------------------------------------* *& Form alv_user_command *&---------------------------------------------------------------------* * 定義初始螢幕操作邏輯 *----------------------------------------------------------------------* * -->P_UCOMM text * -->P_SELFIELD text *----------------------------------------------------------------------* FORM alv_user_command USING p_ucomm TYPE sy-ucomm p_selfield TYPE slis_selfield. p_selfield-refresh = 'X'. "控制grid產生新螢幕 CLEAR wa_insert. CASE p_ucomm. WHEN '&IC1'. READ TABLE gt_itab INDEX p_selfield-tabindex. "定位雙擊的行號 LOOP AT itab1 WHERE belnr = gt_itab-belnr. APPEND itab1 TO itab2. ENDLOOP. IF itab2[] IS NOT INITIAL. CALL SCREEN '1001'. ENDIF. WHEN 'SP'. "多個會計憑證一起審批 LOOP AT gt_itab WHERE sel = 'X'. CLEAR wa_insert. MOVE-CORRESPONDING gt_itab TO wa_insert. wa_insert-zerdt = sy-datum. wa_insert-uzeit = sy-uzeit. wa_insert-uname = sy-uname. wa_insert-sp = 'X'. INSERT zfi_sp_table FROM wa_insert. DELETE gt_itab. ENDLOOP. p_selfield-refresh = 'X'. "審批完成重新整理 ENDCASE. ENDFORM. "MALV_USER_COMMAND *&---------------------------------------------------------------------* *& Form alvshow *&---------------------------------------------------------------------* * 顯示雙擊選中會計編號的詳細會計科目 * CL_GUI_ALV_GRID->set_table_for_first_display *----------------------------------------------------------------------* FORM alvshow. gs_layout02-no_rowmark = 'X'. "禁用行選擇 gs_layout02-cwidth_opt = 'X'. "優化列寬度 gs_layout02-no_toolbar = 'X'. "隱藏工具欄 gs_variant02-report = sy-repid. CREATE OBJECT g_custom_container EXPORTING container_name = g_container. "建立容器 CREATE OBJECT grid EXPORTING i_parent = g_custom_container."建立ALV物件 PERFORM f_grid_build_fieldcat CHANGING gt_fieldcat02. SORT itab2 BY hkont DESCENDING. CALL METHOD grid->set_table_for_first_display EXPORTING is_layout = gs_layout02 is_variant = gs_variant02 CHANGING it_outtab = itab2[] it_fieldcatalog = gt_fieldcat02. CLEAR:gt_fieldcat02,gs_layout02,gs_variant02. ENDFORM. "alvshow *&---------------------------------------------------------------------* *& Form f_grid_build_fieldcat *&---------------------------------------------------------------------* * *----------------------------------------------------------------------* * -->PT_FIELDCAT text *----------------------------------------------------------------------* FORM f_grid_build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat. DATA ls_fcat TYPE lvc_s_fcat. CLEAR ls_fcat. ls_fcat-fieldname = 'BUKRS'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '公司'. ls_fcat-outputlen = 4. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'BELNR'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '憑證'. ls_fcat-outputlen = 10. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'HKONT'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '科目'. ls_fcat-outputlen = 10. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'SHKZG'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '借方/貸方標識'. ls_fcat-outputlen = 1. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'BUZEI'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '會計憑證中的行專案數'. ls_fcat-outputlen = 3. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'DMBTR'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '按本位幣計的金額本'. ls_fcat-outputlen = 13. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'WRBTR'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '憑證貨幣金額'. ls_fcat-outputlen = 13. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'SGTXT'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '摘要'. ls_fcat-outputlen = 50. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'KUNNR'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '客戶編號'. ls_fcat-outputlen = 10. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'LIFNR'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '供應商或債權人的帳號'. ls_fcat-outputlen = 8. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'TXT50'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '科目名稱'. ls_fcat-outputlen = 50. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'KOSTL'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '成本中心'. ls_fcat-outputlen = 10. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'FKBER_LONG'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '功能範圍'. ls_fcat-outputlen = 16. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'KTEXT'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '客戶名稱'. ls_fcat-outputlen = 35. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'NAME'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '供應商名稱'. ls_fcat-outputlen = 35. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'BLDAT'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '憑證日期'. ls_fcat-outputlen = 8. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'BUDAT'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '過賬日期'. ls_fcat-outputlen = 8. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'BLART'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '型別'. ls_fcat-outputlen = 2. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'HWAER'. ls_fcat-coltext = ls_fcat-tooltip = ls_fcat-seltext = '本幣'. ls_fcat-outputlen = 5. APPEND ls_fcat TO pt_fieldcat. ENDFORM. "F_GRID_BUILD_FIELDCAT *&---------------------------------------------------------------------* *& Form alv_status_set *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->PT_EXTAB text *----------------------------------------------------------------------* FORM alv_status_set USING pt_extab TYPE slis_t_extab. SET PF-STATUS 'COPY_GUI'." OF PROGRAM 'SAPLKKBL'. ENDFORM. "ALV_STATUS_SET *&---------------------------------------------------------------------* *& Form set_layout *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM set_layout . gs_layout-zebra = 'X'. gs_layout-colwidth_optimize = 'X'. gs_layout-cell_merge = 'X'. "內容能夠複製到剪貼簿 IF a_check <> 'X'. "顯示已審批資料不用指定 不然點選按鈕會報錯 gs_layout-box_fieldname = 'SEL'. "指定這個欄位為【選擇塊】 ENDIF. ENDFORM. " SET_LAYOUT *&---------------------------------------------------------------------* *& Form set_fieldname *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM set_fieldname. DEFINE setfieldcat. clear: gs_fieldcat. gs_fieldcat-col_pos = &1. gs_fieldcat-fieldname = &2. gs_fieldcat-seltext_m = &3. gs_fieldcat-no_zero = 'X'. append gs_fieldcat to gt_fieldcat. END-OF-DEFINITION. setfieldcat 1 'BUKRS' '工廠'. setfieldcat 2 'BELNR' '憑證編號'. setfieldcat 3 'GJAHR' '年度'. setfieldcat 4 'BLART' '型別'. IF a_check = 'X'. setfieldcat 5 'ZERDT' '審批日期'. setfieldcat 6 'UZEIT' '審批時間'. setfieldcat 7 'UNAME' '審批人'. setfieldcat 8 'SP' '審批完成標識'. ELSE. setfieldcat 5 'BLDAT' '憑證日期'. setfieldcat 6 'BUDAT' '過帳日期'. setfieldcat 7 'BKTXT' '抬頭文字'. * setfieldcat 8 'SP' '審批標識'. ENDIF. ENDFORM. "set_fieldname *&---------------------------------------------------------------------* *& Form result_alv *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM result_alv . IF a_check = ''. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid is_layout = gs_layout it_fieldcat = gt_fieldcat it_events = gt_events i_callback_user_command = 'ALV_USER_COMMAND' "按鈕功能(這個功能也能在is_layout中定義) TABLES t_outtab = gt_itab EXCEPTIONS program_error = 1 OTHERS = 2. ELSE. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid is_layout = gs_layout it_fieldcat = gt_fieldcat TABLES t_outtab = fi_itab EXCEPTIONS program_error = 1 OTHERS = 2. ENDIF. CLEAR a_check. ENDFORM. " RESULT_ALV *&---------------------------------------------------------------------* *& Form set_event *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM set_event . CLEAR gs_event. MOVE 'PF_STATUS_SET' TO gs_event-name."呼叫PF_STATUS_SET簽名的Form,ALV工具欄顯示前,可自定義工具條 MOVE 'ALV_STATUS_SET' TO gs_event-form. "工具欄設定 APPEND gs_event TO gt_events. ENDFORM. " SET_EVENT *&---------------------------------------------------------------------* *& Form all_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM all_data. SELECT SINGLE * FROM t001 WHERE bukrs = t_bukrs. comtitle = t001-butxt. SELECT bukrs "公司程式碼 belnr "憑證編號 blart "憑證型別 usnam "使用者名稱 ppnam "憑證製作人 budat "過帳日期 bldat "憑證日期 waers hwaer "本位幣 kursf "匯率 INTO CORRESPONDING FIELDS OF TABLE itab_bkpf FROM bkpf WHERE bukrs IN t_bukrs "公司程式碼 AND belnr IN b_belnr "憑證編號 AND gjahr = b_gjahr "會計年度 AND bldat IN b_bldat "憑證日期 AND budat IN b_budat "過帳日期 AND blart IN b_blart "憑證型別 AND usnam IN b_usnam. "製作人 SORT itab_bkpf BY belnr ASCENDING . IF sy-subrc <> 0. MESSAGE '輸入的憑證編號不存在!' TYPE 'E'. ENDIF. LOOP AT itab_bkpf. SELECT belnr "憑證編號 hkont "總分類帳帳目 shkzg "借方/貸方標識 dmbtr "按本位幣計的金額 wrbtr "憑證貨幣金額 sgtxt "專案文字 kunnr "客戶編號1 lifnr "供應商或債權人的帳號 zuonr "分配編號 buzei "會計憑證中的行專案數 kostl "成本中心 fkber_long "功能範圍 APPENDING CORRESPONDING FIELDS OF TABLE itab_bseg FROM bseg WHERE belnr = itab_bkpf-belnr AND gjahr = b_gjahr AND bukrs IN t_bukrs . "修改日元問題 by hua.su. IF itab_bkpf-waers = 'JPY' . LOOP AT itab_bseg WHERE belnr = itab_bkpf-belnr. itab_bseg-wrbtr = itab_bseg-wrbtr * 100. MODIFY itab_bseg. CLEAR itab_bseg. ENDLOOP. ENDIF. SELECT SINGLE butxt INTO itab_bkpf-butxt FROM t001 WHERE bukrs = itab_bkpf-bukrs. SELECT SINGLE ltext FROM t003t INTO itab_bkpf-ltext WHERE blart = itab_bkpf-blart AND t003t~spras = '1'. IF itab_bkpf-blart = 'KR' OR itab_bkpf-blart = 'KZ' OR itab_bkpf-blart = 'DR' OR itab_bkpf-blart = 'DZ' OR itab_bkpf-blart = 'SA'. SELECT SINGLE xblnr INTO itab_bkpf-xblnr "參考憑證號 FROM bkpf WHERE belnr = itab_bkpf-belnr. ENDIF. SELECT SINGLE name_last name_first INTO (itab_bkpf-name_last,itab_bkpf-name_first) FROM user_addr WHERE bname = itab_bkpf-usnam. CONCATENATE itab_bkpf-name_last itab_bkpf-name_first INTO itab_bkpf-name_last. SELECT SINGLE bseg~kunnr INTO itab_bkpf-kunnr FROM bseg WHERE bseg~belnr = itab_bkpf-belnr AND kunnr <> ''. IF itab_bkpf-blart = 'RV'. SELECT SINGLE kna1~name1 INTO itab_bkpf-sgtxt FROM kna1 WHERE kunnr = itab_bkpf-kunnr. CONCATENATE '銷售-' itab_bkpf-sgtxt INTO itab_bkpf-sgtxt. ENDIF. MODIFY itab_bkpf INDEX sy-tabix. ENDLOOP. IF NOT itab_bseg[] IS INITIAL. DATA temp_sgtxt LIKE bseg-sgtxt. SORT itab_bseg DESCENDING BY belnr lifnr. LOOP AT itab_bseg. SELECT SINGLE txt50 FROM skat INTO itab_bseg-txt50 WHERE skat~saknr = itab_bseg-hkont. SELECT SINGLE cskt~ktext INTO itab_bseg-ktext FROM cskt WHERE cskt~kostl = itab_bseg-kostl AND cskt~spras = '1'. IF itab_bseg-lifnr <> ''. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = itab_bseg-lifnr IMPORTING output = itab_bseg-lifnr. CONCATENATE itab_bseg-txt50 '-' itab_bseg-lifnr INTO itab_bseg-txt50. ENDIF. IF itab_bseg-kunnr <> ''. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = itab_bseg-kunnr IMPORTING output = itab_bseg-kunnr. CONCATENATE itab_bseg-txt50 '-' itab_bseg-kunnr INTO itab_bseg-txt50. ENDIF. IF itab_bseg-fkber_long = '1000'. CONCATENATE itab_bseg-txt50 '-' itab_bseg-ktext '-' itab_bseg-kostl '-' '製造費用' INTO itab_bseg-txt50. ELSEIF itab_bseg-fkber_long = '2000' . CONCATENATE itab_bseg-txt50 '-' itab_bseg-ktext '-' itab_bseg-kostl '-' '管理費用' INTO itab_bseg-txt50. ELSEIF itab_bseg-fkber_long = '3000'. CONCATENATE itab_bseg-txt50 '-' itab_bseg-ktext '-' itab_bseg-kostl '-' '銷售費用' INTO itab_bseg-txt50. ELSEIF itab_bseg-fkber_long = '4000'. CONCATENATE itab_bseg-txt50 '-' itab_bseg-ktext '-' itab_bseg-kostl '-' '研發費用' INTO itab_bseg-txt50. ELSEIF itab_bseg-fkber_long = '5000'. CONCATENATE itab_bseg-txt50 '-' itab_bseg-ktext '-' itab_bseg-kostl '-' '材料附加費' INTO itab_bseg-txt50. ENDIF. MODIFY itab_bseg INDEX sy-tabix. ENDLOOP. ENDIF. *************讀取供應商或客戶描述************* IF NOT itab_bseg[] IS INITIAL."確定為已過帳的憑證 SELECT saknr txt50 INTO TABLE itab_skat FROM skat FOR ALL ENTRIES IN itab_bseg WHERE saknr = itab_bseg-hkont AND spras = sy-langu AND ktopl = t001-ktopl. * READ TABLE ITAB_SKAT. SELECT kunnr name1 INTO TABLE itab_kna1 FROM kna1 FOR ALL ENTRIES IN itab_bseg WHERE kunnr = itab_bseg-kunnr. SELECT lifnr name1 INTO TABLE itab_lfa1 FROM lfa1 FOR ALL ENTRIES IN itab_bseg WHERE lifnr = itab_bseg-lifnr. ENDIF. SORT itab_bseg BY shkzg DESCENDING buzei ASCENDING belnr ASCENDING . LOOP AT itab_bseg. COLLECT itab_bseg INTO itab. ENDLOOP. SORT itab BY belnr. LOOP AT itab. "FBY 2015 READ TABLE itab_bkpf WITH KEY belnr = itab-belnr. IF sy-subrc = 0. itab1-bukrs = itab_bkpf-bukrs. itab1-belnr = itab_bkpf-belnr."會計憑證編號 itab1-hkont = itab-hkont. "科目編碼 itab1-shkzg = itab-shkzg. "借方/貸方標識 itab1-buzei = itab-buzei. itab1-dmbtr = itab-dmbtr. "按本位幣計的金額 itab1-wrbtr = itab-wrbtr. "憑證貨幣金額 itab1-sgtxt = itab-sgtxt. "摘要 itab1-kunnr = itab-kunnr. "客戶編號1 itab1-lifnr = itab-lifnr. "供應商或債權人的帳號 itab1-txt50 = itab-txt50. "科目名稱 itab1-kostl = itab-kostl. "成本中心 itab1-fkber_long = itab-fkber_long. "功能範圍 itab1-ktext = itab-ktext. "成本中心描述 itab1-name1 = itab-name1. "客戶名稱 itab1-name = itab-name. "供應商名稱 itab1-bldat = itab_bkpf-bldat. "憑證日期 "fby itab1-budat = itab_bkpf-budat. "過賬日期 itab1-blart = itab_bkpf-blart. "型別 itab1-hwaer = itab_bkpf-hwaer. "本幣 APPEND itab1. CLEAR itab1. ENDIF. ENDLOOP. ENDFORM. "FRM_GET_DATA *&---------------------------------------------------------------------* *& Form frm_authority_check *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM frm_authority_check . DATA: BEGIN OF lt_werks OCCURS 0 , werks LIKE t001w-werks, END OF lt_werks . SELECT werks INTO CORRESPONDING FIELDS OF TABLE lt_werks FROM t001w WHERE werks IN t_bukrs. LOOP AT lt_werks . AUTHORITY-CHECK OBJECT 'ZWERKS' ID 'WERKS' FIELD lt_werks-werks . IF sy-subrc <> 0. MESSAGE e001(00) WITH '你沒有 ' lt_werks-werks '公司的操作許可權!'. ENDIF. ENDLOOP . ENDFORM. "frm_authority_check INCLUDE zfi_sp_pbo . INCLUDE zfi_sp_pai .
*&---------------------------------------------------------------------*
*&  包括                ZFI_SP_ALLDATA
*&---------------------------------------------------------------------*
*--------------------------------------------------------------------------------------------------------------------------------*
DATA:comtitle     LIKE t001-butxt.
TYPES:BEGIN OF ty_itab1,
       bukrs LIKE bkpf-bukrs,
       belnr LIKE bseg-belnr, "會計憑證編號
       hkont LIKE bseg-hkont,  "科目編碼
       shkzg LIKE bseg-shkzg,  "借方/貸方標識
       buzei LIKE bseg-buzei,
       dmbtr LIKE bseg-dmbtr,  "按本位幣計的金額
       wrbtr LIKE bseg-wrbtr,  "憑證貨幣金額
       sgtxt LIKE bseg-sgtxt, "摘要
       kunnr LIKE bseg-kunnr,                               "客戶編號1
       lifnr LIKE bseg-lifnr, "供應商或債權人的帳號
       txt50 LIKE skat-txt50,  "科目名稱
       kostl LIKE bseg-kostl,  "成本中心
       fkber_long LIKE bseg-fkber_long,  "功能範圍
       ktext LIKE cskt-ktext,  "成本中心描述
       name1 LIKE kna1-name1,  "客戶名稱
       name  LIKE lfa1-name1,  "供應商名稱
       bldat LIKE bkpf-bldat, "憑證日期      "fby
       budat LIKE bkpf-budat, "過賬日期
       blart LIKE bkpf-blart, "型別
       hwaer LIKE bkpf-hwaer, "本幣
     END OF ty_itab1.
DATA:itab1 TYPE TABLE OF ty_itab1 WITH HEADER LINE,
     itab2 TYPE TABLE OF ty_itab1 WITH HEADER LINE.


DATA:BEGIN OF itab_bkpf OCCURS 0,
       bukrs LIKE bkpf-bukrs,
       butxt LIKE t001-butxt,
       belnr LIKE bseg-belnr,"會計憑證編號
       blart LIKE bkpf-blart,
       bktxt LIKE bkpf-bktxt,
       usnam LIKE bkpf-usnam,"過帳人
       ppnam LIKE bkpf-ppnam,"預製人
       budat LIKE bkpf-budat,
       bldat LIKE bkpf-bldat,
       xblnr LIKE bkpf-xblnr,"參照
       waers LIKE bkpf-waers,"幣別碼
       hwaer LIKE bkpf-hwaer,"本位幣 by snowchen 10/05/25
       ltext  LIKE t003t-ltext, "憑證型別描述
       name_first  LIKE user_addr-name_first,        "
       name_last   LIKE user_addr-name_last,         "
       sgtxt LIKE bseg-sgtxt, "摘要
       kunnr LIKE bseg-kunnr, "客戶程式碼
       kursf LIKE bkpf-kursf, "匯率
     END OF itab_bkpf.
DATA:BEGIN OF itab_bseg OCCURS 0,

  belnr LIKE bseg-belnr, "會計憑證編號
  hkont LIKE bseg-hkont,  "科目編碼
  shkzg LIKE bseg-shkzg,  "借方/貸方標識
  buzei LIKE bseg-buzei,
  dmbtr LIKE bseg-dmbtr,  "按本位幣計的金額
  wrbtr LIKE bseg-wrbtr,  "憑證貨幣金額
  sgtxt LIKE bseg-sgtxt, "摘要
  kunnr LIKE bseg-kunnr,                                    "客戶編號1
  lifnr LIKE bseg-lifnr, "供應商或債權人的帳號
  txt50 LIKE skat-txt50,  "科目名稱
  kostl LIKE bseg-kostl,  "成本中心
  fkber_long LIKE bseg-fkber_long,  "功能範圍
  ktext LIKE cskt-ktext,  "成本中心描述
  name1 LIKE kna1-name1,  "客戶名稱
  name  LIKE lfa1-name1,  "供應商名稱
END OF itab_bseg.
DATA: itab LIKE TABLE OF itab_bseg  WITH HEADER LINE.

DATA: BEGIN OF itab_skat OCCURS 10  ,
saknr LIKE skat-saknr,   "會計科目
txt50 LIKE skat-txt50,    "科目描述
END OF itab_skat.


DATA: BEGIN OF itab_kna1 OCCURS 0 ,
      kunnr LIKE kna1-kunnr,"客戶編碼
      name1 LIKE kna1-name1,"客戶名稱
END OF itab_kna1.

DATA: BEGIN OF itab_lfa1 OCCURS 0 ,
      lifnr LIKE lfa1-lifnr,"供應商編碼
      name1 LIKE lfa1-name1,"供應商名稱

END OF itab_lfa1.

DATA: BEGIN OF itab_sgtxt OCCURS 0 ,
      sgtxt LIKE bseg-sgtxt,
  END OF itab_sgtxt.
*--------------------------------------------------------------------------------------------------、

PBO

*&---------------------------------------------------------------------*
*&  Include           ZFI_SP_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_1001 OUTPUT.
  SET PF-STATUS 'T001'.
  PERFORM alvshow.   "展示雙擊選中會計編號的詳細會計科目
*  SET TITLEBAR '憑證科目'.
ENDMODULE.                 " STATUS_1001  OUTPUT

PAI

*&---------------------------------------------------------------------*
*&  Include           ZFI_SP_PAI
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1001  INPUT
*&---------------------------------------------------------------------*
*  單個記錄已審批的的會計憑證
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'SP'.
      MOVE-CORRESPONDING gt_itab TO wa_insert.
      wa_insert-zerdt = sy-datum.
      wa_insert-uzeit = sy-uzeit.
      wa_insert-uname = sy-uname.
      wa_insert-sp = 'X'.
      INSERT zfi_sp_table FROM wa_insert.

      MOVE-CORRESPONDING gt_itab TO wa_itab.
      DELETE TABLE gt_itab FROM wa_itab.
      CLEAR:wa_itab,gt_itab.
      CLEAR:itab2[],itab2.
      LEAVE TO SCREEN 0.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      CLEAR:itab2[],itab2,wa_itab,gt_itab.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_1001  INPUT