当前位置: 首页 > 工具软件 > Posterita POS > 使用案例 >

bapi:Post with clearing (FB05) using internal posting interface

荆炳
2023-12-01

*&---------------------------------------------------------------------*
*& Report  ZBAPI_POST_CLEAR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZBAPI_POST_CLEAR_TEST.
DATA:GT_BLNTAB TYPE STANDARD TABLE OF BLNTAB INITIAL SIZE 0,
      GT_BSID_CLEARING TYPE STANDARD TABLE OF BSID INITIAL SIZE 0 ,
      GT_FTCLEAR TYPE STANDARD TABLE OF FTCLEAR INITIAL SIZE 0,
      GT_FTPOST TYPE STANDARD TABLE OF FTPOST INITIAL SIZE 0 ,
      GT_FTTAX TYPE STANDARD TABLE OF FTTAX INITIAL SIZE 0 .
DATA:GS_FTPOST LIKE LINE OF GT_FTPOST,
      GS_BSID_CLEARING LIKE LINE OF GT_BSID_CLEARING.

START-OF-SELECTION.
GS_BSID_CLEARING-BELNR = '2000000303'.
GS_BSID_CLEARING-GJAHR = '2013'.
GS_BSID_CLEARING-BUZEI = 1.
APPEND GS_BSID_CLEARING TO GT_BSID_CLEARING.
  PERFORM: F_POSTING_INTERFACE_START.
  PERFORM: F_POSTING_INTERFACE_CLEARING.
  PERFORM: F_POSTING_INTERFACE_END.

*&---------------------------------------------------------------------*
*&      Form  f_posting_interface_start
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_POSTING_INTERFACE_START .
  CONSTANTS: LC_FUNCTION       LIKE  RFIPI-FUNCT VALUE 'C',
  " B= BDC, C= Call Trans
             LC_MODE LIKE RFPDO-ALLGAZMD VALUE 'E', "ERRORS only
             LC_UPDATE LIKE RFPDO-ALLGVBMD VALUE 'S' .

  CALL FUNCTION 'POSTING_INTERFACE_START'
    EXPORTING
      I_FUNCTION         = LC_FUNCTION
      I_MODE             = LC_MODE
      I_UPDATE           = LC_UPDATE
    EXCEPTIONS
      CLIENT_INCORRECT   = 1
      FUNCTION_INVALID   = 2
      GROUP_NAME_MISSING = 3
      MODE_INVALID       = 4
      UPDATE_INVALID     = 5
      OTHERS             = 6.
  IF SY-SUBRC <> 0.
    MESSAGE 'ERROR' TYPE 'S'.
  ENDIF.
ENDFORM." F_POSTING_INTERFACE_START
*&---------------------------------------------------------------------*
*&      Form  f_posting_interface_clearing
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_POSTING_INTERFACE_CLEARING.

  CONSTANTS: LC_AUGLV TYPE AUGLV VALUE 'EINGZAHL',
             LC_TCODE TYPE SYTCODE VALUE 'FB05',
             LC_SGFUNCT TYPE SGFUNCT_PI VALUE 'C'.

  PERFORM: F_PREPARE_FTPOST.
  PERFORM: F_PREPARE_FTCLEAR.

  CALL FUNCTION 'POSTING_INTERFACE_CLEARING'
    EXPORTING
      I_AUGLV                    = LC_AUGLV
      I_TCODE                    = LC_TCODE
      I_SGFUNCT                  = LC_SGFUNCT
    TABLES
      T_BLNTAB                   = GT_BLNTAB
      T_FTCLEAR                  = GT_FTCLEAR
      T_FTPOST                   = GT_FTPOST
      T_FTTAX                    = GT_FTTAX
    EXCEPTIONS
      CLEARING_PROCEDURE_INVALID = 1
      CLEARING_PROCEDURE_MISSING = 2
      TABLE_T041A_EMPTY          = 3
      TRANSACTION_CODE_INVALID   = 4
      AMOUNT_FORMAT_ERROR        = 5
      TOO_MANY_LINE_ITEMS        = 6
      COMPANY_CODE_INVALID       = 7
      SCREEN_NOT_FOUND           = 8
      NO_AUTHORIZATION           = 9
      OTHERS                     = 10.

  IF SY-SUBRC <> 0.
    CASE SY-SUBRC.
      WHEN '1'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '2'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '3'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '4'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '5'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '6'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '7'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '8'.
        MESSAGE 'ERROR' TYPE 'S'.
      WHEN '9'.
        MESSAGE 'ERROR' TYPE 'S'.
    ENDCASE.
  ELSE.
    COMMIT WORK.
    SET SCREEN 0.
  ENDIF.

ENDFORM." F_POSTING_INTERFACE_CLEARING

*&---------------------------------------------------------------------*
*&      Form  f_prepare_ftpost
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_PREPARE_FTPOST .
  CONSTANTS: LC_HEADER TYPE C VALUE 'K', "Header
             LC_ITEM TYPE C VALUE 'P', "Item
             LC_COUNT TYPE I VALUE '001'.

*fill_header(BKPF)
* Convert the date format from  YYYYMMDD -> DD/MM/YYYY
*  PERFORM: F_CONVERT_DATE USING PA_BLDAT
*                         CHANGING PA_BLDAT.
  GS_FTPOST-STYPE = LC_HEADER.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'BKPF-BLDAT'.
  GS_FTPOST-FVAL  = SY-DATUM.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

* Convert the date format from  YYYYMMDD -> DD/MM/YYYY
*  PERFORM: F_CONVERT_DATE USING PA_BUDAT
*                         CHANGING PA_BUDAT.
  GS_FTPOST-STYPE = LC_HEADER.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'BKPF-BUDAT'.
  GS_FTPOST-FVAL  = SY-DATUM.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

  GS_FTPOST-STYPE = LC_HEADER.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'BKPF-BLART'.
  GS_FTPOST-FVAL  = 'SA'.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.


  GS_FTPOST-STYPE = LC_HEADER.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'BKPF-BUKRS'.
  GS_FTPOST-FVAL  = '1000'.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

  GS_FTPOST-STYPE = LC_HEADER.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'BKPF-WAERS'. "Currency
  GS_FTPOST-FVAL  = 'USD'.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

*  GS_FTPOST-STYPE = LC_HEADER.
*  GS_FTPOST-COUNT = LC_COUNT.
*  GS_FTPOST-FNAM  = 'BKPF-XBLNR'.
*  GS_FTPOST-FVAL  = PA_XBLNR.
*  APPEND GS_FTPOST TO GT_FTPOST.
*  CLEAR GS_FTPOST.

*  GS_FTPOST-STYPE = LC_HEADER.
*  GS_FTPOST-COUNT = LC_COUNT.
*  GS_FTPOST-FNAM  = 'BKPF-BKTXT'. "Doc. Header Text
*  GS_FTPOST-FVAL  = PA_TEXT.
*  APPEND GS_FTPOST TO GT_FTPOST.
*  CLEAR GS_FTPOST.

*Commented temporarily
*  gs_ftpost-stype = lc_header.
*  gs_ftpost-count = lc_count.
*  gs_ftpost-fnam  = 'BKPF-KURSF'. "Exchange Rate
*  gs_ftpost-fval  = pa_erate.
*  SHIFT gs_ftpost-fval LEFT DELETING LEADING space.
*  APPEND gs_ftpost TO gt_ftpost.
*  CLEAR gs_ftpost.

*Item Data
  GS_FTPOST-STYPE = LC_ITEM.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'RF05A-NEWKO'.
  GS_FTPOST-FVAL  = 'MA03E'.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

  GS_FTPOST-STYPE = LC_ITEM.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'RF05A-NEWBS'.
  GS_FTPOST-FVAL  = '31'.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

  GS_FTPOST-STYPE = LC_ITEM.
  GS_FTPOST-COUNT = LC_COUNT.
  GS_FTPOST-FNAM  = 'BSEG-WRBTR'.
  GS_FTPOST-FVAL  = '1000'.
  SHIFT GS_FTPOST-FVAL LEFT DELETING LEADING SPACE.
  APPEND GS_FTPOST TO GT_FTPOST.
  CLEAR GS_FTPOST.

* Convert the date format from  YYYYMMDD -> DD/MM/YYYY
*  PERFORM: F_CONVERT_DATE USING PA_VALUT
*                         CHANGING PA_VALUT.

*  GS_FTPOST-STYPE = LC_ITEM.
*  GS_FTPOST-COUNT = LC_COUNT.
*  GS_FTPOST-FNAM  = 'BSEG-VALUT'.
*  GS_FTPOST-FVAL  = SY-DATUM.
*  APPEND GS_FTPOST TO GT_FTPOST.
*  CLEAR GS_FTPOST.
*
** Convert the date format from  YYYYMMDD -> DD/MM/YYYY
*  PERFORM: F_CONVERT_DATE USING PA_ZFBDT
*                         CHANGING PA_ZFBDT.
*  GS_FTPOST-STYPE = LC_ITEM.
*  GS_FTPOST-COUNT = LC_COUNT.
*  GS_FTPOST-FNAM  = 'BSEG-ZFBDT'.
*  GS_FTPOST-FVAL  = PA_ZFBDT.
*  APPEND GS_FTPOST TO GT_FTPOST.
*  CLEAR GS_FTPOST.


ENDFORM." F_PREPARE_FTPOST
*&---------------------------------------------------------------------*
*&      Form  f_prepare_ftclear
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_PREPARE_FTCLEAR .
  DATA: LS_FTCLEAR TYPE FTCLEAR.
  CONSTANTS: LC_AGKOA TYPE KOART VALUE 'S', "Customers
             LC_SELFD TYPE FLD30_F05A VALUE 'BELNR'.
  LOOP AT GT_BSID_CLEARING INTO GS_BSID_CLEARING. "Clearing Table
    LS_FTCLEAR-AGKOA = LC_AGKOA.
*    LS_FTCLEAR-AGKON = '200120'. "Customer
    LS_FTCLEAR-AGBUK = '1000'. "Company code
    LS_FTCLEAR-XNOPS = 'X'. "G/L Indicator
    LS_FTCLEAR-SELFD = LC_SELFD.
*    LS_FTCLEAR-AVSID = '2000000302'.
    LS_FTCLEAR-SELVON = '2000000303'.
    LS_FTCLEAR-SELBIS = '2000000303'.

    APPEND LS_FTCLEAR TO GT_FTCLEAR.
  ENDLOOP.
ENDFORM." F_PREPARE_FTCLEAR
*&---------------------------------------------------------------------*
*&      Form  f_posting_interface_end
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_POSTING_INTERFACE_END .
  CALL FUNCTION 'POSTING_INTERFACE_END'
    EXPORTING
      I_BDCIMMED              = 'X'
    EXCEPTIONS
      SESSION_NOT_PROCESSABLE = 1
      OTHERS                  = 2.
  IF SY-SUBRC <> 0.
    MESSAGE 'ERROR' TYPE 'S'.
  ENDIF.
ENDFORM.                    " F_POSTING_INTERFACE_END

BAPI:POSTING_INTERFACE_CLEARING


Post with clearing (FB05) 这个接口的使用,在网上看到别人的例子,自己使用总是清帐不成功,仔细查找

是这两个字段要设置一样的值 都填写belnr的值,虽然不知道原因,但是可以清帐了,附测试代码:


 类似资料:

相关阅读

相关文章

相关问答