BAPI過賬
REPORT ZWGX013.
* DATA LR_DOC TYPE REF TO CL_DOCUMENT.
* DATA LV_KEY TYPE BAPIACHE09-OBJ_KEY.
CLASS CL_DOCUMENT DEFINITION.
PUBLIC SECTION.
METHODS SET_HEAD
IMPORTING
HEADER_TXT TYPE BKTXT
COMP_CODE TYPE BUKRS
DOC_DATE TYPE DATS
PSTNG_DATE TYPE DATS
FISC_YEAR TYPE GJAHR
FIS_PERIOD TYPE MONAT.
METHODS ADD_ITEM
IMPORTING
ACCOUNT TYPE HKONT
TEXT TYPE SGTXT
CURRENCY TYPE WAERS
AMONT TYPE BAPIDOCCUR.
METHODS CHECK
RETURNING VALUE(FLAG) TYPE ABAP_BOOL.
METHODS POST
RETURNING VALUE(OBJKEY) TYPE BAPIACHE09-OBJ_KEY.
PRIVATE SECTION.
DATA HEADER TYPE BAPIACHE09."表頭
DATA ITEMS TYPE TABLE OF BAPIACGL09.
DATA ITEM TYPE BAPIACGL09.
DATA CITEMS TYPE TABLE OF BAPIACCR09.
DATA CITEM TYPE BAPIACCR09.
DATA ITEMNO TYPE POSNR_ACC."會計憑證行項目編號
DATA RETURNS TYPE TABLE OF BAPIRET2."BAPIRET2返回參數
ENDCLASS.
CLASS CL_DOCUMENT IMPLEMENTATION.
METHOD SET_HEAD.
HEADER-USERNAME = SY-UNAME.
HEADER-COMP_CODE = COMP_CODE.
HEADER-HEADER_TXT = HEADER_TXT.
HEADER-DOC_DATE = DOC_DATE."DOC_DATE憑證中的憑證日期
HEADER-PSTNG_DATE = PSTNG_DATE."PSTNG_DATE憑證中的過帳日期
HEADER-DOC_TYPE = ‘SA‘."憑證類型
HEADER-FISC_YEAR = FISC_YEAR."財年
HEADER-FIS_PERIOD = FIS_PERIOD."會計期間
ITEMNO = 1.
ENDMETHOD.
METHOD ADD_ITEM.
DATA: ITEM TYPE BAPIACGL09."總賬科項目
DATA: CITEM TYPE BAPIACCR09."貨幣項目
ITEM-ITEMNO_ACC = ITEMNO."ITEMNO_ACC會計憑證行項目編號
ITEM-GL_ACCOUNT = ACCOUNT."GL_ACCOUNT總賬科目
ITEM-ITEM_TEXT = TEXT."ITEM_TEXT項目文本
APPEND ITEM TO ITEMS.
CLEAR ITEM.
CITEM-ITEMNO_ACC = ITEMNO.
CITEM-CURRENCY = CURRENCY.
CITEM-AMT_DOCCUR = AMONT.
APPEND CITEM TO CITEMS.
CLEAR CITEM.
ITEMNO = ITEMNO + 1.
ENDMETHOD.
METHOD CHECK.
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_CHECK‘
EXPORTING
DOCUMENTHEADER = HEADER
* CUSTOMERCPD =
* CONTRACTHEADER =
TABLES
ACCOUNTGL = ITEMS
* ACCOUNTRECEIVABLE =
* ACCOUNTPAYABLE =
* ACCOUNTTAX =
CURRENCYAMOUNT = CITEMS
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
RETURN = RETURNS
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.
READ TABLE RETURNS WITH KEY TYPE = ‘E‘ TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
FLAG = ABAP_FALSE.
ELSE.
FLAG = ABAP_TRUE.
ENDIF .
ENDMETHOD.
* DATA LV_KEY TYPE BAPIACHE09-OBJ_KEY.
METHOD POST.
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_POST‘
EXPORTING
DOCUMENTHEADER = HEADER
* CUSTOMERCPD =
* CONTRACTHEADER =
IMPORTING ""沒放開,DUMP
* OBJ_TYPE =