码迷,mamicode.com
首页 > Web开发 > 详细

abap金税上传EXCEL版

时间:2015-04-29 11:39:46      阅读:433      评论:0      收藏:0      [点我收藏+]

标签:abap金税上传   abap金税下载   

      SAP ERP ECC6.0标准功能提供给了金税接口,对于一般的公司来说,这个接口基本也够了。

     事务代码:GT_DLN 下载SAP发票信息;     

     事务代码:GT_ULN 上传金税信息到SAP中;

     前提条件:SAP ERP ECC6.0 功能增强包EHp3及以上。
     

     激活业务功能事务代码 SFW5选择业务功能FIN_LOC_CI_1,点击激活按钮。

     激活业务功能包后,系统将执行一个后台任务,执行可能需要长达一小时。

     参见SAP Note:Note 1290073 – China Golden Tax Switch ActivateNote 1380072 – China Golden Tax Interface Legal Change for GTS 6.1x补充说明SAP 还提供了在创建系统发票时,根据发票限额自动进行分拆的程序原理是在复制控制中利用例程(roution)实现。参见SAP NoteNote 192558 – Template for invoice split with a maximum amount per
invoice

     下面是自开发的EXCEL版不的金税上传程序。

*&---------------------------------------------------------------------
*
*&   VAT 发票号码写入会计凭证批输入程序
*
*&   功能 : 将 VAT 发票号码, 开票日期, 发票类型输入到Header Text
*
*&           (bkpf-bktxt). 并把VAT发票号码输入到
*
*&           第一个行项目的定位号字段(bseg-zuonr)中
*
*&   查找会计凭证的条件:1. 参考过程为 VBRK 并且对象代码为系统发票号码
*
*&
*
*&   SAP-CN 2000.01.18
*
*&---------------------------------------------------------------------
*
* use the development class ZINV. transaction code ZIMP.
* use the function group ZINV.
REPORT  ZSD_JSEXCEL2 NO STANDARD PAGE HEADING MESSAGE-ID ZLC.
DATA:II TYPE I"定义循环次数变量
     INVONO(8).
INCLUDE ZIMPDEF_TT1.
*INCLUDE ZIMPDEF.
SELECTION-SCREEN COMMENT 10(60TEXT-020.
SELECTION-SCREEN SKIP.
* the definitiion is follow the ‘jingshui‘. which stand for receipt
*type
*      ‘Welcome importing the VAT number to R/3 system‘(020).
PARAMETERS: BILLTYPE(10TYPE C.
PARAMETERS: VAT_FILE LIKE RLGRAP-FILENAME .
*            ERR_FILE LIKE RLGRAP-FILENAME.

INITIALIZATION.
  MOVE ‘C:\SAP上传\金税导入.XLS‘ TO VAT_FILE.
*  MOVE ‘C:\VAT\IMP_ERR.TXT‘ TO ERR_FILE.
* user exit to set the initial value.
*  CALL CUSTOMER-FUNCTION ‘002‘
*            CHANGING
*              VAT_FILE  =  VAT_FILE
**              ERR_FILE  =  ERR_FILE
*              BILLTYPE  =  BILLTYPE.

AT SELECTION-SCREEN.
  PERFORM AUTHORITY_CHECK USING ‘04‘ RC ‘*‘ ‘*‘.
*  check rc = 0.
* user exit 001 for authority check.
  CALL CUSTOMER-FUNCTION ‘001‘
       CHANGING
            RC      = RC
       EXCEPTIONS
            OTHERS  = 1.

  CHECK RC = 0.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR VAT_FILE.
  PERFORM GET_PC_FILENAME.
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR ERR_FILE.
*  PERFORM GET_ERR_FILENAME.

AT SELECTION-SCREEN ON VAT_FILE.
  IF VAT_FILE IS INITIAL.
    MESSAGE E212.
  ENDIF.

START-OF-SELECTION.
  PERFORM UPLOAD_FILE.      "upload the VAT file
*  PERFORM GET_DOCUMENT.     "Get the FI document
  PERFORM GET_UPFILE.       "整理出税控发票和系统发票号的对应.
  SET PF-STATUS ‘IMP‘.
  WRITE‘总发票数量:‘,TOTAL,
        / ‘   明细如下,如需要更新系统,请保存‘.
  FORMAT COLOR COL_HEADING.
  WRITE:/(106) SY-ULINE.
  WRITE:/ SY-VLINE,(4‘顺序号‘,
         SY-VLINE,(8‘公司代码‘,
         SY-VLINE,(10‘ 会计凭证 ‘,
         SY-VLINE,(4‘年度‘,
         SY-VLINE,(18‘税控发票号‘,
         SY-VLINE,(10‘R/3发票号‘,
         SY-VLINE,(30‘文本‘,
         SY-VLINE.
  WRITE:/(106) SY-ULINE.
  FORMAT COLOR COL_NORMAL .
  LOOP AT ITAB_BKPF INTO WA_BKPF.
    WRITE:/ SY-VLINE,(4) SY-TABIX,
           SY-VLINE,(8) WA_BKPF-BUKRS ,
           SY-VLINE,(10) WA_BKPF-BELNR ,
           SY-VLINE,(4) WA_BKPF-GJAHR,
           SY-VLINE,(18) WA_BKPF-VATNUM,
           SY-VLINE,(10) WA_BKPF-AWKEY,
           SY-VLINE,(30) WA_BKPF-BKTXT ,
           SY-VLINE.
    WRITE:/(106) SY-ULINE.

  ENDLOOP.

AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN ‘UPDATE‘.
      PERFORM UPDATE_TABLE.
  ENDCASE.
**Fill the BDCtable and call transaction
*  LOOP AT ITAB_BKPF INTO WA_BKPF.
*    REFRESH BDCDATA.
*    PERFORM FILL_BDCTABLE.
*    PERFORM CALL_TRANSACTION.
*  ENDLOOP.
*
**Download the error file.
*  PERFORM DOWNLOAD_ERROR.
*
*END-OF-SELECTION.
*  ULINE.
*  WRITE: / ‘The imported file is as below.‘(023).
*  LOOP AT ITAB_INVOICE INTO LIN_INVOICE .
*    WRITE: / LIN_INVOICE.
*  ENDLOOP.

*********************Subroutine****************************************
*
FORM AUTHORITY_CHECK  USING US_ACTVT US_SUBRC
                            US_VKORG US_FKART  .
  US_SUBRC = 0.
  AUTHORITY-CHECK OBJECT ‘V_VBRK_VKO‘
       ID ‘VKORG‘ FIELD US_VKORG
       ID ‘ACTVT‘ FIELD US_ACTVT.

  IF SY-SUBRC NE 0.
    US_SUBRC = SY-SUBRC.
    CASE US_ACTVT.
      WHEN ‘04‘.
        MESSAGE E518(VF) WITH US_VKORG.
      WHEN ‘03‘.
        MESSAGE E514(VF) WITH US_VKORG.
      WHEN ‘02‘.
        MESSAGE E515(VF) WITH US_VKORG.
      WHEN OTHERS.
        MESSAGE E011 WITH US_VKORG.
*      when ‘01‘.
*        xkomfk-fxmsg = ‘515‘.
*        perform vbfs_hinzufuegen using ‘000000‘ ‘515‘ us_vkorg
*                                                      space space.
    ENDCASE.
  ENDIF.

  AUTHORITY-CHECK OBJECT ‘V_VBRK_FKA‘
       ID ‘FKART‘ FIELD US_FKART
       ID ‘ACTVT‘ FIELD US_ACTVT.

  IF SY-SUBRC NE 0.
    US_SUBRC = SY-SUBRC.
    CASE US_ACTVT.
      WHEN ‘04‘.
        MESSAGE E519(VF) WITH US_FKART.
      WHEN ‘03‘.
        MESSAGE E516(VF) WITH US_FKART.
      WHEN ‘02‘.
        MESSAGE E517(VF) WITH US_FKART.
      WHEN OTHERS.
        MESSAGE E012 WITH US_FKART.
*      when ‘01‘.
*        xkomfk-fxmsg = ‘517‘.
*        perform vbfs_hinzufuegen using ‘000000‘ ‘517‘ us_fkart
*                                                      space space.
    ENDCASE.
  ENDIF.
ENDFORM.                               " AUTHORITY_CHECK

*&---------------------------------------------------------------------
*
*&      Form  get_document
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM GET_DOCUMENT.
*data: lin_invoice type linvoice.
  DATA: IDX LIKE SY-TABIX VALUE ‘1‘.
  DATA: LEN LIKE SY-FDPOS,
        OFF LIKE SY-FDPOS.
* the definition is follow the ‘jingshui‘.
  DATA: P_INVOICE(8TYPE C,
        P_DATE LIKE SY-DATUM,
        P_ITEMNUM(3TYPE N,
        P_BILLING LIKE VBRK-VBELN.
  DATA: P_BILLBAK(10TYPE N.   "used for c-->n-->c. reference vbrk-vbeln
  DATA: P_BKTXT LIKE BKPF-BKTXT.
  DATA: DELETE_FLAG(1TYPE C.
  REFRESH: ITAB_BKPF.
  DO.
    CLEAR : OFF, LEN, P_DATE, P_INVOICE, P_BKTXT, P_ITEMNUM.
    CLEAR: DELETE_FLAG, WA_BSEG, WA_BKPF.
    READ TABLE ITAB_INVOICE INDEX IDX INTO LIN_INVOICE.
    IF SY-SUBRC <> 0EXITENDIF.
    SEARCH LIN_INVOICE FOR ‘,‘ .
    IF SY-SUBRC <> 0MESSAGE E058 WITH VAT_FILE . ENDIF"
    MOVE LIN_INVOICE(SY-FDPOS) TO P_INVOICE.
    MOVE P_INVOICE TO WA_BKPF-VATNUM.
    OFF = SY-FDPOS + 2.
    LEN = OFF - 1.

    SEARCH LIN_INVOICE FOR ‘,‘ STARTING AT OFF.
    IF SY-SUBRC <> 0MESSAGE E058 WITH VAT_FILE . ENDIF"
    MOVE LIN_INVOICE+LEN(SY-FDPOS) TO P_ITEMNUM.
    OFF = OFF + SY-FDPOS + 1.
    LEN = OFF - 1.

    SEARCH LIN_INVOICE FOR ‘,‘ STARTING AT OFF.
    IF SY-SUBRC <> 0MESSAGE E058 WITH VAT_FILE. ENDIF"
    MOVE LIN_INVOICE+LEN(SY-FDPOS) TO P_DATE.
    OFF = OFF + SY-FDPOS + 1.
    LEN = OFF - 1.

    SEARCH LIN_INVOICE FOR ‘,‘ STARTING AT OFF.
    IF SY-SUBRC <> 0.MESSAGE E058 WITH VAT_FILE . ENDIF"
    MOVE LIN_INVOICE+LEN(SY-FDPOS) TO P_BILLING.
    MOVE P_BILLING TO P_BILLBAK.
    MOVE P_BILLBAK TO P_BILLING.

    SELECT SINGLE BUKRS BELNR GJAHR AWKEY
            INTO CORRESPONDING FIELDS OF WA_BKPF  FROM BKPF
            WHERE AWTYP = ‘VBRK‘   "FI document header
            AND  AWKEY  = P_BILLING.
    IF SY-SUBRC <> 0.
      MESSAGE E215 WITH P_BILLING VAT_FILE.
    ENDIF.
    MOVE P_INVOICE TO WA_BKPF-BKTXT(8).
    MOVE BILLTYPE TO WA_BKPF-BKTXT+9(4).
    MOVE P_DATE TO WA_BKPF-BKTXT+14(10).
    CONDENSE WA_BKPF-BKTXT.

* user exit for changing the wa_bkpf value.
* You can use it to choose the suitable data for R/3.
    CALL CUSTOMER-FUNCTION ‘003‘
               CHANGING
                  BUKRS  = WA_BKPF-BUKRS
                  BELNR  = WA_BKPF-BELNR
                  GJAHR  = WA_BKPF-GJAHR
                  BKTXT  = WA_BKPF-BKTXT
                  AWKEY  = WA_BKPF-AWKEY
                  XCPDS  = WA_BKPF-XCPDS
                  VATNUM = WA_BKPF-VATNUM
                  BUZEI  = WA_BKPF-BUZEI.

*  append wa_bkpf to itab_bkpf .
* Process all VAT number and include the one time customer
    SELECT SINGLE BUKRS BELNR GJAHR BUZEI KUNNR INTO WA_BSEG
          FROM BSEG       "FI document line item
          WHERE BUKRS = WA_BKPF-BUKRS
          AND   BELNR = WA_BKPF-BELNR
          AND   GJAHR = WA_BKPF-GJAHR
         AND   KUNNR NE SPACE.  "Only have one customer follow buss rule
*        and   buzei = ‘001‘.      "only deal with first line item

    IF SY-SUBRC EQ 0" and wa_bseg-kunnr ne space.
      MOVE WA_BSEG-BUZEI TO WA_BKPF-BUZEI.
      SELECT SINGLE KUNNR KTOKD
             INTO WA_KNA1
             FROM  KNA1                " customer data
             WHERE  KUNNR  = WA_BSEG-KUNNR.
*                ktokd
      IF SY-SUBRC EQ 0 AND WA_KNA1-KTOKD NE SPACE.
        SELECT SINGLE KTOKD XCPDS FROM  T077D   " customer account
               INTO WA_T077D
               WHERE  KTOKD  = WA_KNA1-KTOKD.
        IF SY-SUBRC EQ 0.
          WA_BKPF-XCPDS = WA_T077D-XCPDS.       " one time account flag
        ELSE.
          DELETE_FLAG = ‘X‘.
* 客户帐户组错
          PERFORM PROCESS_ERROR USING WA_BKPF-BELNR
                                      WA_BKPF-BKTXT
                                      WA_BKPF-AWKEY
                                      TEXT-006.
        ENDIF.
      ELSE.
        DELETE_FLAG = ‘X‘.
* 客户号码错
        PERFORM PROCESS_ERROR USING WA_BKPF-BELNR
                                    WA_BKPF-BKTXT
                                    WA_BKPF-AWKEY
                                    TEXT-005.
      ENDIF.
    ELSE.
      DELETE_FLAG = ‘X‘.
* 没有行项目
      PERFORM PROCESS_ERROR USING WA_BKPF-BELNR
                                  WA_BKPF-BKTXT
                                  WA_BKPF-AWKEY
                                  TEXT-004.
    ENDIF.

* user exit to deal with the exceptions.
    CALL CUSTOMER-FUNCTION ‘004‘
         IMPORTING
                BUKRS  = WA_BKPF-BUKRS
                BELNR  = WA_BKPF-BELNR
                GJAHR  = WA_BKPF-GJAHR
                BKTXT  = WA_BKPF-BKTXT
                AWKEY  = WA_BKPF-AWKEY
                XCPDS  = WA_BKPF-XCPDS
                VATNUM = WA_BKPF-VATNUM
                BUZEI  = WA_BKPF-BUZEI
           CHANGING
                DELETE_FLAG = DELETE_FLAG.

    IF DELETE_FLAG = ‘‘.
      APPEND WA_BKPF TO ITAB_BKPF.
    ENDIF.

* add the idx for the read imported file
    IDX = IDX + P_ITEMNUM + 1.
  ENDDO.



ENDFORM.                    " GET_DOCUMENT
*&---------------------------------------------------------------------
*
*&      Form  GET_PC_FILENAME
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM GET_PC_FILENAME.
  CALL FUNCTION ‘WS_FILENAME_GET‘
    EXPORTING
*     def_filename     = vat_file
*     DEF_PATH         = ‘ ‘
      MASK             = ‘,*.* ,*.*.‘
      MODE             = ‘0‘
      TITLE            = ‘Get the Invoice import file name‘
    IMPORTING
      FILENAME         = VAT_FILE
*     RC               =
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.
  IF SY-SUBRC <> 0.
    MESSAGE E216.
  ENDIF.
ENDFORM.                    " GET_PC_FILENAME
*&---------------------------------------------------------------------
*
*&      Form  GET_ERR_FILENAME
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM GET_ERR_FILENAME.
  CALL FUNCTION ‘WS_FILENAME_GET‘
    EXPORTING
*     DEF_FILENAME     = ‘ ‘
*     DEF_PATH         = ‘ ‘
      MASK             = ‘,*.* ,*.*.‘
      MODE             = ‘0‘
      TITLE            = ‘Get the Error message export file name‘
    IMPORTING
      FILENAME         = VAT_FILE
*     RC               =
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.
  IF SY-SUBRC <> 0.
    MESSAGE E216.
  ENDIF.

ENDFORM.                    " GET_ERR_FILENAME
*&---------------------------------------------------------------------
*
*&      Form  UPLOAD_FILE
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM UPLOAD_FILE.

  DATA: LINE_CNT TYPE I.
  REFRESH: ITAB_INVOICE.
*注释txt部分
*  CALL FUNCTION ‘WS_UPLOAD‘
*       EXPORTING
**           CODEPAGE            = ‘ ‘
*            FILENAME            = VAT_FILE
*            FILETYPE            = ‘ASC‘
**           HEADLEN             = ‘ ‘
**           LINE_EXIT           = ‘ ‘
**           TRUNCLEN            = ‘ ‘
**           USER_FORM           = ‘ ‘
**           USER_PROG           = ‘ ‘
**      IMPORTING
**           FILELENGTH          =
*       TABLES
*            DATA_TAB            =  ITAB_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.

**********上传excel dingyang
  CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE‘
*导入EXCEL数据到内表
          EXPORTING
            FILENAME    = VAT_FILE
            I_BEGIN_COL = ‘1‘
            I_BEGIN_ROW = ‘1‘
            I_END_COL   = ‘4‘            "只取4列
            I_END_ROW   = ‘2000‘         "只取500行
          TABLES
            INTERN      = ITAB_INVOICE.

**********上传excel dingyang
  IF SY-SUBRC >< 0.
    MESSAGE E217 WITH VAT_FILE.
  ENDIF.
  DESCRIBE TABLE ITAB_INVOICE LINES LINE_CNT.
  IF LINE_CNT LT 1.
    MESSAGE E218 WITH VAT_FILE.
  ENDIF.

**************处理ITAB_INVOICE数据,将其变为横项4列
  DATA IDXY(3).
  CLEAR IDXY.
  LOOP AT ITAB_INVOICE.

    IDXY = IDXY + 1.
    IF ITAB_INVOICE-COL = ‘0001‘.
      ITAB_INVOICE1-VBELN = ITAB_INVOICE-VALUE.
    ENDIF.
    IF ITAB_INVOICE-COL = ‘0003‘.
      ITAB_INVOICE1-LX = ITAB_INVOICE-VALUE.
    ENDIF.
    IF ITAB_INVOICE-COL = ‘0004‘.
      ITAB_INVOICE1-FPH = ITAB_INVOICE-VALUE.
    ENDIF.
    IF IDXY MOD 4 = 0.
      APPEND ITAB_INVOICE1.
      CLEAR ITAB_INVOICE1.
    ENDIF.
  ENDLOOP.
***
***  READ TABLE ITAB_INVOICE1 INDEX 1.
***  IF ITAB_INVOICE1-VBELN = ‘销售单据编号‘.
***    DELETE ITAB_INVOICE1.
***  ENDIF.

  DELETE ITAB_INVOICE1 INDEX 1.
  LOOP AT ITAB_INVOICE1.

    CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
      EXPORTING
        INPUT  = ITAB_INVOICE1-FPH
      IMPORTING
        OUTPUT = ITAB_INVOICE1-FPH
      EXCEPTIONS
        OTHERS = 1.
    MODIFY ITAB_INVOICE1.
  ENDLOOP.


ENDFORM.                    " UPLOAD_FILE
*&---------------------------------------------------------------------
*
*&      Form  PROCESS_ERROR
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*      -->P_WA_BKPF-BELNR  text
*
*      -->P_WA_BKPF-BKTXT  text
*
*      -->P_WA_BKPF-AWKEY  text
*
*      -->P_TEXT-006  text
*
*----------------------------------------------------------------------
*
FORM PROCESS_ERROR USING   P_VBELN P_BKTXT P_AWKEY P_TEXT.
  CLEAR WA_ERROR.
  WA_ERROR-BELNR = P_VBELN.
  WA_ERROR-BKTXT = P_BKTXT.
  WA_ERROR-AWKEY = P_AWKEY.
  WA_ERROR-TEXT  = P_TEXT.
  APPEND WA_ERROR TO ITAB_ERROR.

ENDFORM.                    " PROCESS_ERROR
*&---------------------------------------------------------------------
*
*&      Form  FILL_BDCTABLE
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM FILL_BDCTABLE.

* fill FB02 first screen data
  PERFORM FIRST_SCREEN.
  PERFORM CHOOSE_ONEITEM.
* process one time customer screen
  IF WA_BKPF-XCPDS = ‘X‘.
    PERFORM ONE_TIME_CUSTOMER.
  ENDIF.

* fill VAT number in customer line item ‘allocation‘ field
  PERFORM CUSTOMER_ITEM.

* fill VAT number in document header text filed
  PERFORM DOC_HEADER.

  IF WA_BKPF-XCPDS = ‘X‘.
    PERFORM ONE_TIME_CUSTOMER.
  ENDIF.

* save FI document
  PERFORM DOC_SAVE.

ENDFORM.                               " FILL_BDCTABLE

*&---------------------------------------------------------------------
*
*&      Form  CALL_TRANSACTION
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM CALL_TRANSACTION.

  CLEAR MESSTAB.
  REFRESH MESSTAB.

  CALL TRANSACTION ‘FB02‘
       USING BDCDATA
*      mode   ‘A‘                      " display screen
*      mode   ‘E‘            " Display screen only if an error occurs
       MODE   ‘N‘                      " No display
       UPDATE ‘S‘                      " Synchronous update
       MESSAGES INTO MESSTAB.

* process error
  IF SY-SUBRC NE 0.

    LOOP AT MESSTAB.
      CLEAR WA_T100.
      SELECT SINGLE * FROM T100 INTO WA_T100
             WHERE SPRSL = MESSTAB-MSGSPRA
               AND ARBGB = MESSTAB-MSGID
               AND MSGNR = MESSTAB-MSGNR.
      REPLACE ‘&1‘ WITH MESSTAB-MSGV1(10INTO WA_T100-TEXT.
      REPLACE ‘&2‘ WITH MESSTAB-MSGV2(10INTO WA_T100-TEXT.
      REPLACE ‘&3‘ WITH MESSTAB-MSGV3(10INTO WA_T100-TEXT.
      REPLACE ‘&4‘ WITH MESSTAB-MSGV4(10INTO WA_T100-TEXT.
      REPLACE ‘&‘  WITH MESSTAB-MSGV1(10INTO WA_T100-TEXT.
      REPLACE ‘&‘  WITH MESSTAB-MSGV2(10INTO WA_T100-TEXT.
      REPLACE ‘&‘  WITH MESSTAB-MSGV3(10INTO WA_T100-TEXT.
      REPLACE ‘&‘  WITH MESSTAB-MSGV4(10INTO WA_T100-TEXT.
      WRITE: / TEXT-011,
               WA_BKPF-BELNR,
               WA_BKPF-BKTXT,
               WA_BKPF-AWKEY,
            /  TEXT-012,
               MESSTAB-MSGTYP(1),
               MESSTAB-MSGID(2),
               MESSTAB-MSGNR(3),
               WA_T100-TEXT(60).

      WA_ERROR-BELNR = WA_BKPF-BELNR.
      WA_ERROR-AWKEY = WA_BKPF-AWKEY.
      WA_ERROR-BKTXT = WA_BKPF-BKTXT.
      WA_ERROR-TEXT  = WA_T100-TEXT.
      APPEND WA_ERROR TO ITAB_ERROR.
    ENDLOOP.
  ENDIF.

ENDFORM.                               " CALL_TRANSACTION
*&---------------------------------------------------------------------
*
*&      Form  DOWNLOAD_ERROR
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM DOWNLOAD_ERROR.

  READ TABLE ITAB_ERROR INTO WA_ERROR INDEX 1.
  IF SY-SUBRC NE 0.
    WRITE: / ‘VAT number upload successfully!‘(001).
  ELSE.
    WRITE: / ‘Pls check the error log !‘(002).
*    CALL FUNCTION ‘WS_DOWNLOAD‘
*         EXPORTING
**         BIN_FILESIZE            = ‘ ‘
**         CODEPAGE                = ‘ ‘
*          FILENAME                = ERR_FILE
*          FILETYPE                = ‘DAT‘
**         MODE                    = ‘ ‘
**         WK1_N_FORMAT            = ‘ ‘
**         WK1_N_SIZE              = ‘ ‘
**         WK1_T_FORMAT            = ‘ ‘
**         WK1_T_SIZE              = ‘ ‘
**         COL_SELECT              = ‘ ‘
**         COL_SELECTMASK          = ‘ ‘
**         NO_AUTH_CHECK           = ‘ ‘
**    IMPORTING
**         FILELENGTH              =
*         TABLES
*              DATA_TAB                = ITAB_ERROR
**             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
*              GUI_REFUSE_FILETRANSFER = 8
*              OTHERS                  = 9.
*
*    IF SY-SUBRC NE 0.
*      MESSAGE E059 WITH ERR_FILE .
*    ENDIF.
  ENDIF.

ENDFORM.                               " DOWNLOAD_ERROR
*&---------------------------------------------------------------------
*
*&      Form  FIRST_SCREEN
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM FIRST_SCREEN.

  PERFORM BDC_DYNPRO      USING ‘SAPMF05L‘ ‘0100‘.  "transactionFB02
  PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                ‘/00‘.
  PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                ‘RF05L-AWTYP‘.
  PERFORM BDC_FIELD       USING ‘RF05L-BELNR‘
                                WA_BKPF-BELNR.     "   ‘2200000042‘.
  PERFORM BDC_FIELD       USING ‘RF05L-BUKRS‘
                                WA_BKPF-BUKRS.              "   ‘0001‘.
  PERFORM BDC_FIELD       USING ‘RF05L-GJAHR‘
                                WA_BKPF-GJAHR.     "    ‘1999‘.

ENDFORM.                               " FIRST_SCREEN

*&---------------------------------------------------------------------
*
*&      Form  CHOOSE_ONEITEM
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM CHOOSE_ONEITEM.
  DATA: SEL_ITEM LIKE BDCDATA-FVAL.
  MOVE ‘RF05L-ANZDT(‘ TO SEL_ITEM.
  MOVE WA_BKPF-BUZEI+1(2TO SEL_ITEM+12.
  MOVE ‘)‘ TO SEL_ITEM+14.
  PERFORM BDC_DYNPRO  USING ‘SAPMF05L‘ ‘0700‘"transaction
  PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                ‘PK‘.
  PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                SEL_ITEM.

ENDFORM.                    " CHOOSE_ONEITEM


*&---------------------------------------------------------------------
*
*&      Form  DOC_HEADER
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM DOC_HEADER.

  PERFORM BDC_DYNPRO      USING ‘SAPMF05L‘ ‘1710‘.
  PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                ‘=ENTR‘.
  PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                ‘BKPF-BKTXT‘.
  PERFORM BDC_FIELD       USING ‘BKPF-BKTXT‘
                                WA_BKPF-BKTXT.    "     ‘0090000064‘.

ENDFORM.                               " DOC_HEADER

*&---------------------------------------------------------------------
*
*&      Form  CUSTOMER_ITEM
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM CUSTOMER_ITEM.

  PERFORM BDC_DYNPRO      USING ‘SAPMF05L‘ ‘0301‘.
  PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                ‘=VK‘.
  PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                ‘BSEG-ZUONR‘.
  PERFORM BDC_FIELD       USING ‘BSEG-ZUONR‘
                                WA_BKPF-VATNUM.      "  ‘0090000064‘.

ENDFORM.                               " CUSTOMER_ITEM

*&---------------------------------------------------------------------
*
*&      Form  ONE_TIME_CUSTOMER
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM ONE_TIME_CUSTOMER.

  PERFORM BDC_DYNPRO      USING ‘SAPLFCPD‘ ‘0100‘.
  PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                ‘/00‘.         "‘/ECNC‘.
  PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                ‘BSEC-NAME1‘.

ENDFORM.                               " ONE_TIME_CUSTOMER

*&---------------------------------------------------------------------
*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*      -->P_0572   text
*
*      -->P_0573   text
*
*----------------------------------------------------------------------
*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = ‘X‘.
  APPEND BDCDATA.

ENDFORM.                               " BDC_DYNPRO


*---------------------------------------------------------------------*
*       FORM BDC_FIELD                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  FNAM                                                          *
*  -->  FVAL                                                          *
*---------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  CLEAR BDCDATA.
  BDCDATA-FNAM = FNAM.
  BDCDATA-FVAL = FVAL.
  APPEND BDCDATA.
ENDFORM.                    "BDC_FIELD

*&---------------------------------------------------------------------
*
*&      Form  DOC_SAVE
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM DOC_SAVE.

  PERFORM BDC_DYNPRO      USING ‘SAPMF05L‘ ‘0301‘.
  PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                ‘=AE‘.
  PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                ‘BSEG-ZUONR‘.

ENDFORM.                               " DOC_SAVE
*&---------------------------------------------------------------------
*
*&      Form  get_upfile
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM GET_UPFILE.
*data: lin_invoice type linvoice.
  DATA: IDX LIKE SY-TABIX VALUE ‘1‘.
  DATA: LEN LIKE SY-FDPOS,
        OFF LIKE SY-FDPOS.
* the definition is follow the ‘jingshui‘.
  DATA: P_INVOICE(8TYPE C,
        P_DATE LIKE SY-DATUM,
        P_ITEMNUM(3TYPE N,
        P_BILLING LIKE VBRK-VBELN.
  DATA: P_BILLBAK(10TYPE N.   "used for c-->n-->c. reference vbrk-vbeln
  DATA: P_BKTXT LIKE BKPF-BKTXT.
  DATA: DELETE_FLAG(1TYPE C.
  REFRESH: ITAB_BKPF.
*获取第一行判断文件是否税控下载的.
*  READ TABLE ITAB_INVOICE INTO LIN_INVOICE INDEX 1.
*  IF LIN_INVOICE(8) <> ‘SJJK0201‘.
*    MESSAGE E219.
*  ENDIF.
*获取第二行第一个字段,得到发票数量.
*  READ TABLE ITAB_INVOICE INTO LIN_INVOICE INDEX 2.
*  SEARCH LIN_INVOICE FOR ‘~~‘ .
  DESCRIBE TABLE ITAB_INVOICE1 LINES TABLE_LINES.
  TOTAL = TABLE_LINES.
  CLEAR IDX.
*  REFRESH IT_INVOICE.
*  LOOP AT ITAB_INVOICE INTO LIN_INVOICE.
*    IDX = IDX + 1.
  CLEAR : OFF, LEN, P_DATE, P_INVOICE, P_BKTXT, P_ITEMNUM.
  CLEAR: DELETE_FLAG, WA_BSEG, WA_BKPF.
*  READ TABLE ITAB_INVOICE INDEX IDX INTO LIN_INVOICE.
*  IF SY-SUBRC <> 0. MESSAGE E058 WITH VAT_FILE . ENDIF. "
*添加发票抬头行到内表it_invoice中.
*    IF ( LIN_INVOICE(1) = ‘0‘ OR LIN_INVOICE(1) = ‘1‘ )
*       AND ( LIN_INVOICE+3(1) = ‘0‘ OR LIN_INVOICE+3(1) = ‘1‘ )
*       AND ( LIN_INVOICE+6(1) = ‘0‘ OR LIN_INVOICE+6(1) = ‘1‘ )  .
*      APPEND LIN_INVOICE TO IT_INVOICE.
*    ENDIF.
*  ENDLOOP.
*  DESCRIBE TABLE IT_INVOICE LINES TABLE_LINES.
*  IF TABLE_LINES <> TOTAL OR TABLE_LINES = 0.
*    MESSAGE E072(ZI).
*  ENDIF.

*****************处理数据dingyang20131211
  LOOP AT ITAB_INVOICE1.
*Vat发票号码
    WA_BKPF-VATNUM = ITAB_INVOICE1-FPH.
*系统发票号码9开头

* CONVERSION_EXIT_ALPHA_INPUT  增加数字前的0
    CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
      EXPORTING
        INPUT  = ITAB_INVOICE1-VBELN
      IMPORTING
        OUTPUT = ITAB_INVOICE1-VBELN
      EXCEPTIONS
        OTHERS = 1.
    WA_BKPF-AWKEY = ITAB_INVOICE1-VBELN.
**合并发票类型和号码
    CONCATENATE ITAB_INVOICE1-LX ITAB_INVOICE1-FPH INTO WA_BKPF-VATNUM.

    SELECT SINGLE BUKRS BELNR GJAHR AWKEY
             INTO CORRESPONDING FIELDS OF WA_BKPF  FROM BKPF
             WHERE AWTYP = ‘VBRK‘   "FI document header
              AND  AWKEY  = WA_BKPF-AWKEY.
    IF SY-SUBRC <> 0.
      MESSAGE E057 WITH VAT_FILE.
    ENDIF.
    MOVE WA_BKPF-VATNUM TO WA_BKPF-BKTXT(10).
*  MOVE P_DATE TO WA_BKPF-BKTXT+11(8).
    CONDENSE WA_BKPF-BKTXT.
    APPEND WA_BKPF TO ITAB_BKPF.
  ENDLOOP.
*****************处理数据dingyang20131211
*  LOOP AT IT_INVOICE INTO LIN_INVOICE.
*    CLEAR: OFF ,LEN,SEARCHED.
*    WA_BKPF-BAD = LIN_INVOICE(1).
*    OFF = 1.
*
*    DO 10 TIMES .
*      SEARCH LIN_INVOICE FOR ‘~~‘ STARTING AT OFF.
*      IF SY-SUBRC = 0.
*        LEN = SY-FDPOS.
*        OFF = OFF - 1.
*        IF SEARCHED = 3.
*          BILLTYPE = LIN_INVOICE+OFF(LEN).  "vat发票类型
*        ELSEIF SEARCHED = 4.
*          INVONO = LIN_INVOICE+OFF(LEN).
*          II = 8 - STRLEN( LIN_INVOICE+OFF(LEN) ).
*          DO II TIMES.
*            CONCATENATE ‘0‘ INVONO INTO INVONO.
*          ENDDO.
*          CONCATENATE BILLTYPE  INVONO INTO WA_BKPF-VATNUM.
**Vat发票号码
*        ELSEIF SEARCHED = 6.
*          P_DATE = LIN_INVOICE+OFF(LEN).     "vat发票日期
*        ELSEIF SEARCHED = 8.
*          WA_BKPF-AWKEY = LIN_INVOICE+OFF(LEN). "系统发票号码
*        ENDIF.
*        SEARCHED = SEARCHED + 1.
*        OFF = OFF + 1.
*        OFF = OFF + 2.
*        OFF = OFF + LEN .
*      ENDIF.
*    ENDDO.
*    SELECT SINGLE BUKRS BELNR GJAHR AWKEY
*          INTO CORRESPONDING FIELDS OF WA_BKPF  FROM BKPF
*          WHERE AWTYP = ‘VBRK‘   "FI document header
*          AND  AWKEY  = WA_BKPF-AWKEY.
*    IF SY-SUBRC <> 0.
*      MESSAGE E057 WITH P_BILLING VAT_FILE.
*    ENDIF.
*    MOVE WA_BKPF-VATNUM TO WA_BKPF-BKTXT(10).
*    MOVE P_DATE TO WA_BKPF-BKTXT+11(8).
*    CONDENSE WA_BKPF-BKTXT.
*    APPEND WA_BKPF TO ITAB_BKPF.
*    IF WA_BKPF-BAD = ‘1‘.
*      SELECT SINGLE VBELN FROM VBRK INTO ITAB_BKPF-AWKEY
*          WHERE SFAKN = WA_BKPF-AWKEY.
*      SELECT SINGLE BUKRS BELNR GJAHR AWKEY
*            INTO CORRESPONDING FIELDS OF ITAB_BKPF  FROM BKPF
*            WHERE AWTYP = ‘VBRK‘   "FI document header
*            AND  AWKEY  = ITAB_BKPF-AWKEY.
*      IF SY-SUBRC <> 0.
*        MESSAGE E057 WITH P_BILLING VAT_FILE.
*      ENDIF.
*      MOVE ITAB_BKPF-VATNUM TO ITAB_BKPF-BKTXT(10).
*      MOVE P_DATE TO ITAB_BKPF-BKTXT+11(8).
*      CONDENSE ITAB_BKPF-BKTXT.
*      APPEND  ITAB_BKPF.
*    ENDIF.
*  ENDLOOP.
ENDFORM.                    " get_upfile
*&---------------------------------------------------------------------
*
*&      Form  update_table
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM UPDATE_TABLE.
  LOOP AT ITAB_BKPF INTO WA_BKPF.
*    update bkpf set bktxt = wa_bkpf-bktxt
    UPDATE BKPF SET BKTXT = WA_BKPF-VATNUM
       WHERE BUKRS = WA_BKPF-BUKRS
         AND GJAHR = WA_BKPF-GJAHR
         AND BELNR = WA_BKPF-BELNR.
    IF SY-SUBRC = 0.
*      UPDATE bseg SET zuonr = wa_bkpf-vatnum
*        WHERE bukrs = wa_bkpf-bukrs
*         AND gjahr = wa_bkpf-gjahr
*         AND belnr = wa_bkpf-belnr
*         AND kunnr <> ‘ ‘.
*      UPDATE bsid SET zuonr = wa_bkpf-vatnum
*         WHERE bukrs = wa_bkpf-bukrs
*         AND gjahr = wa_bkpf-gjahr
*         AND belnr = wa_bkpf-belnr.
*      UPDATE bsad SET zuonr = wa_bkpf-vatnum
*         WHERE bukrs = wa_bkpf-bukrs
*         AND gjahr = wa_bkpf-gjahr
*         AND belnr = wa_bkpf-belnr.
    ENDIF.
  ENDLOOP.
  MESSAGE I211.
  LEAVE PROGRAM.
ENDFORM.                    " update_table

abap金税上传EXCEL版

标签:abap金税上传   abap金税下载   

原文地址:http://blog.csdn.net/champaignwolf/article/details/45363711

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!