码迷,mamicode.com
首页 > Windows程序 > 详细

会计凭证BAPI_ACC_DOCUMENT_POST

时间:2016-11-15 16:58:57      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:group   tle   hang   class   rollback   字段   filter   ack   无数据   

*&---------------------------------------------------------------------*
*& Report               ZFIFB107
*& Description         薪酬计提批导开发
*&---------------------------------------------------------------------*
*& 开发人员   时间         更改类型       描述
*& CR信息
*&---------------------------------------------------------------------*
*& WuLiang   20140904     ECDK901469      FI-FI107-薪酬计提批导开发
*&---------------------------------------------------------------------*

REPORT ZFIB107.

TYPE-POOLS: SLIS.

TABLES: SSCRFIELDS.

DATA: T_FILE          TYPE STRING,
      T_PATH          TYPE STRING,
      T_FULLPATH      TYPE STRING,
      T_USER_ACTION   TYPE I,
      T_FILE_ENCODING TYPE ABAP_ENCOD.

DATA: IT_FCODE     TYPE TABLE OF SY-UCOMM,
      FALG         TYPE          C,
      SCREEN_VALUE TYPE          SY-DYNNR VALUE 100,
      GS_OBJDATA   LIKE          WWWDATATAB.

TYPES: BEGIN OF TY_OUTPUT_LINE,
         KOSTL  TYPE CSKS-KOSTL,
         DMBTR1 TYPE BSEG-DMBTR,
         DMBTR2 TYPE BSEG-DMBTR,
         DMBTR3 TYPE BSEG-DMBTR,
         DMBTR4 TYPE BSEG-DMBTR,
         DMBTR5 TYPE BSEG-DMBTR,
         DMBTR6 TYPE BSEG-DMBTR,
         DMBTR7 TYPE BSEG-DMBTR,
         DMBTR8 TYPE BSEG-DMBTR,
*         dmbtr9 type bseg-dmbtr,
       END OF TY_OUTPUT_LINE.
DATA: WA_OUTPUT_LINE TYPE          TY_OUTPUT_LINE,
      IT_OUTPUT_ITAB TYPE TABLE OF TY_OUTPUT_LINE WITH HEADER LINE,
      IT_TOTAL_ITAB  TYPE TABLE OF TY_OUTPUT_LINE WITH HEADER LINE.

DATA: L_OREF              TYPE REF TO CX_ROOT,
      EXCEPTION_MSG(1000),
      MSG(1000).

DATA: UPLOAD_FALG TYPE C.

DATA: G_EXCEL_ITAB TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS : <FS>.
DATA: G_INDEX   TYPE I,
      ERROR_TXT TYPE STRING,
      ROW_INDEX TYPE STRING.

DATA: DOCUMENTHEADER    TYPE          BAPIACHE09,
      OBJ_TYPE          TYPE          BAPIACHE02-OBJ_TYPE,
      OBJ_KEY           TYPE          BAPIACHE02-OBJ_KEY,
      OBJ_SYS           TYPE          BAPIACHE02-OBJ_SYS,
      ACCOUNTRECEIVABLE TYPE TABLE OF BAPIACAR09 WITH HEADER LINE,
      ACCOUNTGL         TYPE TABLE OF BAPIACGL09 WITH HEADER LINE,
      CURRENCYAMOUNT    TYPE TABLE OF BAPIACCR09 WITH HEADER LINE,
      ACCOUNTPAYABLE    TYPE TABLE OF BAPIACAP09 WITH HEADER LINE,
      RETURN            TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
      WA_RETURN         TYPE          BAPIRET2,
      EXTENSION2        TYPE TABLE OF BAPIPAREX WITH HEADER LINE,
      ZACC_DOCUMENT     TYPE          ZACC_DOCUMENT.

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-T01.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME,
            P_BUKRS TYPE T001-BUKRS,
            P_BLDAT TYPE BKPF-BLDAT,
            P_BUDAT TYPE BKPF-BUDAT,
            P_SAKNR TYPE SKB1-SAKNR.
PARAMETERS: P_R1 RADIOBUTTON GROUP G1 DEFAULT X,
            P_R2 RADIOBUTTON GROUP G1.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN END OF SCREEN 100.

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-T02.
PARAMETERS: P_DOWN LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN END OF SCREEN 200.

SELECTION-SCREEN: FUNCTION KEY 1,
                  FUNCTION KEY 2.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK SUB FOR 50 LINES,
                  END OF BLOCK SUB.

INITIALIZATION.
  SSCRFIELDS-FUNCTXT_01 = 执行批导.
  SSCRFIELDS-FUNCTXT_02 = 模板下载.
  SUB-PROG = SY-REPID.
  SUB-DYNNR = 100.

AT SELECTION-SCREEN.
  IF SSCRFIELDS-UCOMM = FC02.
    SUB-DYNNR = 200.
  ENDIF.
  IF SSCRFIELDS-UCOMM = FC01.
    SUB-DYNNR = 100.
  ENDIF.
  PERFORM FRM_CHECK_DATA.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM SUB_FRM_GET_FILEPATH.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_DOWN.
  PERFORM SUB_FRM_GET_DOWN.

START-OF-SELECTION.
  IF SUB-DYNNR EQ 100.
    PERFORM FRM_GET_DATA.
    IF IT_OUTPUT_ITAB[] IS INITIAL.
      MESSAGE S888(SABAPDOCU) WITH 上载文件无数据 DISPLAY LIKE E.
      RETURN.
    ENDIF.
    IF NOT P_R1 IS INITIAL.
*创建类型为AB的会计凭证
      PERFORM FRM_CREATE_JT_BELNR.
    ELSE.
*创建类型为SK的会计凭证
      PERFORM FRM_CREATE_FF_BELNR.
    ENDIF.
*创建会计凭证信息输出
    PERFORM FRM_OUTPUT_MESSAGE.
  ELSE.
    PERFORM FRM_DOWN_FILE.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  SUB_FRM_GET_FILEPATH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_FRM_GET_FILEPATH .
*上传文件F4帮助
  CALL FUNCTION WS_FILENAME_GET
    EXPORTING
      DEF_FILENAME     = P_FILE
      DEF_PATH         = C:\‘
      MASK             = ,*.dat.
      MODE             = O
      TITLE            = Select Upload File
    IMPORTING
      FILENAME         = P_FILE
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.
ENDFORM.                    " SUB_FRM_GET_FILEPATH
*&---------------------------------------------------------------------*
*&      Form  SUB_FRM_GET_DOWN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_FRM_GET_DOWN .
*模板下载位置选择
  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    EXPORTING
      FILE_FILTER       = .XLS
      DEFAULT_EXTENSION = XLS
      DEFAULT_FILE_NAME = 薪酬计提批导开发导入模板
      INITIAL_DIRECTORY = C:\
    CHANGING
      FILENAME          = T_FILE
      PATH              = T_PATH
      FULLPATH          = T_FULLPATH
      USER_ACTION       = T_USER_ACTION
      FILE_ENCODING     = T_FILE_ENCODING
    EXCEPTIONS
      CNTL_ERROR        = 1
      ERROR_NO_GUI      = 2
      OTHERS            = 3.

  P_DOWN = T_FULLPATH.
ENDFORM.                    " SUB_FRM_GET_DOWN
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHECK_DATA .
*根据功能选择不同,判断不同的字段是否必输
  CASE SY-DYNNR.
    WHEN 0100.
      CASE SSCRFIELDS-UCOMM.
        WHEN F02.
          SUB-DYNNR = 200.
        WHEN ONLI.
          IF SUB-DYNNR EQ 100 AND P_FILE IS INITIAL.
            SUB-DYNNR = 100.
            MESSAGE 请输入上载文件 TYPE E.
          ENDIF.

          IF SUB-DYNNR EQ 100 AND P_BUKRS IS INITIAL.
            SUB-DYNNR = 100.
            MESSAGE 请输入公司代码 TYPE E.
          ENDIF.

          IF SUB-DYNNR EQ 100 AND P_BLDAT IS INITIAL.
            SUB-DYNNR = 100.
            MESSAGE 请输入凭证日期 TYPE E.
          ENDIF.

          IF SUB-DYNNR EQ 100 AND P_BUDAT IS INITIAL.
            SUB-DYNNR = 100.
            MESSAGE 请输入过帐日期 TYPE E.
          ENDIF.

          IF SUB-DYNNR EQ 100 AND P_SAKNR IS INITIAL AND NOT P_R2 IS INITIAL.
            SUB-DYNNR = 100.
            MESSAGE 请输入银行科目 TYPE E.
          ENDIF.
      ENDCASE.

    WHEN 0200.
      CASE SSCRFIELDS-UCOMM.
        WHEN F01.
          SUB-DYNNR = 100.

        WHEN ONLI.
          PERFORM FRM_CHECK_DOWN.
          IF SUB-DYNNR EQ 200 AND P_DOWN IS INITIAL.
            SUB-DYNNR = 200.
            MESSAGE 请输入下载目录 TYPE E.
          ENDIF.
      ENDCASE.
  ENDCASE.
ENDFORM.                    " FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_DOWN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHECK_DOWN .
*模板下载
  DATA:L_OBJID TYPE WWWDATATAB-OBJID.
  DATA: L_ERRTXT TYPE STRING.

  L_OBJID = ZFIB107.
  SELECT SINGLE RELID OBJID FROM WWWDATA INTO CORRESPONDING FIELDS OF GS_OBJDATA
           WHERE SRTF2 = 0 AND RELID = MI AND OBJID = L_OBJID.
  IF SY-SUBRC NE 0 OR GS_OBJDATA-OBJID EQ SPACE.
    CONCATENATE 模板文件 L_OBJID 不存在 INTO L_ERRTXT.
    MESSAGE L_ERRTXT TYPE E.
  ENDIF.
ENDFORM.                    " FRM_CHECK_DOWN
*&---------------------------------------------------------------------*
*&      Form  FRM_DOWN_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DOWN_FILE .
*模板下载
  DATA:LS_DESTINATION LIKE RLGRAP-FILENAME.
  DATA:L_RC     LIKE SY-SUBRC,
       L_ERRTXT TYPE STRING.
  CALL FUNCTION DOWNLOAD_WEB_OBJECT
    EXPORTING
      KEY         = GS_OBJDATA
      DESTINATION = P_DOWN
    IMPORTING
      RC          = L_RC.
  IF L_RC NE 0.
    CONCATENATE 模板文件: GS_OBJDATA-OBJID 下载失败 INTO L_ERRTXT.
    MESSAGE L_ERRTXT TYPE E.
  ELSE.
    MESSAGE 模板下载成功 TYPE S.
  ENDIF.
ENDFORM.                    " FRM_DOWN_FILE
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
*取得EXCEL数据
  CLEAR: MSG, UPLOAD_FALG.
  CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
  CONSTANTS: C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
  CLEAR MSG.
  TRY.
      CALL FUNCTION ALSM_EXCEL_TO_INTERNAL_TABLE
        EXPORTING
          FILENAME                = P_FILE
          I_BEGIN_COL             = 1
          I_BEGIN_ROW             = 3
          I_END_COL               = 9
          I_END_ROW               = 65535
        TABLES
          INTERN                  = G_EXCEL_ITAB
        EXCEPTIONS
          INCONSISTENT_PARAMETERS = 1
          UPLOAD_OLE              = 2
          OTHERS                  = 3.
      LOOP AT G_EXCEL_ITAB.
        MOVE: G_EXCEL_ITAB-COL TO G_INDEX.
        ASSIGN COMPONENT G_INDEX OF STRUCTURE IT_OUTPUT_ITAB TO <FS>.
        MOVE: G_EXCEL_ITAB-VALUE TO <FS>.
        AT END OF ROW.
          APPEND IT_OUTPUT_ITAB.
          IF NOT P_R1 IS INITIAL.
            CLEAR IT_OUTPUT_ITAB-KOSTL."Changed By LY 20150305
          ENDIF.
          COLLECT IT_OUTPUT_ITAB INTO IT_TOTAL_ITAB.
          CLEAR IT_OUTPUT_ITAB.
        ENDAT.
      ENDLOOP.
    CATCH CX_ROOT INTO L_OREF.
      UPLOAD_FALG = X.
      MSG =  L_OREF->GET_TEXT( ).
      IF NOT MSG IS INITIAL.
        WRITE:/ upladload file exception:, MSG.
      ENDIF.
  ENDTRY.
ENDFORM.                    " FRM_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_CREATE_JT_BELNR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CREATE_JT_BELNR .
  DATA: L_INDEX  TYPE I,
        L_DMBTR1 TYPE BSEG-DMBTR,
        L_DMBTR2 TYPE BSEG-DMBTR,
        L_DMBTR3 TYPE BSEG-DMBTR,
        L_DMBTR4 TYPE BSEG-DMBTR.

  CLEAR L_INDEX.

*调用BAPI生成类型为AB的会计凭证
  DOCUMENTHEADER-DOC_TYPE   = AB.
  DOCUMENTHEADER-DOC_DATE   = P_BLDAT.
  DOCUMENTHEADER-PSTNG_DATE = P_BUDAT.
  DOCUMENTHEADER-FIS_PERIOD = P_BUDAT+4(2).
  DOCUMENTHEADER-COMP_CODE  = P_BUKRS.
  DOCUMENTHEADER-USERNAME   = SY-UNAME.
  DOCUMENTHEADER-BUS_ACT = RFBU.
  DOCUMENTHEADER-HEADER_TXT = 珠宝工资分配.

  SORT IT_OUTPUT_ITAB BY KOSTL.

  LOOP AT IT_OUTPUT_ITAB.
    MOVE IT_OUTPUT_ITAB TO WA_OUTPUT_LINE.
    AT NEW KOSTL.
      CLEAR: L_DMBTR1, L_DMBTR2.
    ENDAT.

    L_DMBTR1 = L_DMBTR1 + WA_OUTPUT_LINE-DMBTR1.
*    l_dmbtr2 = l_dmbtr1 + wa_output_line-dmbtr9.
    L_DMBTR2 = L_DMBTR2 + WA_OUTPUT_LINE-DMBTR2 + WA_OUTPUT_LINE-DMBTR3 + WA_OUTPUT_LINE-DMBTR4 + WA_OUTPUT_LINE-DMBTR5
                        + WA_OUTPUT_LINE-DMBTR6 + WA_OUTPUT_LINE-DMBTR7 + WA_OUTPUT_LINE-DMBTR8.

    AT END OF KOSTL.
      ADD 1 TO L_INDEX.
      ACCOUNTGL-ITEMNO_ACC  = L_INDEX.
      IF WA_OUTPUT_LINE-KOSTL EQ C2I000012I."Change By Ly 20150323
*      IF wa_output_line-kostl EQ C202000006.
        ACCOUNTGL-GL_ACCOUNT  = 5001030000.
*       ELSEif wa_output_line-kostl eq C202000005.“DELETE BY LY 20150304
*        accountgl-gl_account  = 5101010000.
      ELSE.
        ACCOUNTGL-GL_ACCOUNT  = 6601010000.
      ENDIF.
      ACCOUNTGL-COSTCENTER  = WA_OUTPUT_LINE-KOSTL.
      ACCOUNTGL-ITEM_TEXT   = 珠宝工资分配.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

      CURRENCYAMOUNT-ITEMNO_ACC = L_INDEX.
      CURRENCYAMOUNT-AMT_DOCCUR = L_DMBTR1.
      CURRENCYAMOUNT-CURRENCY = CNY.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

      CLEAR: ZACC_DOCUMENT.
      ZACC_DOCUMENT-POSNR = L_INDEX.
*      zacc_document-bschl = 40.Changed By Ly 20150323
      IF L_DMBTR1 < 0.                            "更改  shirumeng  20150506
        ZACC_DOCUMENT-BSCHL = 50.
        ZACC_DOCUMENT-XNEGP = X.
      ELSE.
        ZACC_DOCUMENT-BSCHL = 40.
      ENDIF.
      EXTENSION2-STRUCTURE = ZACC_DOCUMENT.
      EXTENSION2-VALUEPART1 = ZACC_DOCUMENT.
      APPEND EXTENSION2.
      CLEAR EXTENSION2.

      ADD 1 TO L_INDEX.
      ACCOUNTGL-ITEMNO_ACC  = L_INDEX.
      ACCOUNTGL-GL_ACCOUNT  = 2211010100.                "更改   shiruemng  20150429
      ACCOUNTGL-COSTCENTER  = WA_OUTPUT_LINE-KOSTL.
      ACCOUNTGL-ITEM_TEXT   = 珠宝工资分配.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

      CURRENCYAMOUNT-ITEMNO_ACC = L_INDEX.
      CURRENCYAMOUNT-AMT_DOCCUR = L_DMBTR2.
      CURRENCYAMOUNT-CURRENCY = CNY.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

      CLEAR: ZACC_DOCUMENT.
      ZACC_DOCUMENT-POSNR = L_INDEX.
*      zacc_document-bschl = 40.
      IF L_DMBTR2 < 0.
        ZACC_DOCUMENT-BSCHL = 50.
        ZACC_DOCUMENT-XNEGP = X.
      ELSE.
        ZACC_DOCUMENT-BSCHL = 40.
      ENDIF.
      EXTENSION2-STRUCTURE = ZACC_DOCUMENT.
      EXTENSION2-VALUEPART1 = ZACC_DOCUMENT.
      APPEND EXTENSION2.
      CLEAR EXTENSION2.

      ADD 1 TO L_INDEX.
      ACCOUNTGL-ITEMNO_ACC  = L_INDEX.
      ACCOUNTGL-GL_ACCOUNT  = 2211010100.      "更改   shiruemng  20150429
      ACCOUNTGL-COSTCENTER  = WA_OUTPUT_LINE-KOSTL.
      ACCOUNTGL-ITEM_TEXT   = 珠宝工资分配.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

      CURRENCYAMOUNT-ITEMNO_ACC = L_INDEX.
      CURRENCYAMOUNT-AMT_DOCCUR = L_DMBTR1 * -1.
      CURRENCYAMOUNT-CURRENCY = CNY.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

      CLEAR: ZACC_DOCUMENT.
      ZACC_DOCUMENT-POSNR = L_INDEX.
*  和  6601010000  效果相反。
      IF L_DMBTR1 < 0.
        ZACC_DOCUMENT-BSCHL = 40.
        ZACC_DOCUMENT-XNEGP = X.
      ELSE.
        ZACC_DOCUMENT-BSCHL = 50.
      ENDIF.
      " ZACC_DOCUMENT-BSCHL = 50.
      EXTENSION2-STRUCTURE = ZACC_DOCUMENT.
      EXTENSION2-VALUEPART1 = ZACC_DOCUMENT.
      APPEND EXTENSION2.
      CLEAR EXTENSION2.
    ENDAT.
  ENDLOOP.

  READ TABLE IT_TOTAL_ITAB INDEX 1.
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2241010100 IT_TOTAL_ITAB-DMBTR2.
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2241010200 IT_TOTAL_ITAB-DMBTR3.
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2241010300 IT_TOTAL_ITAB-DMBTR4.
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2241010500 IT_TOTAL_ITAB-DMBTR5.
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2241010600 IT_TOTAL_ITAB-DMBTR7.
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2241019900 IT_TOTAL_ITAB-DMBTR8.      "更改   shiruemng  20150429
  ADD 1 TO L_INDEX.
  PERFORM FRM_FILL_ITEM USING L_INDEX 2221110000 IT_TOTAL_ITAB-DMBTR6.

  CALL FUNCTION BAPI_ACC_DOCUMENT_POST
    EXPORTING
      DOCUMENTHEADER    = DOCUMENTHEADER
    TABLES
      ACCOUNTRECEIVABLE = ACCOUNTRECEIVABLE
      ACCOUNTPAYABLE    = ACCOUNTPAYABLE
      ACCOUNTGL         = ACCOUNTGL
      CURRENCYAMOUNT    = CURRENCYAMOUNT
      EXTENSION2        = EXTENSION2
      RETURN            = RETURN.
ENDFORM.                    " FRM_CREATE_JT_BELNR
*&---------------------------------------------------------------------*
*&      Form  FRM_CREATE_FF_BELNR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CREATE_FF_BELNR .
  DATA: L_INDEX  TYPE I,
        L_DMBTR1 TYPE BSEG-DMBTR,
        L_DMBTR2 TYPE BSEG-DMBTR,
        L_DMBTR3 TYPE BSEG-DMBTR,
        L_DMBTR4 TYPE BSEG-DMBTR.
  DATA:LV_DMBTR5 TYPE BSEG-DMBTR.

  CLEAR L_INDEX.
*调用BAPI生成类型为SK会计凭证
  DOCUMENTHEADER-DOC_TYPE   = SK.
  DOCUMENTHEADER-DOC_DATE   = P_BLDAT.
  DOCUMENTHEADER-PSTNG_DATE = P_BUDAT.
  DOCUMENTHEADER-FIS_PERIOD = P_BUDAT+4(2).
  DOCUMENTHEADER-COMP_CODE  = P_BUKRS.
  DOCUMENTHEADER-USERNAME   = SY-UNAME.
  DOCUMENTHEADER-BUS_ACT = RFBU.
  DOCUMENTHEADER-HEADER_TXT = 珠宝工资发放.

  CHECK IT_TOTAL_ITAB[] IS NOT INITIAL.

  SORT IT_TOTAL_ITAB[] BY KOSTL.
  LOOP AT IT_TOTAL_ITAB.
    ADD 1 TO L_INDEX.
*  read table it_total_itab index 1.

    ACCOUNTGL-ITEMNO_ACC  = L_INDEX."1.
    ACCOUNTGL-GL_ACCOUNT  = 2211010100.    "更改  shiruemng  20150429
    ACCOUNTGL-COSTCENTER  = IT_TOTAL_ITAB-KOSTL.
    ACCOUNTGL-ITEM_TEXT   = 珠宝工资发放.
    APPEND ACCOUNTGL.
    CLEAR ACCOUNTGL.

    CURRENCYAMOUNT-ITEMNO_ACC = L_INDEX."1.
    CURRENCYAMOUNT-AMT_DOCCUR = IT_TOTAL_ITAB-DMBTR1 - IT_TOTAL_ITAB-DMBTR2 - IT_TOTAL_ITAB-DMBTR3 - IT_TOTAL_ITAB-DMBTR4
                                - IT_TOTAL_ITAB-DMBTR5 - IT_TOTAL_ITAB-DMBTR6 - IT_TOTAL_ITAB-DMBTR7 - IT_TOTAL_ITAB-DMBTR8.
    CURRENCYAMOUNT-CURRENCY = CNY.
    APPEND CURRENCYAMOUNT.


    CLEAR: ZACC_DOCUMENT.
    ZACC_DOCUMENT-POSNR = L_INDEX."1.
    IF CURRENCYAMOUNT-AMT_DOCCUR < 0.
      ZACC_DOCUMENT-BSCHL = 50.
      ZACC_DOCUMENT-XNEGP = X.
    ELSE.
      ZACC_DOCUMENT-BSCHL = 40.
    ENDIF.
*    zacc_document-bschl = 40.
    ZACC_DOCUMENT-RSTGR = -07.
    EXTENSION2-STRUCTURE = ZACC_DOCUMENT.
    EXTENSION2-VALUEPART1 = ZACC_DOCUMENT.
    APPEND EXTENSION2.
    CLEAR EXTENSION2.
    CLEAR CURRENCYAMOUNT.                                   "20150506
*    add 1 to l_index.
*    accountgl-itemno_acc  = l_index.
*    accountgl-gl_account  = p_saknr.
*    accountgl-item_text   = 珠宝工资发放.
*    append accountgl.
*    clear accountgl.
*
*    currencyamount-itemno_acc = l_index.
**  currencyamount-amt_doccur = it_total_itab-dmbtr1 * -1.
*    currencyamount-amt_doccur = ( it_total_itab-dmbtr1 - it_total_itab-dmbtr2 - it_total_itab-dmbtr3 - it_total_itab-dmbtr4
*                                - it_total_itab-dmbtr5 - it_total_itab-dmbtr6 - it_total_itab-dmbtr7 - it_total_itab-dmbtr8 ) * -1.
    LV_DMBTR5 = IT_TOTAL_ITAB-DMBTR1 - IT_TOTAL_ITAB-DMBTR2 - IT_TOTAL_ITAB-DMBTR3 - IT_TOTAL_ITAB-DMBTR4
                 - IT_TOTAL_ITAB-DMBTR5 - IT_TOTAL_ITAB-DMBTR6 - IT_TOTAL_ITAB-DMBTR7 - IT_TOTAL_ITAB-DMBTR8 + LV_DMBTR5.
*    currencyamount-currency = CNY.
*    append currencyamount.
*    clear currencyamount.
*
*    clear: zacc_document.
*    zacc_document-posnr = l_index.
*    zacc_document-bschl = 50.
*    extension2-structure = ZACC_DOCUMENT.
*    extension2-valuepart1 = zacc_document.
*    append extension2.
*    clear extension2.
*    clear it_total_itab.
  ENDLOOP.

  "Changed by ly 20150311
  ADD 1 TO L_INDEX.
  ACCOUNTGL-ITEMNO_ACC  = L_INDEX.
  ACCOUNTGL-GL_ACCOUNT  = P_SAKNR.
  ACCOUNTGL-ITEM_TEXT   = 珠宝工资发放.
  APPEND ACCOUNTGL.
  CLEAR ACCOUNTGL.

  CURRENCYAMOUNT-ITEMNO_ACC = L_INDEX.
  CURRENCYAMOUNT-AMT_DOCCUR = LV_DMBTR5 * -1.
*    currencyamount-amt_doccur = ( it_total_itab-dmbtr1 - it_total_itab-dmbtr2 - it_total_itab-dmbtr3 - it_total_itab-dmbtr4
*                                - it_total_itab-dmbtr5 - it_total_itab-dmbtr6 - it_total_itab-dmbtr7 - it_total_itab-dmbtr8 ) * -1.
  CURRENCYAMOUNT-CURRENCY = CNY.
  APPEND CURRENCYAMOUNT.


  CLEAR: ZACC_DOCUMENT.
  ZACC_DOCUMENT-POSNR = L_INDEX.
  IF LV_DMBTR5 < 0.
    ZACC_DOCUMENT-BSCHL = 40.
 "   ZACC_DOCUMENT-XNEGP = X.
  ELSE.
    ZACC_DOCUMENT-BSCHL = 50.
  ENDIF.
  " ZACC_DOCUMENT-BSCHL = 50.
  EXTENSION2-STRUCTURE = ZACC_DOCUMENT.
  EXTENSION2-VALUEPART1 = ZACC_DOCUMENT.
  APPEND EXTENSION2.
  CLEAR EXTENSION2.
  CLEAR IT_TOTAL_ITAB.
  CLEAR CURRENCYAMOUNT.                                     "20150506
  "Changed by ly 20150311



  CALL FUNCTION BAPI_ACC_DOCUMENT_POST
    EXPORTING
      DOCUMENTHEADER    = DOCUMENTHEADER
    TABLES
      ACCOUNTRECEIVABLE = ACCOUNTRECEIVABLE
      ACCOUNTPAYABLE    = ACCOUNTPAYABLE
      ACCOUNTGL         = ACCOUNTGL
      CURRENCYAMOUNT    = CURRENCYAMOUNT
      EXTENSION2        = EXTENSION2
      RETURN            = RETURN.
ENDFORM.                    " FRM_CREATE_FF_BELNR
*&---------------------------------------------------------------------*
*&      Form  FRM_FILL_ITEM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_L_INDEX  text
*      -->P_1149   text
*      -->P_IT_TOTAL_ITAB_DMBTR4  text
*----------------------------------------------------------------------*
FORM FRM_FILL_ITEM  USING    P_L_INDEX
                             VALUE(P_1149)
                             P_IT_TOTAL_ITAB_DMBTR4.
  ACCOUNTGL-ITEMNO_ACC  = P_L_INDEX.
  ACCOUNTGL-GL_ACCOUNT  = P_1149.
  ACCOUNTGL-ITEM_TEXT   = 珠宝工资分配.
  APPEND ACCOUNTGL.
  CLEAR ACCOUNTGL.

  CURRENCYAMOUNT-ITEMNO_ACC = P_L_INDEX.
  CURRENCYAMOUNT-AMT_DOCCUR = P_IT_TOTAL_ITAB_DMBTR4 * -1.
  CURRENCYAMOUNT-CURRENCY = CNY.
  APPEND CURRENCYAMOUNT.
  CLEAR CURRENCYAMOUNT.

  CLEAR: ZACC_DOCUMENT.
  ZACC_DOCUMENT-POSNR = P_L_INDEX.
  IF P_IT_TOTAL_ITAB_DMBTR4 < 0.
    ZACC_DOCUMENT-BSCHL = 40.
    ZACC_DOCUMENT-XNEGP = X.
  ELSE.
    ZACC_DOCUMENT-BSCHL = 50.
  ENDIF.
  EXTENSION2-STRUCTURE = ZACC_DOCUMENT.
  EXTENSION2-VALUEPART1 = ZACC_DOCUMENT.
  APPEND EXTENSION2.
  CLEAR EXTENSION2.
ENDFORM.                    " FRM_FILL_ITEM
*&---------------------------------------------------------------------*
*&      Form  FRM_OUTPUT_MESSAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_OUTPUT_MESSAGE .
  DATA:LT_MESSAGE        TYPE FUCN_T_MESSAGE,
       LS_MESSAGE        TYPE FUCN_S_MESSAGE,
       LV_SAVE_NECESSARY TYPE FUCN_REP_FLG VALUE  .

  LOOP AT RETURN.
    CLEAR LS_MESSAGE.
    LS_MESSAGE-MSGID = RETURN-ID .
    LS_MESSAGE-MSGTY = RETURN-TYPE .
    LS_MESSAGE-MSGNO = RETURN-NUMBER.
    LS_MESSAGE-MSGV1 = RETURN-MESSAGE_V1.
    LS_MESSAGE-MSGV2 = RETURN-MESSAGE_V2.
    APPEND LS_MESSAGE TO LT_MESSAGE.
  ENDLOOP.

  CALL FUNCTION FUCN_MESSAGE_POPUP
    EXPORTING
      IT_MESSAGE        = LT_MESSAGE
      IF_SAVE_NECESSARY = LV_SAVE_NECESSARY.

  READ TABLE RETURN WITH KEY TYPE = S.
  IF SY-SUBRC EQ 0.
    CALL FUNCTION BAPI_TRANSACTION_COMMIT
      EXPORTING
        WAIT = X.
  ELSE.
    CALL FUNCTION BAPI_TRANSACTION_ROLLBACK.
  ENDIF.
ENDFORM.                    " FRM_OUTPUT_MESSAGE

 

会计凭证BAPI_ACC_DOCUMENT_POST

标签:group   tle   hang   class   rollback   字段   filter   ack   无数据   

原文地址:http://www.cnblogs.com/sapSB/p/6066133.html

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