FICO 会计凭证批量导入

REPORT ZFINR_084.
 TABLES:SSCRFIELDS.

 TYPES:BEGIN OF TY_TAB,
         ZIDX(4),
         BUKRS(4),"  公司代码
        BLART(2),"  凭证类型
        BLDAT(8),"  凭证日期
        BUDAT(8),"  记帐日期
        WAERS(5),"  交易货币
        XBLNR(16)," 参考凭证号
        BKTXT(25)," 凭证抬头文本
        KURSF(9),"(5位小数)  汇率
        BSCHL(2),"  记帐码
        UMSKZ(2)  ,"特别总帐标志
        ANBWA(3),"  交易类型
        HKONT(10)," 总账科目
        KUNNR(10)," 客户
        LIFNR(10)," 供应商
        ANLN1(12)," 资产
        WRBTR(13),"(2位小数) 交易货币金额
        DMBTR(13),"(2位小数) 本位币金额
        MWSKZ(2),"  税码
        WMWST(13),"(2位小数) 凭证货币税额
        RSTGR(3),"  原因代码
        ZZBY01(10),"  辅助核算
        VBUND(6),"  贸易伙伴
        VALUT(8),"  起息日
        ZUONR(18)," 分配
        SGTXT(50)," 项目文本
        ZLSCH(1),"  付款方式
        ZTERM(4),"  付款条件
        ZFBDT(8),"  付款基准日期
        XREF3(20)," 参考码3
         HBKID(5),"  开户银行
        HKTID(5),"  帐户标识
        ZZBY11(22),"  票号/合同号1
         ZZBY12(22),"  票号/合同号2
         ZZBY1(8)  ,"票据/合同号到期日
        KOSTL(10)," 成本中心
        PROJK(8)  ,"项目WBS
         AUFNR(12)," 内部订单
        PAOBJNR(10)," 获利能力分析
        ZINFOR(100),
         BELNR       TYPE BSEG-BELNR,
       END OF TY_TAB.

 TYPES:BEGIN OF TY_TABA,
         ZIDX(4),
         BUKRS       TYPE BKPF-BUKRS , "  公司代码
        BLART       TYPE BKPF-BLART , "  凭证类型
        BLDAT       TYPE BKPF-BLDAT , "  凭证日期
        BUDAT       TYPE BKPF-BUDAT , "  记帐日期
        WAERS       TYPE BKPF-WAERS , "  交易货币
        XBLNR       TYPE BKPF-XBLNR , "  参考凭证号
        BKTXT       TYPE BKPF-BKTXT , "  凭证抬头文本
        KURSF       TYPE BKPF-KURSF , "  汇率
        BSCHL       TYPE BSEG-BSCHL , "  记帐码
        UMSKZ       TYPE BSEG-UMSKZ , "  特别总帐标志
        HKONT       TYPE BSEG-HKONT , "  总账科目
        KUNNR       TYPE BSEG-KUNNR , "  客户
        LIFNR       TYPE BSEG-LIFNR , "  供应商
        WRBTR       TYPE BSEG-WRBTR , "  交易货币金额
        DMBTR       TYPE BSEG-DMBTR , "  本位币金额
        MWSKZ       TYPE BSEG-MWSKZ , "  税码
        WMWST       TYPE BSEG-WMWST , "  凭证货币税额
        RSTGR       TYPE BSEG-RSTGR , "  原因代码
        ZZBY01      TYPE BSEG-ZZBY01 , "  辅助核算
        VBUND       TYPE BSEG-VBUND , "  贸易伙伴
        VALUT       TYPE BSEG-VALUT , "  起息日
        ZUONR       TYPE BSEG-ZUONR , "  分配
        SGTXT       TYPE BSEG-SGTXT , "  项目文本
        ZLSCH       TYPE BSEG-ZLSCH , "  付款方式
        ZTERM       TYPE BSEG-ZTERM, "   付款条件
        ZFBDT       TYPE BSEG-ZFBDT, "   付款基准日期
        XREF3       TYPE BSEG-XREF3, "   参考码3
         HBKID       TYPE BSEG-HBKID, "   开户银行
        HKTID       TYPE BSEG-HKTID, "   帐户标识
        ZZBY11      TYPE BSEG-ZZBY11 , "  票号/合同号1
         ZZBY12      TYPE BSEG-ZZBY12 , "  票号/合同号2
         ZZBY1       TYPE BSEG-ZZBY1, "   票据/合同号到期日
        KOSTL       TYPE BSEG-KOSTL, "   成本中心
        PROJK       TYPE BSEG-PROJK, "   项目WBS
         AUFNR       TYPE BSEG-AUFNR, "   内部订单
        PAOBJNR     TYPE BSEG-PAOBJNR , "  获利能力分析
        ZINFOR(100),
         BELNR       TYPE BSEG-BELNR,
       END OF TY_TABA.



*&---根据记账码判断金额正负


TYPES: BEGIN OF TY_TBSL ,
          BSCHL TYPE TBSL-BSCHL,
          SHKZG TYPE TBSL-SHKZG,
          KOART TYPE TBSL-KOART,
        END OF TY_TBSL .


 DATA: GT_TBSL TYPE TABLE OF TY_TBSL,
       GS_TBSL TYPE TY_TBSL.



*&---取出对应公司代码下的本位币


TYPES: BEGIN OF TY_T001 ,
          BUKRS TYPE T001-BUKRS,
          WAERS TYPE T001-WAERS,
        END OF TY_T001 .
 DATA: GT_T001 TYPE TABLE OF TY_T001,
       GS_T001 TYPE TY_T001.


 DATA:GT_TABA TYPE TABLE OF TY_TAB,
      GS_TABA TYPE TY_TAB.
 FIELD-SYMBOLS: <FS_TAB> TYPE TY_TABA.
 DATA:GT_TAB TYPE STANDARD TABLE OF TY_TABA,
      GS_TAB TYPE TY_TABA.
 DATA:GT_TAB1 TYPE TABLE OF TY_TABA,
      GS_TAB1 TYPE TY_TABA.
 DATA:GT_TAB2 TYPE TABLE OF TY_TABA,
      GS_TAB2 TYPE TY_TABA.
 DATA:GT_TAB3 TYPE TABLE OF TY_TABA,
      GS_TAB3 TYPE TY_TABA.
 DATA:GT_TAB4 TYPE STANDARD TABLE OF TY_TABA,
      GS_TAB4 TYPE TY_TABA.
 DATA:GT_DATA TYPE STANDARD TABLE OF ZSEXCEL WITH HEADER LINE .


* 全局变量 上传文件


DATA: GV_FULLPATH TYPE STRING, "路径文件
      GV_PATH     TYPE STRING,  "路径
      GV_NAME     TYPE STRING.  "文件名字


* 上传数据


DATA: LT_FILENAME TYPE RLGRAP-FILENAME,
       LT_DATA     TYPE TRUXS_T_TEXT_DATA.
 FIELD-SYMBOLS: <FS>.


*&币别,汇率行项目


DATA :LV_WAERS TYPE BKPF-WAERS , " 交易货币
      LV_KURSF TYPE BKPF-KURSF . "  汇率


*&是否执行过账


DATA LV_CHECK(1).


*&生成会计凭证
*---------------------------------------------------------------------*
 * ALV                                                                 *
 *                                                                     *
 *---------------------------------------------------------------------*


DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
       GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
       GS_LAYOUT   TYPE SLIS_LAYOUT_ALV.

 DATA : DOCUMENTHEADER TYPE BAPIACHE09,
        GT_CURRENCYAMOUNT    TYPE TABLE OF BAPIACCR09 , "货币行项目
       GS_CURRENCYAMOUNT    TYPE  BAPIACCR09 , "货币行项目
       GT_ACCOUNTGL         TYPE TABLE OF BAPIACGL09, "总账科目项
       GS_ACCOUNTGL         TYPE  BAPIACGL09, "总账科目项
       GT_ACCOUNTPAYABLE    TYPE TABLE OF BAPIACAP09, "供应商
       GS_ACCOUNTPAYABLE    TYPE BAPIACAP09, "供应商
       GT_ACCOUNTRECEIVABLE TYPE TABLE OF BAPIACAR09,
        GS_ACCOUNTRECEIVABLE TYPE BAPIACAR09,
        GT_ACCOUNTTAX        LIKE TABLE OF BAPIACTX09, "税
       GS_ACCOUNTTAX        LIKE  BAPIACTX09,
        GT_EXTENSION2        TYPE TABLE OF BAPIPAREX, "增强
       GS_EXTENSION2        TYPE  BAPIPAREX, "增强
       ZACC_DOCUMENT        TYPE ZSFIN_ZACC_DOCUMENT,
        GT_RETURN            TYPE TABLE OF BAPIRET2,
        GS_RETURN            TYPE  BAPIRET2.
 DATA LV_NUM TYPE I VALUE 0. " 凭证行项目编号

DATA: GS_FUNX TYPE SMP_DYNTXT. "选择屏幕按钮

"宏定义
DEFINE INIT_FIELDCAT.
   CLEAR GS_FIELDCAT.
    &1 = &1 + 1 .
   GS_FIELDCAT-COL_POS          = &1.
   GS_FIELDCAT-FIELDNAME        = &2.
   GS_FIELDCAT-SELTEXT_L        = &3.
   APPEND GS_FIELDCAT TO GT_FIELDCAT.
 END-OF-DEFINITION.
 DATA:L_COLPOS TYPE LVC_S_FCAT-COL_POS VALUE 0.



*---------------------------------------------------------------------*
 * Selection-screen                                                    *
 *     选择屏幕                                                         *
 *---------------------------------------------------------------------*


SELECTION-SCREEN: FUNCTION KEY 1,BEGIN OF BLOCK BLK0.


*SELECTION-SCREEN BEGIN OF BLOCK BLK0 WITH FRAME .     "设置一个标题


PARAMETERS:P_PATH LIKE RLGRAP-FILENAME." MEMORY ID M1 MODIF ID M1. "文件上载

SELECTION-SCREEN END OF BLOCK BLK0.


*-----------------------------------------------------------------------
 *初始化
*-----------------------------------------------------------------------
****************************激活下载模板***************************************




INITIALIZATION.
   GS_FUNX-ICON_ID = ICON_NEXT_PAGE.
   GS_FUNX-ICON_TEXT =  '下载模板'.
   SSCRFIELDS-FUNCTXT_01 = GS_FUNX.  "定义按钮



*---------------------------------------------------------------------*
 * At selection-screen                                                 *
 *                                                                     *
 *---------------------------------------------------------------------*


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PATH.
   PERFORM FRM_BROWSER_FILE.  "上传文件地址索引

AT SELECTION-SCREEN.
   CASE SSCRFIELDS-UCOMM.          "处理按钮命令
    WHEN 'FC01'.
       PERFORM FRM_GET_FULLPATH CHANGING GV_FULLPATH GV_PATH GV_NAME.


*路径为空则退出


      IF GV_FULLPATH IS INITIAL.
         MESSAGE S009(ZFIN01) .   "用户取消操作
        RETURN.
       ENDIF.
       PERFORM FRM_DOWNLOAD_TEMPLATE_CREATE USING GV_FULLPATH.  "下载导入文件模板

  ENDCASE.


*---------------------------------------------------------------------*
 * Start-of-selection                                                  *
 *                                                                     *
 *---------------------------------------------------------------------*


START-OF-SELECTION.

   "提示选择导入文件
  IF P_PATH IS INITIAL .
     MESSAGE  E010(ZFIN01).   "请选择导入文件
  ENDIF.
   "判断文件路径不为空
  IF  P_PATH IS NOT INITIAL.
     PERFORM FRM_UPLOAD_DATA  . "上传数据
    IF GT_DATA IS INITIAL.
       MESSAGE E011(ZFIN01).  "上传数据不能为空

    ENDIF.

     IF GT_TAB IS NOT INITIAL.
       PERFORM FRM_GET_DATA.


*alv数据导入


      PERFORM FRM_ALV_LAYOUT.
       PERFORM FRM_ALV_FIELDCAT.
       PERFORM FRM_ALV_DISPLAY .
     ENDIF.
   ENDIF.


*&---------------------------------------------------------------------*
 *& Form FRM_BROWSER_FILE
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *& -->  p1        text
 *& <--  p2        text
 *&---------------------------------------------------------------------*


FORM FRM_BROWSER_FILE .

   CALL FUNCTION 'TB_LIMIT_WS_FILENAME_GET'
     IMPORTING
       FILENAME         = P_PATH
     EXCEPTIONS
       SELECTION_CANCEL = 1
       SELECTION_ERROR  = 2
       OTHERS           = 3.
   IF SY-SUBRC <> 0.


* Implement suitable error handling here


  ENDIF.
 ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_UPLOAD_DATA
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *& -->  p1        text
 *& <--  p2        text
 *&---------------------------------------------------------------------*


FORM FRM_UPLOAD_DATA .

   LT_FILENAME = P_PATH.   "路径
  call function 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
     EXPORTING
       FILENAME                = LT_FILENAME
       I_BEGIN_COL             = '2'
       I_BEGIN_ROW             = '8'
       I_END_COL               = '50'
       I_END_ROW               = '1100'
     TABLES
       INTERN                  = GT_DATA
     EXCEPTIONS
       INCONSISTENT_PARAMETERS = 1
       UPLOAD_OLE              = 2
       OTHERS                  = 3.

   IF GT_DATA[] IS INITIAL.
     MESSAGE E361(ZFIN01)."  '清单中无数据'.
   ENDIF.

   LOOP AT GT_DATA .                    "添加至内表

    AT NEW ROW.
       CLEAR GS_TAB.
     ENDAT .

     ASSIGN COMPONENT GT_DATA-COL OF STRUCTURE  GS_TAB TO <FS>."分配
    <FS> =  GT_DATA-VALUE."赋值

    AT END OF ROW.
       APPEND GS_TAB TO GT_TAB.
     ENDAT.

   ENDLOOP.
 ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_GET_FULLPATH
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *      <--P_GV_FULLPATH  text
 *      <--P_GV_PATH  text
 *      <--P_GV_NAME  text   下载模版
*&---------------------------------------------------------------------*


FORM FRM_GET_FULLPATH CHANGING PV_FULLPATH TYPE STRING
                                  PV_PATH     TYPE STRING
                                  PV_NAME     TYPE STRING.
   DATA: LV_INIT_PATH  TYPE STRING,
         LV_INIT_FNAME TYPE STRING,
         LV_PATH       TYPE STRING,
         LV_FILENAME   TYPE STRING,
         LV_FULLPATH   TYPE STRING.



* 初始名称(输出的文件名称)


  LV_INIT_FNAME = TEXT-040.



* 获取桌面路径


  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY
     CHANGING
       DESKTOP_DIRECTORY    = LV_INIT_PATH
     EXCEPTIONS
       CNTL_ERROR           = 1
       ERROR_NO_GUI         = 2
       NOT_SUPPORTED_BY_GUI = 3
       OTHERS               = 4.
   IF SY-SUBRC <> 0.
     EXIT.
   ENDIF.



* 用户选择名称、路径


  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
     EXPORTING


*     WINDOW_TITLE         = '指定保存文件名'
 *     DEFAULT_EXTENSION    = 'DOC'


      DEFAULT_FILE_NAME    = LV_INIT_FNAME


*     FILE_FILTER          = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
 *     FILE_FILTER          = CL_GUI_FRONTEND_SERVICES=>FILETYPE_WORD


      INITIAL_DIRECTORY    = LV_INIT_PATH
       PROMPT_ON_OVERWRITE  = 'X'
     CHANGING
       FILENAME             = LV_FILENAME
       PATH                 = LV_PATH
       FULLPATH             = LV_FULLPATH


*     USER_ACTION          =
 *     FILE_ENCODING        =


    EXCEPTIONS
       CNTL_ERROR           = 1
       ERROR_NO_GUI         = 2
       NOT_SUPPORTED_BY_GUI = 3
       OTHERS               = 4.
   IF SY-SUBRC = 0.
     PV_FULLPATH = LV_FULLPATH.
     PV_PATH     = LV_PATH.
   ENDIF.

 ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_DOWNLOAD_TEMPLATE_CREATE
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *      -->P_GV_FULLPATH  下载导入文件模板
*&---------------------------------------------------------------------*


FORM FRM_DOWNLOAD_TEMPLATE_CREATE USING PV_FILENAME.

   DATA: LV_OBJDATA     LIKE WWWDATATAB,
         LV_MIME        LIKE W3MIME,
         LV_DESTINATION LIKE RLGRAP-FILENAME,
         LV_OBJNAM      TYPE STRING,
         LV_RC          LIKE SY-SUBRC,
         LV_ERRTXT      TYPE STRING.

   DATA: LV_FILENAME TYPE STRING,
         LV_RESULT,
         LV_SUBRC    TYPE SY-SUBRC.

   DATA: LV_OBJID TYPE WWWDATATAB-OBJID .

   LV_OBJID = 'ZFINR_084'.   "上传的模版名称

  "查找文件是否存在。
  SELECT SINGLE
     RELID             "IMPORT/EXPORT 记录中的区域
    OBJID            "SAP WWW 网关对象名
    FROM WWWDATA     "存储 WWW 对象的 INDX 类型表
    INTO CORRESPONDING FIELDS OF LV_OBJDATA
     WHERE SRTF2 = 0       "EXPORT/IMPORT 数据表中的下个记录计数器
    AND   RELID = 'MI'
   AND   OBJID = LV_OBJID.

   "判断模版不存在则报错 检查表wwwdata中是否存在所指定的模板文件
  IF SY-SUBRC <> 0 OR LV_OBJDATA-OBJID = SPACE.
     CONCATENATE '模板文件:' LV_OBJID '不存在,请用TCODE:SMW0进行加载'
     INTO LV_ERRTXT.
     MESSAGE E000(ZFIN01) WITH LV_ERRTXT.
   ENDIF.

   LV_FILENAME = PV_FILENAME.  "保存路径

  "判断本地地址是否已经存在此文件。
  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
     EXPORTING
       FILE                 = LV_FILENAME
     RECEIVING
       RESULT               = LV_RESULT
     EXCEPTIONS
       CNTL_ERROR           = 1
       ERROR_NO_GUI         = 2
       WRONG_PARAMETER      = 3
       NOT_SUPPORTED_BY_GUI = 4
       OTHERS               = 5.
   IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
   IF LV_RESULT = 'X'.  "如果存在则删除原始文件,重新覆盖
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_DELETE
       EXPORTING
         FILENAME = LV_FILENAME
       CHANGING
         RC       = LV_SUBRC


*      EXCEPTIONS
 *       FILE_DELETE_FAILED   = 1
 *       CNTL_ERROR           = 2
 *       ERROR_NO_GUI         = 3
 *       FILE_NOT_FOUND       = 4
 *       ACCESS_DENIED        = 5
 *       UNKNOWN_ERROR        = 6
 *       NOT_SUPPORTED_BY_GUI = 7
 *       WRONG_PARAMETER      = 8
 *       OTHERS   = 9


      .
     IF LV_SUBRC <> 0. "如果删除失败,则报错。
      CONCATENATE '同名EXCEL文件已打开' '请关闭该EXCEL后重试。'
       INTO LV_ERRTXT.
       MESSAGE E000(ZFIN01) WITH LV_ERRTXT.


*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.


    ENDIF.
   ENDIF.

   LV_DESTINATION   = PV_FILENAME.

   "下载模版 如果存在,调用DOWNLOAD_WEB_OBJECT 函数下载模板到路径下
  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
     EXPORTING
       KEY         = LV_OBJDATA
       DESTINATION = LV_DESTINATION
     IMPORTING
       RC          = LV_RC


*    CHANGING
 *     TEMP        =


    .
   IF LV_RC NE 0.
     CONCATENATE '模板文件' '下载失败' INTO LV_ERRTXT.
     MESSAGE E000(ZFIN01) WITH LV_ERRTXT.
   ENDIF.
 ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_GET_DATA
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *& -->  p1        text
 *& <--  p2        text
 *&---------------------------------------------------------------------*


FORM FRM_GET_DATA .
   DATA LV_ID(4).
   SELECT BUKRS
          WAERS
     INTO CORRESPONDING FIELDS OF TABLE GT_T001
     FROM T001
     FOR ALL ENTRIES IN GT_TAB
   WHERE BUKRS = GT_TAB-BUKRS .
   SORT GT_T001 BY BUKRS .
   DELETE ADJACENT DUPLICATES FROM GT_T001 COMPARING BUKRS .


   SELECT BSCHL
          SHKZG
          KOART
     INTO CORRESPONDING FIELDS OF TABLE GT_TBSL
     FROM TBSL
      FOR ALL ENTRIES IN GT_TAB
   WHERE BSCHL = GT_TAB-BSCHL .
   SORT GT_TBSL BY BSCHL .


*&---凭证数据整理


  APPEND LINES OF GT_TAB TO GT_TAB1.
   " SORT GT_TAB1 BY ZIDX bukrs .
   SORT GT_TAB1 BY  ZIDX ASCENDING  BUKRS DESCENDING.
   DELETE ADJACENT DUPLICATES FROM GT_TAB1 COMPARING ZIDX.

   LOOP AT GT_TAB1 ASSIGNING <FS_TAB>.
     CLEAR LV_ID.
     CLEAR LV_WAERS.
     CLEAR LV_KURSF.
     AT NEW ZIDX.
       CLEAR: DOCUMENTHEADER.
       REFRESH: GT_CURRENCYAMOUNT,
                GT_ACCOUNTGL,
                GT_ACCOUNTPAYABLE,
                GT_ACCOUNTRECEIVABLE,
                GT_ACCOUNTTAX,
                GT_EXTENSION2,
                GT_RETURN.

       DOCUMENTHEADER-COMP_CODE  = <FS_TAB>-BUKRS.        " 公司代码
      DOCUMENTHEADER-DOC_DATE   = <FS_TAB>-BLDAT.        " 凭证日期
      DOCUMENTHEADER-PSTNG_DATE = <FS_TAB>-BUDAT.        " 记账日期
      DOCUMENTHEADER-FISC_YEAR = <FS_TAB>-BUDAT+0(4).        " 财年
      DOCUMENTHEADER-DOC_TYPE   = <FS_TAB>-BLART.        " 凭证类型
      DOCUMENTHEADER-REF_DOC_NO = <FS_TAB>-XBLNR.        " 参照
      DOCUMENTHEADER-HEADER_TXT = <FS_TAB>-BKTXT.        " 凭证抬头文本
      DOCUMENTHEADER-USERNAME   = SY-UNAME.                 " 创建人


*&将index传给变量


      LV_ID = <FS_TAB>-ZIDX.
       LV_WAERS = <FS_TAB>-WAERS.
       LV_KURSF = <FS_TAB>-KURSF.
     ENDAT.

     CLEAR: GS_CURRENCYAMOUNT,
            GS_ACCOUNTGL,
            GS_ACCOUNTPAYABLE,
            GS_ACCOUNTRECEIVABLE,
            GS_EXTENSION2,
            GS_ACCOUNTTAX.



*行项目


    CLEAR <FS_TAB>.
     LOOP AT GT_TAB INTO <FS_TAB> WHERE ZIDX = LV_ID.

       LV_NUM = LV_NUM + 1.



*&-------总账添加前导 0


      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
         EXPORTING
           INPUT  = <FS_TAB>-HKONT
         IMPORTING
           OUTPUT = <FS_TAB>-HKONT.



*&-------成本中心添加前导 0


      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
         EXPORTING
           INPUT  = <FS_TAB>-KOSTL
         IMPORTING
           OUTPUT = <FS_TAB>-KOSTL.


*&-------供应商添加前导 0


      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
         EXPORTING
           INPUT  = <FS_TAB>-LIFNR
         IMPORTING
           OUTPUT = <FS_TAB>-LIFNR.


*&-------客户添加前导 0


      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
         EXPORTING
           INPUT  = <FS_TAB>-KUNNR
         IMPORTING
           OUTPUT = <FS_TAB>-KUNNR.


*&-------内部订单添加前导 0


      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
         EXPORTING
           INPUT  = <FS_TAB>-AUFNR
         IMPORTING
           OUTPUT = <FS_TAB>-AUFNR.


*&-------项目WBS添加前导 0


      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
         EXPORTING
           INPUT  = <FS_TAB>-PROJK
         IMPORTING
           OUTPUT = <FS_TAB>-PROJK.

       IF <FS_TAB>-HKONT IS NOT INITIAL
                                         AND <FS_TAB>-KUNNR IS   INITIAL
                                         AND <FS_TAB>-LIFNR IS INITIAL
                                         AND <FS_TAB>-MWSKZ IS  INITIAL.



         GS_ACCOUNTGL-ITEMNO_ACC = LV_NUM.                          " 行项目编号
        IF <FS_TAB>-KOSTL IS NOT INITIAL.
           GS_ACCOUNTGL-COSTCENTER = <FS_TAB>-KOSTL.                  " 成本中心
        ENDIF.
         IF <FS_TAB>-HKONT IS NOT INITIAL.
           GS_ACCOUNTGL-GL_ACCOUNT = <FS_TAB>-HKONT.                 "总分类帐帐目
        ENDIF.
         IF <FS_TAB>-PROJK NE '00000000'.
           GS_ACCOUNTGL-WBS_ELEMENT = <FS_TAB>-PROJK.                  " 项目WBS
         ENDIF.
         IF <FS_TAB>-AUFNR IS NOT INITIAL.
           GS_ACCOUNTGL-ORDERID  = <FS_TAB>-AUFNR.                  " 内部订单
        ENDIF.
         IF <FS_TAB>-ZUONR IS NOT INITIAL.
           GS_ACCOUNTGL-ALLOC_NMBR = <FS_TAB>-ZUONR.               " 分配
        ENDIF.

         GS_ACCOUNTGL-ITEM_TEXT = <FS_TAB>-SGTXT.            "项目文本

        LOOP AT GT_TAB INTO GS_TAB4 WHERE ZIDX = LV_ID and MWSKZ <> ''.

           GS_ACCOUNTGL-TAX_CODE = GS_TAB4-MWSKZ.                  " 税码
        ENDLOOP.


         APPEND GS_ACCOUNTGL TO GT_ACCOUNTGL.
         CLEAR GS_ACCOUNTGL .
       ENDIF.

       IF <FS_TAB>-KUNNR IS NOT INITIAL.
         GS_ACCOUNTRECEIVABLE-ITEMNO_ACC = LV_NUM.                   " 行项目编号
        IF <FS_TAB>-KUNNR IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-CUSTOMER = <FS_TAB>-KUNNR.          " 客户
        ENDIF.
         IF <FS_TAB>-UMSKZ IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-SP_GL_IND = <FS_TAB>-UMSKZ.         " 特别总账标识
        ENDIF.
         IF <FS_TAB>-HKONT IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-GL_ACCOUNT = <FS_TAB>-HKONT .        " 总账科目
        ENDIF.
         IF <FS_TAB>-VALUT NE '00000000'.
           GS_ACCOUNTRECEIVABLE-BLINE_DATE = <FS_TAB>-VALUT.         " 起息日期
        ENDIF.
         IF <FS_TAB>-ZTERM IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-PMNTTRMS = <FS_TAB>-ZTERM   .        " 付款条件
        ENDIF.
         IF <FS_TAB>-ZLSCH IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-PYMT_METH = <FS_TAB>-ZLSCH   .        " 付款方式
        ENDIF.
         IF <FS_TAB>-ZFBDT NE '00000000'.
           GS_ACCOUNTRECEIVABLE-BLINE_DATE = <FS_TAB>-ZFBDT.         " 付款基准日期
        ENDIF.
         IF <FS_TAB>-XREF3 IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-REF_KEY_3 = <FS_TAB>-XREF3.        " 参考码3
         ENDIF.
         IF <FS_TAB>-HBKID IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-BANK_ID = <FS_TAB>-HBKID.         " 开户银行
        ENDIF.
         IF <FS_TAB>-HKTID IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-HOUSEBANKACCTID = <FS_TAB>-HKTID.        " 帐户标识
        ENDIF.
         IF <FS_TAB>-ZUONR IS NOT INITIAL.
           GS_ACCOUNTRECEIVABLE-ALLOC_NMBR = <FS_TAB>-ZUONR.               " 分配
        ENDIF.
         GS_ACCOUNTRECEIVABLE-ITEM_TEXT = <FS_TAB>-SGTXT.            "项目文本
        APPEND GS_ACCOUNTRECEIVABLE TO GT_ACCOUNTRECEIVABLE.
         CLEAR GS_ACCOUNTRECEIVABLE .
       ENDIF.


       IF <FS_TAB>-LIFNR IS NOT INITIAL.
         GS_ACCOUNTPAYABLE-ITEMNO_ACC = LV_NUM.                   " 行项目编号
        GS_ACCOUNTPAYABLE-VENDOR_NO = <FS_TAB>-LIFNR.      " 供应商
        IF <FS_TAB>-SGTXT IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-ITEM_TEXT = <FS_TAB>-SGTXT.        " 项目文本
        ENDIF.
         IF <FS_TAB>-UMSKZ IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-SP_GL_IND = <FS_TAB>-UMSKZ.         " 特别总账标识
        ENDIF.
         IF <FS_TAB>-HKONT IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-GL_ACCOUNT = <FS_TAB>-HKONT." '2202010000'." <FS_TAB>-HKONT .        " 总账科目
        ENDIF.
         IF <FS_TAB>-VALUT NE '00000000'.
           GS_ACCOUNTPAYABLE-BLINE_DATE = <FS_TAB>-VALUT.         " 起息日期
        ENDIF.
         IF <FS_TAB>-ZTERM IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-PMNTTRMS = <FS_TAB>-ZTERM   .        " 付款条件
        ENDIF.
         IF <FS_TAB>-ZLSCH IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-PYMT_METH = <FS_TAB>-ZLSCH   .        " 付款方式
        ENDIF.
         IF <FS_TAB>-ZFBDT NE '00000000'.
           GS_ACCOUNTPAYABLE-BLINE_DATE = <FS_TAB>-ZFBDT.         " 付款基准日期
        ENDIF.
         IF <FS_TAB>-XREF3 IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-REF_KEY_3 = <FS_TAB>-XREF3.        " 参考码3
         ENDIF.
         IF <FS_TAB>-HBKID IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-BANK_ID = <FS_TAB>-HBKID.         " 开户银行
        ENDIF.
         IF <FS_TAB>-HKTID IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-HOUSEBANKACCTID = <FS_TAB>-HKTID.        " 帐户标识
        ENDIF.
         IF <FS_TAB>-ZUONR IS NOT INITIAL.
           GS_ACCOUNTPAYABLE-ALLOC_NMBR = <FS_TAB>-ZUONR.               " 分配
        ENDIF.

         APPEND GS_ACCOUNTPAYABLE TO GT_ACCOUNTPAYABLE.
         CLEAR GS_ACCOUNTPAYABLE .
       ENDIF.



*&---货币金额


      IF <FS_TAB>-MWSKZ IS  INITIAL.
         IF <FS_TAB>-DMBTR NE '0.00' .
           CLEAR GS_TBSL.
           READ TABLE GT_TBSL INTO GS_TBSL WITH  KEY BSCHL = <FS_TAB>-BSCHL.
           IF SY-SUBRC = 0.
             GS_CURRENCYAMOUNT-ITEMNO_ACC  = LV_NUM.               " 行项目编号
            IF <FS_TAB>-DMBTR NE '0.00' .
               IF GS_TBSL-SHKZG = 'H'.
                 GS_CURRENCYAMOUNT-AMT_DOCCUR  = <FS_TAB>-DMBTR * ( -1 ).    " 本位币货币金额
              ELSE.
                 GS_CURRENCYAMOUNT-AMT_DOCCUR  = <FS_TAB>-DMBTR .    " 本位币货币金额
              ENDIF.
               GS_CURRENCYAMOUNT-CURR_TYPE   = '10'.
               CLEAR GS_T001.
               READ TABLE GT_T001 INTO GS_T001 INDEX 1.
               IF SY-SUBRC = 0.
                 GS_CURRENCYAMOUNT-CURRENCY    = GS_T001-WAERS .        " 本位币货币
              ENDIF.
             ENDIF.
             APPEND GS_CURRENCYAMOUNT TO GT_CURRENCYAMOUNT .
             CLEAR GS_CURRENCYAMOUNT .
           ENDIF.
         ENDIF.

         GS_CURRENCYAMOUNT-ITEMNO_ACC  = LV_NUM.                " 行项目编号
        IF <FS_TAB>-WRBTR NE '0.00'.
           CLEAR GS_TBSL.
           READ TABLE GT_TBSL INTO GS_TBSL WITH  KEY BSCHL = <FS_TAB>-BSCHL.
           IF SY-SUBRC = 0.
             IF GS_TBSL-SHKZG = 'H'.
               GS_CURRENCYAMOUNT-AMT_DOCCUR  = <FS_TAB>-WRBTR * ( -1 ).    " 本位币货币金额
            ELSE.
               GS_CURRENCYAMOUNT-AMT_DOCCUR  = <FS_TAB>-WRBTR .    " 本位币货币金额
            ENDIF.
           ENDIF.
           GS_CURRENCYAMOUNT-CURR_TYPE   = '00'.
         ENDIF.
         IF LV_WAERS IS NOT INITIAL.
           GS_CURRENCYAMOUNT-CURRENCY    = LV_WAERS .    " 凭证货币
        ENDIF.
         IF LV_KURSF NE '0.00000'.
           GS_CURRENCYAMOUNT-EXCH_RATE    = LV_KURSF .    " 汇率
        ENDIF.

         APPEND GS_CURRENCYAMOUNT TO GT_CURRENCYAMOUNT .
         CLEAR GS_CURRENCYAMOUNT .





*&增加字段


        ZACC_DOCUMENT-POSNR = LV_NUM.
         ZACC_DOCUMENT-BSCHL = <FS_TAB>-BSCHL.                 "过账码
        ZACC_DOCUMENT-ZZBY01 = <FS_TAB>-ZZBY01.               " 辅助核算
        ZACC_DOCUMENT-RSTGR = <FS_TAB>-RSTGR.                 "付款原因代码
        ZACC_DOCUMENT-VBUND = <FS_TAB>-VBUND.                 "公司标识
        ZACC_DOCUMENT-ZZBY11 = <FS_TAB>-ZZBY11.               " 票号/合同号1
         ZACC_DOCUMENT-ZZBY12 = <FS_TAB>-ZZBY12.                 "票号/合同号2
         ZACC_DOCUMENT-ZZBY1 = <FS_TAB>-ZZBY1.               " 票据/合同号到期日
        ZACC_DOCUMENT-KOSTL = <FS_TAB>-KOSTL.               " 成本中心

        IF <FS_TAB>-PAOBJNR NE '0000000000'.
           ZACC_DOCUMENT-PAOBJNR = <FS_TAB>-PAOBJNR.               " 获利能力
        ENDIF.
         GS_EXTENSION2-STRUCTURE = 'ZSFIN_ZACC_DOCUMENT'.
         GS_EXTENSION2-VALUEPART1 = ZACC_DOCUMENT  .


         APPEND GS_EXTENSION2 TO GT_EXTENSION2.
         CLEAR GS_EXTENSION2.
       ENDIF.



**     *税额



      IF <FS_TAB>-MWSKZ IS NOT INITIAL.
         " LV_NUM = LV_NUM + 1.
         CLEAR GS_ACCOUNTTAX. "税务项目
        GS_ACCOUNTTAX-ITEMNO_ACC = LV_NUM. "会计凭证行项目编号(有税的会自动新增一行行项目)
         GS_ACCOUNTTAX-TAX_CODE = <FS_TAB>-MWSKZ.                  " 税码
        GS_ACCOUNTTAX-GL_ACCOUNT = <FS_TAB>-HKONT.                 "总分类帐帐目
        APPEND GS_ACCOUNTTAX TO GT_ACCOUNTTAX. "税务项目
        CLEAR GS_ACCOUNTTAX.



         "货币
        GS_CURRENCYAMOUNT-ITEMNO_ACC  = LV_NUM.                " 行项目编号
        IF <FS_TAB>-WMWST NE '0.00' .
           GS_CURRENCYAMOUNT-AMT_DOCCUR  =  <FS_TAB>-WMWST.    " 税额
          GS_CURRENCYAMOUNT-AMT_BASE    = <FS_TAB>-WMWST.    " 税基
        ENDIF.
         IF LV_WAERS IS NOT INITIAL.
           GS_CURRENCYAMOUNT-CURRENCY    = LV_WAERS .    " 凭证货币
        ENDIF.
         IF LV_KURSF IS NOT INITIAL.
           GS_CURRENCYAMOUNT-EXCH_RATE    = LV_KURSF .    " 汇率
        ENDIF.

         APPEND GS_CURRENCYAMOUNT TO GT_CURRENCYAMOUNT .
         CLEAR GS_CURRENCYAMOUNT .



*&增加字段


        ZACC_DOCUMENT-POSNR = LV_NUM.
         ZACC_DOCUMENT-BSCHL = <FS_TAB>-BSCHL.                 "过账码
        ZACC_DOCUMENT-ZZBY01 = <FS_TAB>-ZZBY01.               " 辅助核算
        ZACC_DOCUMENT-RSTGR = <FS_TAB>-RSTGR.                 "付款原因代码
        ZACC_DOCUMENT-VBUND = <FS_TAB>-VBUND.                 "公司标识
        ZACC_DOCUMENT-ZZBY11 = <FS_TAB>-ZZBY11.               " 票号/合同号1
         ZACC_DOCUMENT-ZZBY12 = <FS_TAB>-ZZBY12.                 "票号/合同号2
         ZACC_DOCUMENT-ZZBY1 = <FS_TAB>-ZZBY1.               " 票据/合同号到期日
        ZACC_DOCUMENT-KOSTL = <FS_TAB>-KOSTL.               " 成本中心
        IF <FS_TAB>-PAOBJNR NE '0000000000'.
           ZACC_DOCUMENT-PAOBJNR = <FS_TAB>-PAOBJNR.               " 获利能力
        ENDIF.
         GS_EXTENSION2-STRUCTURE = 'ZSFIN_ZACC_DOCUMENT'.
         GS_EXTENSION2-VALUEPART1 = ZACC_DOCUMENT  .


         APPEND GS_EXTENSION2 TO GT_EXTENSION2.
         CLEAR GS_EXTENSION2.





*        loop  at GT_ACCOUNTGL INTO GS_ACCOUNTGL .
 *          GS_ACCOUNTGL-TAX_CODE = <FS_TAB>-MWSKZ.                  " 税码
*         MODIFY GT_ACCOUNTGL FROM  GS_ACCOUNTGL TRANSPORTING TAX_CODE
 *         COSTCENTER
 *         GL_ACCOUNT
 *         WBS_ELEMENT
 *         ORDERID
 *                 WHERE GL_ACCOUNT = GS_ACCOUNTGL-GL_ACCOUNT .
 *          ENDLOOP.


      ENDIF.
       CLEAR <FS_TAB>.
     ENDLOOP.
     CLEAR LV_NUM.
     IF  LV_CHECK = ''.
       CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
         EXPORTING
           DOCUMENTHEADER    = DOCUMENTHEADER


*         CUSTOMERCPD       =
 *         CONTRACTHEADER    =


        TABLES
           ACCOUNTGL         = GT_ACCOUNTGL
           ACCOUNTRECEIVABLE = GT_ACCOUNTRECEIVABLE
           ACCOUNTPAYABLE    = GT_ACCOUNTPAYABLE
           ACCOUNTTAX        = GT_ACCOUNTTAX
           CURRENCYAMOUNT    = GT_CURRENCYAMOUNT
           RETURN            = GT_RETURN


*         PAYMENTCARD       =
 *         CONTRACTITEM      =


          EXTENSION2        = GT_EXTENSION2


*         REALESTATE        =
 *         ACCOUNTWT         =


        .

       LOOP AT  GT_TAB INTO <FS_TAB> WHERE ZIDX = LV_ID.
         CLEAR GS_RETURN.
         READ TABLE GT_RETURN INTO GS_RETURN WITH KEY TYPE = 'S'.
         "获得消息
        IF SY-SUBRC = 0.
           <FS_TAB>-ZINFOR = '成功'.
           MODIFY GT_TAB FROM <FS_TAB> .
         ELSE.
           READ TABLE GT_RETURN INTO GS_RETURN INDEX 2.
           IF SY-SUBRC = 0.
             <FS_TAB>-ZINFOR = GS_RETURN-MESSAGE+0(100).
             MODIFY GT_TAB FROM <FS_TAB> .
           ENDIF.
         ENDIF.
       ENDLOOP.


     ELSE.

       CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
         EXPORTING
           DOCUMENTHEADER    = DOCUMENTHEADER


*         CUSTOMERCPD       =
 *         CONTRACTHEADER    =


        TABLES
           ACCOUNTGL         = GT_ACCOUNTGL
           ACCOUNTRECEIVABLE = GT_ACCOUNTRECEIVABLE
           ACCOUNTPAYABLE    = GT_ACCOUNTPAYABLE
           ACCOUNTTAX        = GT_ACCOUNTTAX
           CURRENCYAMOUNT    = GT_CURRENCYAMOUNT
           RETURN            = GT_RETURN


*         PAYMENTCARD       =
 *         CONTRACTITEM      =


          EXTENSION2        = GT_EXTENSION2


*         REALESTATE        =
 *         ACCOUNTWT         =


        .
       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
         EXPORTING
           WAIT = 'X'.

       READ TABLE GT_RETURN INTO GS_RETURN WITH KEY TYPE = 'E'.
       IF SY-SUBRC <> 0.
         "获得当凭证号
        READ TABLE GT_RETURN INTO GS_RETURN INDEX 1.
         IF SY-SUBRC = 0.
           LOOP AT  GT_TAB INTO <FS_TAB> WHERE ZIDX = LV_ID.
             <FS_TAB>-BELNR = GS_RETURN-MESSAGE_V2+0(10).
             MODIFY GT_TAB FROM <FS_TAB> .
           ENDLOOP.
         ENDIF.
       ENDIF.
     ENDIF.
   ENDLOOP.


*&判断内表中是否有不可以生成会计凭证的数据


  LOOP AT GT_TAB INTO GS_TAB WHERE ZINFOR NE '成功'.
     MOVE-CORRESPONDING GS_TAB TO GS_TAB3.
     APPEND GS_TAB3 TO GT_TAB3.
   ENDLOOP.
 ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_ALV_LAYOUT
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *& -->  p1        text
 *& <--  p2        text
 *&---------------------------------------------------------------------*


FORM FRM_ALV_LAYOUT .

   GS_LAYOUT-ZEBRA = 'X'.
   GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

 ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_ALV_FIELDCAT
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *& -->  p1        text
 *& <--  p2        text
 *&---------------------------------------------------------------------*


FORM FRM_ALV_FIELDCAT .


   INIT_FIELDCAT:
   L_COLPOS 'ZIDX'   TEXT-001  ," 'INDEX',
   L_COLPOS 'ZINFOR'  TEXT-038  ,"   '消息',
   L_COLPOS 'BELNR'   TEXT-039  ," '凭证编号   '.
   L_COLPOS 'BUKRS'  TEXT-002  ," '公司代码',
   L_COLPOS 'BLART'  TEXT-003  ," '凭证类型',
   L_COLPOS 'BLDAT'  TEXT-004  ," '凭证日期',
   L_COLPOS 'BUDAT'  TEXT-005  ," '记帐日期',
   L_COLPOS 'WAERS'  TEXT-006  ," '交易货币',
   L_COLPOS 'XBLNR'  TEXT-007  ," '参考凭证号',
   L_COLPOS 'BKTXT'  TEXT-008  ," '凭证抬头文本',
   L_COLPOS 'KURSF'  TEXT-009  ," '汇率',
   L_COLPOS 'BSCHL'  TEXT-010  ," '记帐码',
   L_COLPOS 'UMSKZ'  TEXT-011  ," '特别总帐标志',
   L_COLPOS 'HKONT'  TEXT-012  ," '总账科目',
   L_COLPOS 'KUNNR'  TEXT-013  ," '客户',
   L_COLPOS 'LIFNR'  TEXT-014  ," '供应商',
   L_COLPOS 'WRBTR'  TEXT-015  ," '交易货币金额',
   L_COLPOS 'DMBTR'  TEXT-016  ," '本位币金额',
   L_COLPOS 'MWSKZ'  TEXT-017 ," '税码',
   L_COLPOS 'WMWST'  TEXT-018 ," '凭证货币税额',
   L_COLPOS 'RSTGR'  TEXT-019 ," '原因代码',
   L_COLPOS 'ZZBY01' TEXT-020 ,"  '辅助核算',
   L_COLPOS 'VBUND'  TEXT-021 ," '贸易伙伴',
   L_COLPOS 'VALUT'  TEXT-022   ," '起息日',
   L_COLPOS 'ZUONR'  TEXT-023   ," '分配',
   L_COLPOS 'SGTXT'  TEXT-024   ," '项目文本',
   L_COLPOS 'ZLSCH'  TEXT-025   ," '付款方式',
   L_COLPOS 'ZTERM'  TEXT-026   ," '付款条件',
   L_COLPOS 'ZFBDT'  TEXT-027   ," '付款基准日期',
   L_COLPOS 'XREF3'  TEXT-028   ," '参考码3',
   L_COLPOS 'HBKID'  TEXT-029   ," '开户银行',
   L_COLPOS 'HKTID'  TEXT-030    ," '帐户标识',
   L_COLPOS 'ZZBY11' TEXT-031    ," '票号/合同号1',
   L_COLPOS 'ZZBY12' TEXT-032    ," '票号/合同号2',
   L_COLPOS 'ZZBY1'  TEXT-033  ," '票据/合同号到期日',
   L_COLPOS 'KOSTL'   TEXT-034  ," '成本中心',
   L_COLPOS 'PROJK'   TEXT-035  ," '项目WBS',
   L_COLPOS 'AUFNR'   TEXT-036  ," '内部订单',
   L_COLPOS 'PAOBJNR' TEXT-037  ." '获利能力分析',

ENDFORM.


*&---------------------------------------------------------------------*
 *& Form FRM_ALV_DISPLAY
 *&---------------------------------------------------------------------*
 *& text
 *&---------------------------------------------------------------------*
 *& -->  p1        text
 *& <--  p2        text
 *&---------------------------------------------------------------------*


FORM FRM_ALV_DISPLAY .
   DATA:  RS_SELFIELD TYPE SLIS_SELFIELD.
   "刷新
  RS_SELFIELD-REFRESH = 'X'.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       I_CALLBACK_PROGRAM       = SY-REPID
       I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
       I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
       IS_LAYOUT                = GS_LAYOUT
       IT_FIELDCAT              = GT_FIELDCAT
       I_SAVE                   = 'A'
     TABLES
       T_OUTTAB                 = GT_TAB
     EXCEPTIONS
       PROGRAM_ERROR            = 1
       OTHERS                   = 2.
   IF SY-SUBRC <> 0.


* Implement suitable error handling here


  ENDIF.
 ENDFORM.



*&---------------------------------------------------------------------*
 *&      Form  SET_PF_STATUS
 *&---------------------------------------------------------------------*
 *       定义状态条,包括菜单,工具条按钮,系统按钮等
*----------------------------------------------------------------------*
 *      -->RT_EXTAB   text
 *----------------------------------------------------------------------*


FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

   SET PF-STATUS 'STATUS'.
 ENDFORM. "SET_PF_STATUS


*&--------------------------------------------------------------------*
 *&      Form  user_command
 *&--------------------------------------------------------------------*
 *       text
 *---------------------------------------------------------------------*


FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                     RS_SELFIELD TYPE SLIS_SELFIELD.


   CASE R_UCOMM.      "PAI发出的功能代码
    WHEN 'EXIT'.
       LEAVE TO SCREEN 0.
     WHEN 'BACK'.
       LEAVE TO SCREEN 0.

     WHEN 'POST'.
       DATA ANSWER TYPE STRING.  " 应答返回值
      CLEAR ANSWER.
       CLEAR GS_TAB.
       READ TABLE GT_TAB INTO GS_TAB INDEX 1.
       IF SY-SUBRC = 0.
         IF GS_TAB-BELNR IS INITIAL.

           IF GT_TAB3 IS NOT INITIAL .
             CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
               EXPORTING
                 DEFAULTOPTION = 'Y'
                 DIAGNOSETEXT1 = '凭证有错误行项目'  " 标题名


*               DIAGNOSETEXT2 = ' '
 *               DIAGNOSETEXT3 = ' '


                TEXTLINE1     = '是否继续?'  " 内容


*               TEXTLINE2     = ' '


                TITEL         = '警告' " 菜单
                START_COLUMN  = 45
                 START_ROW     = 6


*               CANCEL_DISPLAY       = 'X'


              IMPORTING
                 ANSWER        = ANSWER. " J 是 ,N 否 ,A 取消


*             MESSAGE W384(ZFIN01) .
 *         "  MESSAGE '凭证有错误行项目' type 'S'  DISPLAY LIKE 'E'.


          ENDIF.
           IF ANSWER = 'J' OR ANSWER = ''.
             LV_CHECK = 'X'.
             CLEAR GT_TAB1.
             PERFORM FRM_GET_DATA.

             RS_SELFIELD-COL_STABLE  = 'X'.
             RS_SELFIELD-ROW_STABLE  = 'X'.
             RS_SELFIELD-REFRESH  = 'X'.
           ENDIF.
         ELSE.
           MESSAGE E383(ZFIN01).  "请勿重复过账
        ENDIF.
       ENDIF.
     WHEN '&IC1'.




*跳转事务代码


      READ TABLE GT_TAB INTO GS_TAB INDEX RS_SELFIELD-TABINDEX.
       IF SY-SUBRC = 0.
         IF GS_TAB-BELNR = ''.
           MESSAGE E337(ZFIN01).
         ELSE.

           LOOP AT GT_TAB INTO GS_TAB WHERE ZIDX = GS_TAB-ZIDX.
             GS_TAB2-BUKRS = GS_TAB-BUKRS.
             GS_TAB2-BLDAT = GS_TAB-BLDAT.
             GS_TAB2-BELNR = GS_TAB-BELNR.
             APPEND GS_TAB2 TO GT_TAB2.
           ENDLOOP.
           READ TABLE GT_TAB2 INTO GS_TAB2 INDEX 1.
           IF SY-SUBRC = 0.
             SET PARAMETER ID: 'BUK' FIELD GS_TAB2-BUKRS.
             SET PARAMETER ID: 'BLN' FIELD GS_TAB2-BELNR.
             SET PARAMETER ID: 'GJR' FIELD GS_TAB2-BLDAT+0(4).
           ENDIF.

         ENDIF.
       ENDIF.
       CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN .
       CLEAR GT_TAB2.
   ENDCASE.

   "刷新
  RS_SELFIELD-REFRESH = 'X'.

 ENDFORM. "user_command



*Text elements
 *----------------------------------------------------------
 * 001 INDEX
 * 002 公司代码
* 003 凭证类型
* 004 凭证日期
* 005 记帐日期
* 006 交易货币
* 007 参考凭证号
* 008 凭证抬头文本
* 009 汇率
* 010 记帐码
* 011 特别总帐标志
* 012 总账科目
* 013 客户
* 014 供应商
* 015 交易货币金额
* 016 本位币金额
* 017 税码
* 018 凭证货币税额
* 019 原因代码
* 020 辅助核算
* 021 贸易伙伴
* 022 起息日
* 023 分配
* 024 项目文本
* 025 付款方式
* 026 付款条件
* 027 付款基准日期
* 028 参考码3
 * 029 开户银行
* 030 帐户标识
* 031 票号/合同号1
 * 032 票号/合同号2
 * 033 票据/合同号到期日
* 034 成本中心
* 035 项目WBS
 * 036 内部订单
* 037 获利能力分析
* 038 消息
* 039 凭证编号   
* 040 会记凭证批量打印模板.xlsx


 *Selection texts
 *----------------------------------------------------------
 * P_PATH         上传文件


*Messages
 *----------------------------------------------------------
 *
 * Message class: ZFIN01
 *000   &
 *009   用户取消操作
*010   请选择导入文件
*011   上传模板数据不能为空
*337   请先过账!
*361   清单中无数据!
 *383   请勿重复过账!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,258评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,335评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,225评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,126评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,140评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,098评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,018评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,857评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,298评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,518评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,678评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,400评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,993评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,638评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,801评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,661评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,558评论 2 352