金稅介面
*--------------------------------------------------------------------------------*
* PROJECT NAME:
* PROGRAM TITLE: 金稅介面
* PROGRAM ID/NAME:
* AUTHOR'S NAME: * VERSION: 1.0
*--------------------------------------------------------------------------------*
* DESCRIPTION:
*--------------------------------------------------------------------------------*
* CHANGE HISTORY
*--------------------------------------------------------------------------------*
* Changed by xxxxxxxx
* On xxxxxxxx
* Description of the changes:
* #1.
* #2.
* #...
*---------------------------------------------------------------------------------
REPORT Z NO STANDARD PAGE HEADING
MESSAGE-ID ZSDA
LINE-SIZE 255
line-count 65.
*---------------------------------------------------------------------------------
* INCLUDES
*---------------------------------------------------------------------------------
INCLUDE:
*---------------------------------------------------------------------------------
* TYPE-POOLS
*---------------------------------------------------------------------------------
TYPE-POOLS: slis. "ALV
*---------------------------------------------------------------------------------
* TABLES
*---------------------------------------------------------------------------------
TABLES: vbrk, "Billing Document: Header Data
vbrp, "Billing Document: Item Data
vbfa, "銷售憑證流
vbak, "銷售憑證:抬頭資料
vbap, "銷售憑證:專案資料
vbpa, "銷售憑證:合作伙伴
vbpa3, "一次性客戶的稅編碼
konv, "vbrk-knumv
konp, "konv-knumh
lips, "SD document: Delivery: Item data
bkpf.
TABLES: kna1, "General Data in Customer Master
knvv, "Customer Master Sales Data
knvp, "Customer Master Partner Functions
knbk, "Customer Master (Bank Details)
bnka. "Bank master record
TABLES: adrc, "Addresses (Business Address Services)
adrct,
adr2. "Telephone Numbers (Business Address Services)
TABLES: mara,
t006a. "Assign Internal to Language-Dependent Unit
TABLES: zsd014u, "金稅介面使用者許可權分配表
zsd014o, "從SAP匯出資料記錄表
zsd014i. "從SAP匯入資料記錄表
*---------------------------------------------------------------------------------
* Global data define
*---------------------------------------------------------------------------------
* 內表定義
*---------------------------------------------------------------------------------
* 發票抬頭備註、客戶名稱、客戶地址、客戶銀行
*---------------------------------------------------------------------------------
DATA: BEGIN OF gt_document OCCURS 0,
vbeln LIKE vbrk-vbeln, "發票號
fkart LIKE vbrk-fkart, "發票型別
fkdat LIKE vbrk-fkdat, "出具發票日期
kunrg LIKE vbrk-kunrg, "付款方(客戶)
knumv LIKE vbrk-knumv, "konv-knumv,
zuonr LIKE vbrk-zuonr, "金稅發票號
sfakn LIKE vbrk-sfakn, "取消的發票號
* fksto LIKE vbrk-fksto, "該發票被取消標誌
zuonr1(10) TYPE C, "對應正數發票
zuonr2(8) TYPE C, "號碼
posnr LIKE vbrp-posnr,
matnr LIKE vbrp-matnr,
arktx LIKE vbrp-arktx, "銷售訂單專案短文字(物料描述)
vrkme LIKE vbrp-vrkme, "銷售單位
fkimg LIKE vbrp-fkimg, "開票數量
price(8) TYPE P decimals 7, "單價(不含稅) netwr/fkimg
netwr LIKE vbrp-netwr, "金額(不含稅)
trate TYPE P decimals 2, "稅率 mwsbp/netwr
mwsbp LIKE vbrp-mwsbp, "稅額
tolwr LIKE vbrp-netwr, "總價值 netwr+mwsbp
text(160) TYPE C, "備註
vbelv LIKE vbfa-vbelv, "vbeln+posnrvbelv+posnv 發票與銷售訂單的對應
posnv LIKE vbfa-posnv,
bukrs LIKE vbrk-bukrs, "公司程式碼,不同的公司適用不同風格的發票
END OF gt_document.
DATA: BEGIN OF gt_customer OCCURS 0,
kunnr LIKE kna1-kunnr,
name1 LIKE kna1-name1, "客戶名稱
name2 LIKE kna1-name2, "客戶名稱
name(70) TYPE C, "客戶名稱=name1+name2 匯出到金稅使用
name3(20) TYPE C, "客戶名稱=name1(20) Alv 顯示時使用
ktokd LIKE kna1-ktokd, "客戶帳戶組/判斷是否為一次性客戶
* stras LIKE kna1-stras, "客戶地址(門牌號 街道)
street LIKE adrc-street, "客戶地址-街道
house_num1 LIKE adrc-house_num1, "客戶地址-門牌號
addr(70) TYPE C, "客戶地址(街道 門牌號)
telf1 LIKE kna1-telf1, "電話
stcd1 LIKE kna1-stcd1, "稅號1(納稅人識別號)
bankl LIKE knbk-bankl, "客戶開戶銀行程式碼
banka LIKE bnka-banka, "銀行名稱
* bankn LIKE knbk-bankn, "客戶賬號
bankn LIKE bnka-stras, "銀行街道實際存放客戶賬號
END OF gt_customer.
DATA: BEGIN OF gt_output OCCURS 0.
INCLUDE STRUCTURE gt_document.
INCLUDE STRUCTURE gt_customer.
DATA: sel_flag TYPE C, "選擇框
dc_flag TYPE C, "已匯出到文字標識
ht_flag TYPE C. "已回填標識
DATA: END OF gt_output.
DATA: BEGIN OF gt_input OCCURS 0,
sel_flag TYPE C, "選擇框
jinsh1(10) TYPE C,
jinsh2(8) TYPE C,
vbeln(10) TYPE C,
belnr LIKE bkpf-belnr,
flag TYPE C, "回填結果狀態標誌
message(60) TYPE C,
END OF gt_input.
DATA: gt_zsd014o LIKE zsd014o OCCURS 0 WITH HEADER LINE,
gt_zsd014i LIKE zsd014i OCCURS 0 WITH HEADER LINE.
DATA: gt_bdcdata LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
gt_bdcmsg LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
*---------------------------------------------------------------------------------
* 常量定義
*---------------------------------------------------------------------------------
CONSTANTS: C_AUTH_QUERY LIKE zsd014u-zauth VALUE '1',
C_AUTH_TRANS LIKE zsd014u-zauth VALUE '2'.
CONSTANTS: C_CANCEL_ZUONR1 LIKE vbrk-zuonr VALUE 'x',
C_CANCEL_ZUONR2 LIKE vbrk-zuonr VALUE 'X',
C_LENTH_ZUONR TYPE I VALUE 18.
CONSTANTS: C_TEXT_SEPARATE(2) TYPE C VALUE 'n',
C_TEXT_ID LIKE THEAD-TDID VALUE '0002',
C_TEXT_OBJECT LIKE THEAD-TDOBJECT VALUE 'VBBK'.
CONSTANTS: g_object LIKE inri-object VALUE 'ZMIGSD014', "Number range
g_nr_01 LIKE inri-nrrangenr VALUE '01', "匯出編號區間
g_nr_02 LIKE inri-nrrangenr VALUE '02'. "匯入編號區間
DATA: g_number(10) TYPE C, "Number range
g_create_time LIKE sy-uzeit.
DATA: g_flag_download_chk TYPE C,
g_flag_upload_chk TYPE C,
g_flag_write_chk TYPE C.
*---------------------------------------------------------------------------------
* 全域性變數定義
*---------------------------------------------------------------------------------
DATA: g_authorization LIKE zsd014u-zauth.
DATA: g_filename LIKE rlgrap-filename.
*---------------------------------------------------------------------------------
* Data parameters for alv report use
*---------------------------------------------------------------------------------
* Screen 2000
DATA: ok_code LIKE sy-ucomm.
DATA: g_container TYPE scrfname VALUE 'G_CONTAINER',
g_custom_container TYPE REF TO cl_gui_custom_container,
g_alv_grid TYPE REF TO cl_gui_alv_grid,
gw_layout TYPE lvc_s_layo,
gw_fieldcat TYPE lvc_s_fcat,
gt_fieldcat TYPE lvc_t_fcat.
* Screen 3000
DATA: g_container2 TYPE scrfname VALUE 'G_CONTAINER2',
g_custom_container2 TYPE REF TO cl_gui_custom_container,
g_alv_grid2 TYPE REF TO cl_gui_alv_grid,
gw_layout2 TYPE lvc_s_layo,
gw_fieldcat2 TYPE lvc_s_fcat,
gt_fieldcat2 TYPE lvc_t_fcat.
*=================================================================================
* SELECTION-SCREEN
*=================================================================================
* Billing document number
SELECTION-SCREEN BEGIN OF BLOCK BLOCK0 WITH FRAME TITLE TEXT-006.
* 匯出
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
PARAMETERS: rb_out RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 3(20) text-007.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 WITH FRAME TITLE TEXT-001.
PARAMETERS : p_bukrs LIKE vbrk-bukrs MEMORY ID BUK.
SELECT-OPTIONS: s_fkart FOR vbrk-fkart,
s_vbeln FOR vbrk-vbeln,
s_kunrg FOR vbrk-kunrg,
s_fkdat FOR vbrk-fkdat,
s_zuonr FOR vbrk-zuonr.
SELECTION-SCREEN SKIP 1.
PARAMETERS: rb_ykp RADIOBUTTON GROUP g2.
PARAMETERS: rb_wkp RADIOBUTTON GROUP g2 DEFAULT 'X'.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 4.
PARAMETERS: rb_1 RADIOBUTTON GROUP g3.
SELECTION-SCREEN COMMENT 6(20) text-002.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 4.
PARAMETERS: rb_2 RADIOBUTTON GROUP g3.
SELECTION-SCREEN COMMENT 6(20) text-003.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 4.
PARAMETERS: rb_3 RADIOBUTTON GROUP g3.
SELECTION-SCREEN COMMENT 6(20) text-004.
SELECTION-SCREEN END OF LINE.
PARAMETERS: rb_all RADIOBUTTON GROUP g2.
SELECTION-SCREEN END OF BLOCK BLOCK1.
* 匯入
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
PARAMETERS: rb_in RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 3(20) text-008.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF BLOCK BLOCK2 WITH FRAME TITLE TEXT-005.
PARAMETERS: p_bukrs2 LIKE bkpf-bukrs,
p_gjahr2 LIKE bkpf-gjahr,
p_fname2 LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK BLOCK2.
SELECTION-SCREEN END OF BLOCK BLOCK0.
*---------------------------------------------------------------------------------
* INITIALIZATION
*---------------------------------------------------------------------------------
INITIALIZATION.
PERFORM frm_initial.
*---------------------------------------------------------------------------------
* AT SELECTION-SCREEN
*---------------------------------------------------------------------------------
AT SELECTION-SCREEN.
*---------------------------------------------------------------------------------
* AT SELECTION-SCREEN ON VALUE-REQUEST
*---------------------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname2.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = 'C:'
mask = ',Text Files,*.txt;*.prn,All Files,*.*.'
title = 'Select File'
IMPORTING
filename = p_fname2
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
IF sy-subrc NE 0 AND sy-subrc NE 3 AND p_fname2 NE space.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*=================================================================================
* MAIN PROGRAM
*=================================================================================
*---------------------------------------------------------------------------------
* START-OF-SELECTION
*---------------------------------------------------------------------------------
START-OF-SELECTION.
SELECT SINGLE * FROM zsd014u WHERE uname = sy-uname.
IF sy-subrc NE 0.
MESSAGE S001.
ELSE.
IF rb_out NE SPACE.
g_authorization = zsd014u-zauth.
PERFORM frm_get_billing_document.
PERFORM frm_set_output_data.
PERFORM frm_set_alv_para.
SORT gt_output BY vbeln posnr.
CALL SCREEN 2000.
ELSE.
PERFORM frm_upload CHANGING g_flag_upload_chk.
IF g_flag_upload_chk EQ SPACE.
PERFORM frm_set_alv_para2.
* SORT gt_input BY
CALL SCREEN 3000.
ENDIF.
ENDIF.
ENDIF.
*---------------------------------------------------------------------------------
* END-OF-SELECTION
*---------------------------------------------------------------------------------
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form frm_initial
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_initial .
ENDFORM. " frm_initial
*&---------------------------------------------------------------------*
*& Form frm_get_billing_document
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_get_billing_document .
DATA: l_strlen TYPE I,
l_id LIKE THEAD-TDID,
l_name LIKE THEAD-TDNAME,
l_object LIKE THEAD-TDOBJECT,
lt_tline LIKE tline OCCURS 0 WITH HEADER LINE,
l_index1 LIKE sy-tabix,
l_index2 LIKE sy-tabix,
l_text(40) TYPE C.
CLEAR: gt_document, gt_customer.
REFRESH: gt_document, gt_customer.
SELECT vbrk~vbeln
vbrk~fkart
vbrk~fkdat
vbrk~kunrg
vbrk~knumv
vbrk~zuonr
vbrk~sfakn
vbrp~posnr
vbrp~matnr
vbrp~arktx
vbrp~vrkme
vbrp~fkimg
vbrp~netwr
vbrp~mwsbp
vbrk~bukrs "Alex 2008.07.31
INTO CORRESPONDING FIELDS OF TABLE gt_document
FROM vbrk JOIN vbrp ON vbrk~vbeln = vbrp~vbeln
WHERE vbrk~vbeln IN s_vbeln "開票憑證
AND vbrk~fkart IN s_fkart "開票型別
AND vbrk~vtweg NE '20' "分銷渠道
AND vbrk~fkdat IN s_fkdat "出具發票日期
* AND vbrk~fksto EQ SPACE "已被取消標誌
AND vbrk~bukrs EQ p_bukrs "公司程式碼
AND vbrk~kunrg IN s_kunrg "付款方
AND vbrk~zuonr IN s_zuonr.
* 過濾不需要匯入到金稅系統的發票
LOOP AT gt_document.
TRANSLATE gt_document-fkart TO UPPER CASE.
IF ( gt_document-fkart = 'AF1' OR gt_document-fkart = 'AF3' OR
gt_document-fkart = 'F2A' OR gt_document-fkart = 'ZRE' ).
DELETE gt_document.
ENDIF.
ENDLOOP.
* 設定憑證其它資料
LOOP AT gt_document.
l_index1 = sy-tabix.
CLEAR l_text.
* 總價值/淨價/稅率
gt_document-tolwr = gt_document-netwr + gt_document-mwsbp.
IF gt_document-fkimg NE 0.
gt_document-price = gt_document-netwr / gt_document-fkimg.
ENDIF.
IF gt_document-netwr NE 0.
gt_document-trate = gt_document-mwsbp / gt_document-netwr.
IF gt_document-trate >= '0.155' AND gt_document-trate <= '0.184'. "CHANGED BY Liqiuxiang ON 2007.04.03
gt_document-trate = '0.17'.
ENDIF.
ENDIF.
* 負數發票金額等改為負值
TRANSLATE gt_document-fkart TO UPPER CASE.
IF ( gt_document-fkart = 'RE' OR gt_document-fkart = 'S1' OR
gt_document-fkart = 'S2' ).
gt_document-fkimg = 0 - gt_document-fkimg.
gt_document-netwr = 0 - gt_document-netwr.
gt_document-mwsbp = 0 - gt_document-mwsbp.
gt_document-tolwr = 0 - gt_document-tolwr.
ENDIF.
* 對應正數發票及號碼
IF ( gt_document-fkart = 'RE' OR gt_document-fkart = 'S1' OR
gt_document-fkart = 'S2' ) AND gt_document-sfakn NE SPACE.
SELECT SINGLE * FROM vbrk WHERE vbeln = gt_document-sfakn.
IF sy-subrc = 0.
l_strlen = strlen( vbrk-zuonr ).
IF ( vbrk-zuonr = vbrk-vbeln OR vbrk-zuonr = SPACE OR
vbrk-zuonr = C_CANCEL_ZUONR1 OR vbrk-zuonr = C_CANCEL_ZUONR2 OR
l_strlen NE C_LENTH_ZUONR ).
ELSE.
gt_document-zuonr1 = vbrk-zuonr(10).
gt_document-zuonr2 = vbrk-zuonr+10(8).
CONCATENATE '對應正數發票程式碼' gt_document-zuonr1 ' 號碼' gt_document-zuonr2 INTO l_text.
ENDIF.
ENDIF.
ENDIF.
* 得到備註
l_index2 = 0.
l_name = gt_document-vbeln.
CLEAR lt_tline.
REFRESH lt_tline.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = C_TEXT_ID
LANGUAGE = SY-LANGU
NAME = l_name
OBJECT = C_TEXT_OBJECT
* ARCHIVE_HANDLE =
* LOCAL_CAT =
* IMPORTING
* HEADER =
TABLES
LINES = lt_tline
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8 .
IF sy-subrc = 0.
LOOP AT lt_tline.
l_index2 = l_index2 + 1.
IF l_index2 = 1.
IF l_text EQ SPACE.
gt_document-text = lt_tline-tdline.
ELSE. "負數發票備註第一行為特定文字
CONCATENATE l_text lt_tline-tdline INTO gt_document-text SEPARATED BY C_TEXT_SEPARATE.
ENDIF.
ELSE.
CONCATENATE gt_document-text lt_tline-tdline INTO gt_document-text SEPARATED BY C_TEXT_SEPARATE.
ENDIF.
ENDLOOP.
ELSE.
IF l_text NE SPACE.
gt_document-text = l_text.
ENDIF.
ENDIF.
MOVE gt_document-kunrg TO gt_customer-kunnr.
COLLECT gt_customer.
MODIFY gt_document INDEX l_index1.
ENDLOOP.
* 得到客戶資料
LOOP AT gt_customer.
SELECT SINGLE * FROM kna1 WHERE kunnr = gt_customer-kunnr.
IF sy-subrc = 0.
IF kna1-ktokd NE 'Z006'. "非一次性客戶
MOVE-CORRESPONDING kna1 TO gt_customer.
* 名稱
CONCATENATE gt_customer-name1 gt_customer-name2 INTO gt_customer-name.
gt_customer-name3 = gt_customer-name1(20).
* 地址
SELECT SINGLE * FROM adrc WHERE addrnumber = kna1-adrnr AND date_from <= sy-datum AND date_to >= sy-datum.
IF sy-subrc = 0.
gt_customer-street = adrc-street.
gt_customer-house_num1 = adrc-house_num1.
CONCATENATE gt_customer-street gt_customer-house_num1 INTO gt_customer-addr.
ENDIF.
* 銀行
SELECT * FROM knbk UP TO 1 ROWS WHERE kunnr = gt_customer-kunnr. ENDSELECT.
IF sy-subrc = 0.
gt_customer-bankl = knbk-bankl.
* gt_customer-bankn = knbk-bankn.
* 銀行名稱
SELECT SINGLE * FROM bnka WHERE banks = knbk-banks AND bankl = knbk-bankl.
IF sy-subrc = 0.
gt_customer-banka = bnka-banka.
gt_customer-bankn = bnka-stras.
ENDIF.
ENDIF.
ELSE. "一次性客戶,客戶資料要聯絡憑證資料設定
gt_customer-ktokd = 'Z006'.
ENDIF.
ENDIF.
MODIFY gt_customer.
ENDLOOP.
ENDFORM. " frm_get_billing_document
*&---------------------------------------------------------------------*
*& Form frm_set_output_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_set_output_data .
DATA: l_index_doc LIKE sy-tabix,
l_index_cus LIKE sy-tabix,
l_strlen TYPE i.
CLEAR gt_output.
REFRESH gt_output.
SORT gt_customer BY kunnr.
LOOP AT gt_document.
l_index_doc = sy-tabix.
CLEAR gt_output.
READ TABLE gt_customer WITH KEY kunnr = gt_document-kunrg BINARY SEARCH.
IF sy-subrc = 0.
l_index_cus = sy-tabix.
IF gt_customer-ktokd = 'Z006'. "一次性客戶
* 找到發票對應的銷售訂單
SELECT * UP TO 1 ROWS FROM vbfa WHERE vbeln = gt_document-vbeln
AND posnn = gt_document-posnr
AND vbtyp_n = 'M'
AND vbtyp_v = 'C'.
ENDSELECT.
IF sy-subrc = 0.
gt_document-vbelv = vbfa-vbelv.
gt_document-posnv = vbfa-posnv.
* 找到一次性供應商地址程式碼
SELECT SINGLE * FROM vbpa WHERE vbeln = gt_document-vbelv
AND posnr = '000000'
AND parvw = 'RG'.
IF sy-subrc = 0.
* 一次性客戶資料A
SELECT SINGLE * FROM adrc WHERE addrnumber = vbpa-adrnr
AND date_from <= sy-datum
AND date_to >= sy-datum.
IF sy-subrc = 0.
gt_customer-name1 = adrc-name1.
gt_customer-name2 = adrc-name2.
CONCATENATE gt_customer-name1 gt_customer-name2 INTO gt_customer-name.
gt_customer-name3 = gt_customer-name1(20).
gt_customer-street = adrc-street.
gt_customer-house_num1 = adrc-house_num1.
CONCATENATE gt_customer-street gt_customer-house_num1 INTO gt_customer-addr.
gt_customer-telf1 = adrc-tel_number.
gt_customer-bankn = adrc-extension2.
ENDIF.
* 一次性客戶資料B--銀行名稱
SELECT * UP TO 1 ROWS FROM adrct WHERE addrnumber = vbpa-adrnr
AND date_from <= sy-datum
AND langu = sy-langu.
ENDSELECT.
IF sy-subrc = 0.
gt_customer-banka = adrct-remark.
ENDIF.
ENDIF.
* 一次性客戶資料C--稅號
SELECT SINGLE * FROM vbpa3 WHERE vbeln = gt_document-vbelv
AND posnr = '000000'
AND parvw = 'RG'.
IF sy-subrc = 0.
gt_customer-stcd1 = vbpa3-stcd1.
ENDIF.
ENDIF.
MOVE-CORRESPONDING gt_document TO gt_output.
MODIFY gt_document INDEX l_index_doc.
MOVE-CORRESPONDING gt_customer TO gt_output.
MODIFY gt_customer INDEX l_index_cus.
ELSE.
* 非一次性客戶
MOVE-CORRESPONDING gt_document TO gt_output.
MOVE-CORRESPONDING gt_customer TO gt_output.
ENDIF.
ELSE.
MOVE-CORRESPONDING gt_document TO gt_output.
ENDIF.
* 查詢並設定狀態
SELECT * UP TO 1 ROWS FROM zsd014o WHERE vbeln = gt_output-vbeln.
ENDSELECT.
IF sy-subrc = 0.
gt_output-dc_flag = 'X'.
ELSE.
CLEAR gt_output-dc_flag.
ENDIF.
SELECT * UP TO 1 ROWS FROM zsd014i WHERE vbeln = gt_output-vbeln AND zflag = 'S'.
ENDSELECT.
IF sy-subrc = 0.
gt_output-ht_flag = 'X'.
ELSE.
l_strlen = strlen( gt_output-zuonr ). "changed by Liqiuxiang ON 2007.04.02
IF gt_output-zuonr = C_CANCEL_ZUONR1 OR gt_output-zuonr = C_CANCEL_ZUONR2
OR l_strlen EQ C_LENTH_ZUONR.
gt_output-ht_flag = 'X'.
ELSE.
CLEAR: gt_output-ht_flag,
gt_output-zuonr.
ENDIF.
ENDIF.
APPEND gt_output.
ENDLOOP.
* 根據螢幕選項把不需要顯示的資料從內表刪除
LOOP AT gt_output.
* 只顯示已開票
IF rb_ykp NE space AND gt_output-ht_flag EQ SPACE.
DELETE gt_output.
ENDIF.
* 只顯示未開票
IF rb_wkp NE SPACE.
IF gt_output-ht_flag NE SPACE.
DELETE gt_output.
ELSE.
IF rb_1 NE SPACE AND gt_output-dc_flag NE SPACE. "只顯示未匯出文字
DELETE gt_output.
ENDIF.
IF rb_2 NE SPACE AND gt_output-dc_flag EQ SPACE. "只顯示已匯出文字
DELETE gt_output.
ENDIF.
IF rb_3 NE SPACE. "顯示所有未開票
ENDIF.
ENDIF.
ENDIF.
* 顯示全部
* IF rb_all NE SPACE.
* ENDIF.
ENDLOOP.
ENDFORM. " frm_set_output_data
*&---------------------------------------------------------------------*
*& Form frm_set_alv_para
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_set_alv_para .
* 宏定義
DEFINE ADD_TO_FIELDCAT.
CLEAR gw_fieldcat.
* gw_fieldcat-reftable = &1.
gw_fieldcat-fieldname = &1.
gw_fieldcat-coltext = &2.
gw_fieldcat-col_pos = &3.
gw_fieldcat-just = &4.
gw_fieldcat-outputlen = &5.
gw_fieldcat-checkbox = &6.
gw_fieldcat-edit = &7.
gw_fieldcat-fix_column = &8.
gw_fieldcat-no_zero = &9.
APPEND gw_fieldcat TO gt_fieldcat.
END-OF-DEFINITION.
gw_layout-cwidth_opt = 'X'.
* gw_layout-zebra = 'X'.
* gw_layout-smalltitle = 'X'.
* gw_layout-no_toolbar = 'X'.
* gw_layout-grid_title = text-101.
* gw_layout-info_fname = 'LINE_COLOR'.
ADD_TO_FIELDCAT 'SEL_FLAG' 'Sel' 1 'L' 3 'X' 'X' 'X' ''.
ADD_TO_FIELDCAT 'DC_FLAG' '匯出' 2 'L' 4 'X' '' 'X' ''.
* ADD_TO_FIELDCAT 'HT_FLAG' '開票' 3 'L' 4 '' '' 'X' ''.
ADD_TO_FIELDCAT 'FKART' '型別' 4 'L' 4 '' '' 'X' ''.
ADD_TO_FIELDCAT 'VBELN' '開票憑證' 5 'L' 10 '' '' 'X' ''.
ADD_TO_FIELDCAT 'ZUONR' '金稅發票號' 6 'L' 18 '' '' 'X' ''.
ADD_TO_FIELDCAT 'NAME3' '客戶' 7 'L' 20 '' '' '' ''.
ADD_TO_FIELDCAT 'FKDAT' '發票日期' 8 'L' 10 '' '' '' ''.
ADD_TO_FIELDCAT 'POSNR' '行專案' 9 'L' 6 '' '' '' ''.
ADD_TO_FIELDCAT 'MATNR' '物料' 11 'L' 18 '' '' '' ''.
ADD_TO_FIELDCAT 'ARKTX' '描述' 12 'L' 40 '' '' '' ''.
ADD_TO_FIELDCAT 'FKIMG' '開票數量' 13 'R' 17 '' '' '' ''.
ADD_TO_FIELDCAT 'VRKME' '單位' 14 'L' 4 '' '' '' ''.
ADD_TO_FIELDCAT 'TOLWR' '總價值' 15 'R' 16 '' '' '' ''.
ADD_TO_FIELDCAT 'NETWR' '淨價值' 16 'R' 16 '' '' '' ''.
ADD_TO_FIELDCAT 'PRICE' '單價' 17 'R' 16 '' '' '' ''.
ADD_TO_FIELDCAT 'TRATE' '稅率' 18 'R' 16 '' '' '' ''.
ADD_TO_FIELDCAT 'MWSBP' '稅額' 19 'R' 14 '' '' '' ''.
ADD_TO_FIELDCAT 'KUNNR' '客戶編碼' 22 'L' 10 '' '' '' ''.
ADD_TO_FIELDCAT 'STCD1' '納稅人識別號' 23 'L' 16 '' '' '' ''.
ADD_TO_FIELDCAT 'ADDR' '地址' 24 'L' 70 '' '' '' ''.
ADD_TO_FIELDCAT 'TELF1' '電話' 25 'L' 16 '' '' '' ''.
ADD_TO_FIELDCAT 'BANKA' '開戶行' 26 'L' 30 '' '' '' ''.
ADD_TO_FIELDCAT 'BANKN' '賬號' 27 'L' 35 '' '' '' ''.
ADD_TO_FIELDCAT 'ZUONR1' '對應正數發票' 28 'L' 12 '' '' '' ''.
ADD_TO_FIELDCAT 'ZUONR2' '號碼' 29 'L' 8 '' '' '' ''.
ADD_TO_FIELDCAT 'TEXT' '備註' 30 'L' 160 '' '' '' ''.
ENDFORM. " frm_set_alv_para
*&---------------------------------------------------------------------*
*& ALV EVENT Form frm_set_layout
*&---------------------------------------------------------------------*
FORM frm_user_command USING rf_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE rf_ucomm.
WHEN '&IC1' OR 'DOUB'. "雙擊事件或是F2事件
* READ TABLE gt_document INDEX rs_selfield-tabindex.
* SET PARAMETER ID 'BLN' FIELD xxx.
* SET PARAMETER ID 'BUK' FIELD xxx.
* SET PARAMETER ID 'GJR' FIELD xxx.
* CALL TRANSACTION 'xxxx' AND SKIP FIRST SCREEN.
WHEN 'EXPO'.
* PERFORM frm_check_download_data.
* PERFORM frm_download.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDFORM. "FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
IF g_authorization EQ C_AUTH_QUERY.
SET PF-STATUS 'JS_2000'.
ELSE.
SET PF-STATUS 'JS_2100'.
ENDIF.
SET TITLEBAR '020'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
CREATE OBJECT g_alv_grid
EXPORTING
i_parent = g_custom_container.
CALL METHOD g_alv_grid->set_table_for_first_display
EXPORTING
* i_structure_name =
is_layout = gw_layout
CHANGING
it_outtab = gt_output[]
it_fieldcatalog = gt_fieldcat.
ELSE.
CALL METHOD g_alv_grid->refresh_table_display.
ENDIF.
ENDMODULE. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_2000 INPUT.
* OK_CODE = SY-UCOMM.
* CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'EXIT'.
CLEAR ok_code.
PERFORM frm_free_alv_control.
LEAVE TO SCREEN 0.
WHEN 'ALLS'.
CLEAR ok_code.
PERFORM frm_select_all_2000.
WHEN 'ALLN'.
CLEAR ok_code.
PERFORM frm_unselect_2000.
WHEN 'EXPO'.
CLEAR ok_code.
CALL METHOD g_alv_grid->check_changed_data.
PERFORM frm_check_download_data CHANGING g_flag_download_chk.
IF g_flag_download_chk EQ SPACE.
PERFORM frm_download.
ENDIF.
WHEN OTHERS.
CLEAR ok_code.
CALL METHOD g_alv_grid->check_changed_data.
ENDCASE.
ENDMODULE. " USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*& Form frm_free_alv_control
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_free_alv_control .
* Destroy Control.
IF NOT g_alv_grid IS INITIAL.
CALL METHOD g_alv_grid->free
EXCEPTIONS
others = 1.
* IF sy-subrc NE 0.
* CALL FUNCTION 'POPUP_TO_INFORM'
* EXPORTING
* titel = g_repid
* txt2 = space
* txt1 = text-001.
* ENDIF.
* free also
FREE g_alv_grid.
ENDIF.
* destroy container
IF NOT g_custom_container IS INITIAL.
CALL METHOD g_custom_container->free
EXCEPTIONS
others = 1.
* IF sy-subrc <> 0.
* MESSAGE Exxx.
* ENDIF.
* free also
FREE g_custom_container.
ENDIF.
* finally flush
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
others = 1.
* IF sy-subrc NE 0.
* CALL FUNCTION 'POPUP_TO_INFORM'
* EXPORTING
* titel = g_repid
* txt2 = space
* txt1 = text-002.
* ENDIF.
ENDFORM. " frm_free_alv_control
*&---------------------------------------------------------------------*
*& Form frm_download
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_download .
DATA: BEGIN OF ls_header,
* 單據號(20) 商品行數(4) 客戶名稱(100) 稅號(15) 地址電話(80) 銀行帳號(80)
* 備註(160) 複核人(8) 收款人(8)
* 清單行商品名稱(60) 單據日期(8) 銷方銀行帳號(80) 銷方地址電話(80)
dj(10),
fgf01(2) VALUE '~~',
sp(4) TYPE N,
fgf02(2) VALUE '~~',
kh(50),
fgf03(2) VALUE '~~',
sh(15),
fgf04(2) VALUE '~~',
dz(80),
fgf05(2) VALUE '~~',
yh(50), "Alex 2007.03.16, Original: yh(30)
fgf06(2) VALUE '~~',
bz(160),
fgf07(2) VALUE '~~',
fh(8),
fgf08(2) VALUE '~~',
sk(8),
END OF ls_header.
DATA: BEGIN OF ls_item,
* 貨物名稱(60) 計量單位(16) 規格(30) 數量(16.6) 金額(14.2) 稅率(4.2) 商品稅目(4)
* 折扣金額(14.2) 稅額(14.2) 折扣稅額(14.2) 折扣率(6.3) 單價(16.6) 價格方式(1)
fgf01(2) VALUE ' ',
hwmc(40),
fgf02(2) VALUE '~~',
jldw(6),
fgf03(2) VALUE '~~',
guig(16),
fgf04(2) VALUE '~~',
shul(23),
fgf05(2) VALUE '~~',
jine(17),
fgf06(2) VALUE '~~',
shuil(7),
fgf07(2) VALUE '~~',
spsm(20),
fgf08(2) VALUE '~~',
zkje(17),
fgf09(2) VALUE '~~',
shuie(17),
fgf10(2) VALUE '~~',
zkse(17),
fgf11(2) VALUE '~~',
zkl(10),
fgf12(2) VALUE '~~',
danj(23),
fgf13(2) VALUE '~~',
jgfs(1),
END OF ls_item.
DATA: BEGIN OF lt_lines OCCURS 0,
line(1000) TYPE C,
END OF lt_lines.
DATA: lt_down LIKE gt_output OCCURS 0 WITH HEADER LINE,
lt_down_temp LIKE gt_output OCCURS 0 WITH HEADER LINE,
lt_down_iv LIKE gt_output OCCURS 0 WITH HEADER LINE,
l_index LIKE sy-tabix,
lw_output LIKE gt_output,
l_item_counts TYPE I,
l_shul(11) TYPE P DECIMALS 6, "數量
l_jine(8) TYPE P DECIMALS 2, "金額
l_shuil(3) TYPE P DECIMALS 2, "稅率
l_zkje(8) TYPE P DECIMALS 2, "折扣金額
l_shuie(8) TYPE P DECIMALS 2, "稅額
l_zkse(8) TYPE P DECIMALS 2, "折扣稅額
l_zkl(5) TYPE P DECIMALS 3. "折扣率
* 將要匯出的資料存至內表lt_down/記錄匯出歷史記錄到zsd014o
CLEAR: lt_down, lt_down_temp, lt_down_iv, gt_zsd014o.
REFRESH: lt_down, lt_down_temp, lt_down_iv, gt_zsd014o.
GET TIME FIELD g_create_time.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
object = g_object
nr_range_nr = g_nr_01
IMPORTING
number = g_number.
LOOP AT gt_output.
IF gt_output-sel_flag NE SPACE.
gt_output-dc_flag = 'X'. "更新顯示介面中的標誌欄位
MODIFY gt_output.
MOVE-CORRESPONDING gt_output TO lt_down. "匯出
APPEND lt_down.
CLEAR gt_zsd014o. "記錄
gt_zsd014o-zno = g_number.
gt_zsd014o-vbeln = gt_output-vbeln.
gt_zsd014o-ernam = sy-uname.
gt_zsd014o-erdat = sy-datum.
gt_zsd014o-erzet = g_create_time.
APPEND gt_zsd014o.
ENDIF.
ENDLOOP.
SORT gt_zsd014o BY zno vbeln.
DELETE ADJACENT DUPLICATES FROM gt_zsd014o COMPARING zno vbeln.
MODIFY zsd014o FROM TABLE gt_zsd014o.
COMMIT WORK.
*---------------------------------------------------------------
* 對IV型別發票的特殊處理/相同物料行專案合併---Start
*---------------------------------------------------------------
LOOP AT lt_down.
TRANSLATE lt_down-fkart TO UPPER CASE.
IF lt_down-fkart = 'IV'.
MOVE-CORRESPONDING lt_down TO lt_down_temp.
DELETE lt_down.
APPEND lt_down_temp.
ENDIF.
ENDLOOP.
* 合併
SORT lt_down_temp BY vbeln ascending matnr ascending netwr descending posnr ascending.
LOOP AT lt_down_temp.
READ TABLE lt_down_iv WITH KEY vbeln = lt_down_temp-vbeln
matnr = lt_down_temp-matnr.
IF sy-subrc = 0.
l_index = sy-tabix.
IF lt_down_temp-netwr < 0.
lt_down_iv-fkimg = lt_down_iv-fkimg - lt_down_temp-fkimg.
lt_down_iv-netwr = lt_down_iv-netwr + lt_down_temp-netwr.
lt_down_iv-mwsbp = lt_down_iv-mwsbp + lt_down_temp-mwsbp.
ELSE.
lt_down_iv-fkimg = lt_down_iv-fkimg + lt_down_temp-fkimg.
lt_down_iv-netwr = lt_down_iv-netwr + lt_down_temp-netwr.
lt_down_iv-mwsbp = lt_down_iv-mwsbp + lt_down_temp-mwsbp.
ENDIF.
MODIFY lt_down_iv INDEX l_index.
ELSE.
MOVE-CORRESPONDING lt_down_temp TO lt_down_iv.
* IF lt_down_temp-netwr < 0. "CHANGED BY Liqiuxiang ON 2007.03.28
* lt_down_iv-fkimg = 0 - lt_down_temp-fkimg.
* ELSE.
* lt_down_iv-fkimg = lt_down_temp-fkimg.
* ENDIF.
APPEND lt_down_iv.
ENDIF.
ENDLOOP.
* 重新計算稅率
LOOP AT lt_down_iv.
IF lt_down_iv-netwr NE 0.
lt_down_iv-trate = lt_down_iv-mwsbp / lt_down_iv-netwr.
IF lt_down_iv-trate <= '0.184' AND lt_down_iv-trate >= '0.155'. "CHANGED BY Liqiuxiang ON 2007.04.02
lt_down_iv-trate = '0.17'.
ENDIF.
ELSE.
lt_down_iv-trate = '0.17'.
ENDIF.
MODIFY lt_down_iv.
ENDLOOP.
APPEND LINES OF lt_down_iv TO lt_down.
*---------------------------------------------------------------
* 對IV型別發票的特殊處理/相同物料行專案合併---The end
*---------------------------------------------------------------
* 按金稅格式要求整理要匯出的資料
SORT lt_down BY vbeln posnr.
lt_lines-line = text-102.
APPEND lt_lines.
* lt_lines-line = ' '.
* APPEND lt_lines.
LOOP AT lt_down.
MOVE-CORRESPONDING lt_down TO lw_output.
AT NEW vbeln.
* CLEAR ls_header.
IF lw_output-fkart = 'IV'. "IV型別發票的特殊處理
l_item_counts = 0.
LOOP AT lt_down_iv WHERE vbeln = lw_output-vbeln.
l_item_counts = l_item_counts + 1.
ENDLOOP.
ELSE.
SELECT COUNT(*) FROM vbrp INTO l_item_counts WHERE vbeln = lw_output-vbeln. " AND netwr NE 0.
ENDIF.
MOVE: lw_output-vbeln TO ls_header-dj,
l_item_counts TO ls_header-sp,
lw_output-name TO ls_header-kh,
lw_output-stcd1 TO ls_header-sh.
CONCATENATE lw_output-addr lw_output-telf1 INTO ls_header-dz SEPARATED BY SPACE.
CONCATENATE lw_output-banka lw_output-bankn INTO ls_header-yh SEPARATED BY SPACE.
MOVE: lw_output-text TO ls_header-bz. "備註
* lw_output- TO ls_header-fh, "複核人
* lw_output- TO ls_header-sk, "收款人
* lw_output- TO ls_header-xf. "清單行商品名稱
* lw_output- TO ls_header-fh, "單據日期
* lw_output- TO ls_header-xf. "銷方銀行帳號
* lw_output- TO ls_header-xf. "銷方地址電話
* lt_lines-line = ls_header.
lt_lines-line = ' '.
APPEND lt_lines.
CONCATENATE ls_header-dj ls_header-fgf01 ls_header-sp ls_header-fgf02
ls_header-kh ls_header-fgf03 ls_header-sh ls_header-fgf04
ls_header-dz ls_header-fgf05 ls_header-yh ls_header-fgf06
ls_header-bz INTO lt_lines-line.
APPEND lt_lines.
ENDAT.
* CLEAR ls_item.
l_shul = lw_output-fkimg.
l_jine = lw_output-netwr.
l_shuil = lw_output-trate.
* l_zkje =
l_shuie = lw_output-mwsbp.
* l_zkse =
* l_zkl =
MOVE: lw_output-arktx TO ls_item-hwmc,
lw_output-vrkme TO ls_item-jldw, "單位
* lw_output- TO ls_item-guig, "規格
l_shul TO ls_item-shul,
l_jine TO ls_item-jine,
l_shuil TO ls_item-shuil,
* lw_output- TO ls_item-spsm, "商品稅目
* l_zkje TO ls_item-zkje,
l_shuie TO ls_item-shuie.
* l_zkse TO ls_item-zkse, "折扣稅額
* l_zkl TO ls_item-zkl. "折扣率
* lw_output- TO ls_item-danj, "單價
* lw_output- TO ls_item-jgfs. "價格方式
IF ( lw_output-bukrs = '2000' ) OR ( lw_output-kunnr = '0000001001' ).
MOVE: lw_output-matnr TO ls_item-guig. "Alex 2008.07.31 CD開票需要規格 / 2008.09.04 對CD開票需要規格
ENDIF.
TRANSLATE lw_output-fkart TO UPPER CASE.
IF ( lw_output-fkart = 'RE' OR lw_output-fkart = 'S1' OR
lw_output-fkart = 'S2' OR lw_output-fkart = 'IV' ).
CONDENSE ls_item-shuil.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING value = ls_item-shul.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING value = ls_item-jine.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING value = ls_item-shuie.
ELSE.
CONDENSE ls_item-shuil.
CONDENSE ls_item-shul.
CONDENSE ls_item-jine.
CONDENSE ls_item-shuie.
ENDIF.
* CONCATENATE ls_item-fgf01 ls_item-hwmc ls_item-fgf02 ls_item-jldw
* CONCATENATE ls_item-hwmc ls_item-fgf02 ls_item-jldw
* ls_item-fgf03 ls_item-guig ls_item-fgf04 ls_item-shul
* ls_item-fgf05 ls_item-jine ls_item-fgf06 ls_item-shuil
* ls_item-fgf07 ls_item-spsm ls_item-fgf08 ls_item-zkje
* ls_item-fgf09 ls_item-shuie INTO lt_lines-line.
CONCATENATE ls_item-hwmc ls_item-fgf02 ls_item-jldw
ls_item-fgf03 ls_item-guig ls_item-fgf04 ls_item-shul
ls_item-fgf05 ls_item-jine ls_item-fgf06 ls_item-shuil
ls_item-fgf07 INTO lt_lines-line.
CONCATENATE lt_lines-line ls_item-fgf08 INTO lt_lines-line SEPARATED BY SPACE.
CONCATENATE lt_lines-line ls_item-zkje ls_item-fgf09 ls_item-shuie INTO lt_lines-line.
SHIFT lt_lines-line BY 2 PLACES RIGHT.
APPEND lt_lines.
* AT END OF vbeln.
* lt_lines-line = ' '.
* APPEND lt_lines.
* ENDAT.
ENDLOOP.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = 'C:'
mask = ',Text Files,*.txt;*.prn,All Files,*.*.'
title = 'Select File'
IMPORTING
filename = g_filename
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
IF sy-subrc NE 0 AND sy-subrc NE 3 AND g_filename NE space.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF g_filename IS NOT INITIAL.
CONCATENATE g_filename text-103 INTO g_filename.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = ' '
* CODEPAGE = ' '
filename = g_filename
filetype = 'ASC'
mode = 'A'
TABLES
data_tab = lt_lines
* FIELDNAMES =
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.
ELSE.
MESSAGE E011.
ENDIF.
ENDFORM. " frm_download
*&---------------------------------------------------------------------*
*& Form frm_check_download_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_check_download_data CHANGING pr_check_result.
DATA: lt_download LIKE gt_output OCCURS 0 WITH HEADER LINE.
CLEAR pr_check_result.
CLEAR lt_download.
REFRESH lt_download.
* 已經回填的不能再匯出
LOOP AT gt_output WHERE sel_flag NE SPACE AND ht_flag NE SPACE.
pr_check_result = 'X'.
MESSAGE S009 WITH gt_output-vbeln.
ENDLOOP.
IF pr_check_result NE SPACE.
EXIT.
ENDIF.
* 總價值為0不匯出 Alex 2009.09.10
LOOP AT gt_output WHERE tolwr EQ 0.
pr_check_result = 'X'.
MESSAGE S010 WITH gt_output-vbeln.
ENDLOOP.
IF pr_check_result NE SPACE.
EXIT.
ENDIF.
* 匯出選擇不能遺漏行專案
LOOP AT gt_output WHERE sel_flag NE SPACE.
MOVE-CORRESPONDING gt_output TO lt_download.
APPEND lt_download.
ENDLOOP.
SORT lt_download BY vbeln posnr.
LOOP AT gt_output WHERE sel_flag EQ SPACE.
READ TABLE lt_download WITH KEY vbeln = gt_output-vbeln BINARY SEARCH.
IF sy-subrc = 0.
pr_check_result = 'X'.
MESSAGE S010 WITH gt_output-vbeln.
EXIT.
ENDIF.
ENDLOOP.
ENDFORM. " frm_check_download_data
*&---------------------------------------------------------------------*
*& Form frm_upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_upload CHANGING pr_up_flag.
DATA: wa_line(600) TYPE C,
lt_invoice LIKE wa_line OCCURS 0,
wa_text(160) TYPE C,
lt_text LIKE wa_text OCCURS 0,
l_vbeln LIKE vbrk-vbeln.
DATA: l_message(255) TYPE C,
l_lines TYPE I,
l_char_total(10) TYPE C,
l_lenth TYPE I,
l_total TYPE I.
CLEAR pr_up_flag.
CLEAR gt_input.
REFRESH gt_input.
REFRESH lt_invoice.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
* codepage = ' '
filename = p_fname2
filetype = 'ASC'
* headlen = ' '
* line_exit = ' '
* trunclen = ' '
* user_form = ' '
* user_prog = ' '
* IMPORTING
* filelength =
TABLES
data_tab = lt_invoice
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
others = 8.
IF sy-subrc NE 0.
pr_up_flag = 'X'.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO l_message.
MESSAGE I002 WITH l_message.
EXIT.
ENDIF.
* 資料合法檢查
DESCRIBE TABLE lt_invoice LINES l_lines.
IF l_lines < 2 .
pr_up_flag = 'X'.
MESSAGE I004.
EXIT.
ENDIF.
* 獲取第一行判斷檔案是否稅控下載的
READ TABLE lt_invoice INTO wa_line INDEX 1.
IF wa_line(8) NE 'SJJK0201'.
pr_up_flag = 'X'.
MESSAGE I003.
EXIT.
ENDIF.
* 獲取第二行第一個欄位,得到發票數量.
* READ TABLE lt_invoice INTO wa_line INDEX 2.
* SEARCH wa_line FOR '~~' .
* l_char_total = wa_line(sy-fdpos).
* CONDENSE l_char_total.
* l_lenth = STRLEN( l_char_total ).
* IF l_char_total(l_lenth) CO '0123456789'.
* l_total = l_char_total.
* ELSE.
* pr_up_flag = 'X'.
* MESSAGE I005.
* EXIT.
* ENDIF.
* 提取回填資料
LOOP AT lt_invoice INTO wa_line.
IF ( wa_line(1) = '0' OR wa_line(1) = '1' )
AND ( wa_line+3(1) = '0' OR wa_line+3(1) = '1' )
AND ( wa_line+6(1) = '0' OR wa_line+6(1) = '1' OR wa_line+6(1) = '2') .
REFRESH lt_text.
SPLIT wa_line AT '~~' INTO TABLE lt_text.
CLEAR gt_input.
READ TABLE lt_text INTO wa_text INDEX 4.
CONDENSE wa_text.
gt_input-jinsh1 = wa_text(10).
READ TABLE lt_text INTO wa_text INDEX 5.
CONDENSE wa_text.
gt_input-jinsh2 = wa_text(8).
READ TABLE lt_text INTO wa_text INDEX 9.
CONDENSE wa_text.
gt_input-vbeln = wa_text(10).
* CONDENSE gt_input-vbeln NO-GAPS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gt_input-vbeln
IMPORTING
output = l_vbeln
EXCEPTIONS
others = 1.
IF sy-subrc = 0.
gt_input-vbeln = l_vbeln.
ENDIF.
SELECT * UP TO 1 ROWS FROM bkpf
WHERE bukrs = p_bukrs2
AND gjahr = p_gjahr2
AND awtyp = 'VBRK'
AND awkey = gt_input-vbeln.
ENDSELECT.
IF sy-subrc = 0.
gt_input-belnr = bkpf-belnr.
ENDIF.
APPEND gt_input.
ENDIF.
ENDLOOP.
* 檢查是否含有有效回填資料
DESCRIBE TABLE gt_input LINES l_lines.
IF l_lines = 0 .
pr_up_flag = 'X'.
MESSAGE I006.
EXIT.
ENDIF.
* IF l_lines <> l_total.
* pr_up_flag = 'X'.
* MESSAGE I012.
* EXIT.
* ENDIF.
* 檢查是否已經成功回填過
LOOP AT gt_input.
SELECT * UP TO 1 ROWS FROM zsd014i
WHERE vbeln = gt_input-vbeln
AND zflag = 'S'.
ENDSELECT.
IF sy-subrc = 0.
gt_input-flag = 'S'.
MODIFY gt_input.
ENDIF.
ENDLOOP.
ENDFORM. " frm_upload
*&---------------------------------------------------------------------*
*& Form frm_set_alv_para2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM frm_set_alv_para2 .
* 宏定義
DEFINE ADD_TO_FIELDCAT2.
CLEAR gw_fieldcat2.
* gw_fieldcat2-reftable = &1.
gw_fieldcat2-fieldname = &1.
gw_fieldcat2-coltext = &2.
gw_fieldcat2-col_pos = &3.
gw_fieldcat2-just = &4.
gw_fieldcat2-outputlen = &5.
gw_fieldcat2-checkbox = &6.
gw_fieldcat2-edit = &7.
gw_fieldcat2-fix_column = &8.
gw_fieldcat2-no_zero = &9.
APPEND gw_fieldcat2 TO gt_fieldcat2.
END-OF-DEFINITION.
* gw_layout2-cwidth_opt = 'X'.
* gw_layout2-zebra = 'X'.
* gw_layout2-smalltitle = 'X'.
gw_layout2-no_toolbar = 'X'.
* gw_layout2-grid_title = text-101.
* gw_layout2-info_fname = 'LINE_COLOR'.
ADD_TO_FIELDCAT2 'SEL_FLAG' 'Sel' 1 'L' 3 'X' 'X' 'X' ''.
ADD_TO_FIELDCAT2 'JINSH1' '金稅發票類別程式碼' 2 'L' 16 '' '' 'X' ''.
ADD_TO_FIELDCAT2 'JINSH2' '金稅發票號碼' 3 'L' 12 '' '' 'X' ''.
ADD_TO_FIELDCAT2 'VBELN' 'SAP開票憑證' 4 'L' 10 '' '' 'X' ''.
ADD_TO_FIELDCAT2 'BELNR' '會計憑證' 5 'L' 10 '' '' 'X' ''.
ADD_TO_FIELDCAT2 'FLAG' '匯入結果' 6 'L' 8 '' '' '' ''.
ADD_TO_FIELDCAT2 'MESSAGE' '結果訊息' 7 'L' 60 '' '' '' ''.
ENDFORM. " frm_set_alv_para2
*&---------------------------------------------------------------------*
*& Module STATUS_3000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_3000 OUTPUT.
SET PF-STATUS 'JS_3000'.
SET TITLEBAR '030'.
IF g_custom_container2 IS INITIAL.
CREATE OBJECT g_custom_container2
EXPORTING
container_name = g_container2.
CREATE OBJECT g_alv_grid2
EXPORTING
i_parent = g_custom_container2.
CALL METHOD g_alv_grid2->set_table_for_first_display
EXPORTING
* i_structure_name =
is_layout = gw_layout2
CHANGING
it_outtab = gt_input[]
it_fieldcatalog = gt_fieldcat2.
ELSE.
CALL METHOD g_alv_grid2->refresh_table_display.
ENDIF.
ENDMODULE. " STATUS_3000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_3000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_3000 INPUT.
* OK_CODE = SY-UCOMM.
* CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'EXIT'.
CLEAR ok_code.
PERFORM frm_free_alv_control2.
LEAVE TO SCREEN 0.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/195776/viewspace-1023923/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 智慧金融“一張網”:以數治財,金稅工程如虎添翼
- 吳穎二:12.10 川普稅改總結,黃金走勢分析
- 根據稅碼取得稅率函式函式
- C#發票識別介面,再長的稅號錄入都不怕C#
- 新入金通道USDT支付介面平臺搭建
- 全國增值稅發票查驗介面平臺-JavaScript發票驗真api示例JavaScriptAPI
- c++如何計算增值稅(例如12%的增值稅)C++
- 個人所得稅
- 上海稅收首破萬億:BAT進納稅百強榜BAT
- “區塊鏈+稅費服務”讓辦稅繳費更便捷區塊鏈
- (原)同一種物料保稅與非保稅的處理
- ORACLE ERP物料保稅和非保稅的處理方法Oracle
- 吳穎二:12.14 午評 美聯儲及稅改不如市場預期,黃金今日策略
- 個人所得稅app新增殘疾證享受稅收優惠的方法教程APP
- vf之扣稅計算
- 今年你退稅了嗎?
- 境外iPhone7/Plus要繳稅:加稅後美版也比國行便宜iPhone
- 南非或將採用普通稅收規定對加密貨幣收益徵稅加密
- Go XORM 實踐--使用者金幣獎勵介面開發GoORM
- 免稅行業深度報告:政策護航的黃金賽道,高速成長的萬億市場(附下載)行業
- 30%的“蘋果稅”不公平,那麼50%的“國產安卓稅”公不公平?蘋果安卓
- 谷歌終因避稅低頭 同意向英國政府補交12億元稅款谷歌
- AP自動計稅設定
- Excel——年終獎個人所得稅Excel
- RPA財稅機器人:加速企業財稅智慧化轉型的關鍵機器人
- 輕鬆處理增值稅發票資料的利器——增值稅發票識別 APIAPI
- 個稅app怎麼新增銀行卡? 個人所得稅app新增銀行卡的教程APP
- 【Oracle AP】發票無法計稅Oracle
- 谷歌欠稅法國震怒:絕不妥協谷歌
- 保稅品怎麼處理呢?
- 車船稅業務知識學習(-)
- 車船稅業務知識--天津(三)
- 比利時稅務機構搜尋使用國外加密貨幣交易所的納稅人加密
- SAP SD基礎知識之稅(Taxes)
- python的個稅計算程式碼Python
- EXCEL國地稅表格的合併技巧Excel
- 奧巴馬打算向蘋果微軟徵稅百億美元蘋果微軟
- 車船稅業務知識學習(二)