ABAP代码写一个ECC 6.0 可以跑起来的,生成会计凭证的代码
时间: 2023-06-12 18:03:15 浏览: 230
以下是一个简单的 ABAP 代码示例,用于在 ECC 6.0 中生成会计凭证:
```
REPORT z_generate_accounting_document.
DATA: ls_bkpf TYPE bkpf,
ls_bseg TYPE bseg.
* Fill the header data of the accounting document
ls_bkpf-bukrs = '1000'. " Company code
ls_bkpf-blart = 'SA'. " Document type
ls_bkpf-budat = sy-datum. " Posting date
ls_bkpf-monat = sy-datum(4). " Posting period
ls_bkpf-waers = 'USD'. " Currency code
ls_bkpf-kursf = 1. " Exchange rate
ls_bkpf-xblnr = '12345'. " Reference
ls_bkpf-bktxt = 'Test document'. " Document header text
* Fill the line item data of the accounting document
ls_bseg-bukrs = ls_bkpf-bukrs. " Company code
ls_bseg-gsber = '001'. " Business area
ls_bseg-hkont = '100000'. " GL account
ls_bseg-shkzg = 'S'. " Debit/Credit indicator
ls_bseg-dmbtr = '100.00'. " Amount
ls_bseg-wrbtr = '100.00'. " Amount in document currency
ls_bseg-mwskz = 'V0'. " Tax code
ls_bseg-sgtxt = 'Test line item'. " Line item text
* Call the accounting document creation function module
CALL FUNCTION 'AC_DOCUMENT_CREATE'
EXPORTING
headerdata = ls_bkpf
TABLES
itemdata = lt_bseg.
* Check for errors
IF sy-subrc = 0.
WRITE: 'Accounting document created successfully!'.
ELSE.
WRITE: 'Error creating accounting document:', sy-subrc.
ENDIF.
```
这个示例代码创建了一个会计凭证,其中包括了一个头部和一行项目。在实际应用中,如果需要创建多个行项目,需要在 `itemdata` 表中添加多个条目。代码中使用了 `AC_DOCUMENT_CREATE` 函数模块来创建会计凭证,并且在创建过程中进行了错误检查。
阅读全文