Sub topic 18
Period-end GR/IR clearing and accruals
This chapter assumes you know the three-way match, the GR/IR clearing account, and basic ABAP and OData reading. It first covers what to do with GR/IR balances at period end. It then shows how to read and create purchasing data through APIs.
Why the GR/IR account has a balance at period end
A goods receipt posts a debit to inventory or expense and a credit to the GR/IR clearing account. The invoice receipt posts a debit to GR/IR and a credit to the supplier. When both have happened for the same quantity and value, the account nets to zero for that item.
At period end, some items are still open:
- Goods were received but the invoice has not arrived. GR/IR holds a credit balance.
- An invoice was posted before the goods arrived. GR/IR holds a debit balance.
An open credit balance means you owe the supplier for goods that are not yet in your payables. Reporting it as a clearing balance would understate your liabilities.
Clearing and accruals
Two month-end tasks deal with this.
- GR/IR clearing. Review the open items, usually with the Fiori GR/IR reconciliation apps or the classic GR/IR maintenance transaction. Clear items that will never be matched, such as a final partial delivery that was cancelled.
- Accruals. For received-not-invoiced items, post a reversing accrual. It debits an expense or adjustment account and credits an accrued liability account. The reversal in the next period offsets it, so the real invoice does not double-count the cost.
Reading purchasing data through APIs
Standard OData services let external systems read purchasing data without custom ABAP. This request reads five purchase orders from API_PURCHASEORDER_PROCESS_SRV and returns four header fields:
GET /sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/A_PurchaseOrder?$top=5&$select=PurchaseOrder,Supplier,PurchaseOrderType,CompanyCode HTTP/1.1
Accept: application/jsonInside the system, ABAP SQL reads the PO history table EKBE. VGABE 1 marks goods receipts and VGABE 2 marks invoice receipts. Comparing the two quantities per item shows which items are received but not invoiced.
SELECT ebeln, ebelp, vgabe, belnr, buzei, menge
FROM ekbe
WHERE ebeln = @lv_ebeln
ORDER BY ebelp, belnr
INTO TABLE @DATA(lt_history).
LOOP AT lt_history INTO DATA(ls_hist).
" VGABE 1 = goods receipt, 2 = invoice receipt
WRITE: / ls_hist-ebelp, ls_hist-vgabe, ls_hist-belnr, ls_hist-menge.
ENDLOOP.Creating a purchase order with a BAPI
A BAPI is a released function module that applies SAP's own checks. BAPI_PO_CREATE1 needs the data structures and a matching "X" structure for each. The X structure tells the BAPI which fields you supplied. Check the RETURN table for error (E) or abort (A) messages before you commit.
DATA: lv_ebeln TYPE bapimepoheader-po_number,
lt_return TYPE STANDARD TABLE OF bapiret2 WITH EMPTY KEY,
lt_item TYPE STANDARD TABLE OF bapimepoitem WITH EMPTY KEY,
lt_itemx TYPE STANDARD TABLE OF bapimepoitemx WITH EMPTY KEY,
lt_sched TYPE STANDARD TABLE OF bapimeposchedule WITH EMPTY KEY,
lt_schedx TYPE STANDARD TABLE OF bapimeposchedulx WITH EMPTY KEY.
" Values below are placeholders; use data that exists in your system.
DATA(ls_header) = VALUE bapimepoheader(
comp_code = '1710' doc_type = 'NB' vendor = '0017300001'
purch_org = '1710' pur_group = '001' ).
DATA(ls_headerx) = VALUE bapimepoheaderx(
comp_code = abap_true doc_type = abap_true vendor = abap_true
purch_org = abap_true pur_group = abap_true ).
lt_item = VALUE #( ( po_item = '00010' material = 'TG11' plant = '1710' quantity = 10 ) ).
lt_itemx = VALUE #( ( po_item = '00010' po_itemx = abap_true material = abap_true
plant = abap_true quantity = abap_true ) ).
lt_sched = VALUE #( ( po_item = '00010' sched_line = '0001'
delivery_date = sy-datum + 14 quantity = 10 ) ).
lt_schedx = VALUE #( ( po_item = '00010' sched_line = '0001' po_itemx = abap_true
sched_linex = abap_true delivery_date = abap_true quantity = abap_true ) ).
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = ls_header
poheaderx = ls_headerx
IMPORTING
exppurchaseorder = lv_ebeln
TABLES
return = lt_return
poitem = lt_item
poitemx = lt_itemx
poschedule = lt_sched
poschedulex = lt_schedx.
IF line_exists( lt_return[ type = 'E' ] ) OR line_exists( lt_return[ type = 'A' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true.
ENDIF.Common errors
| Symptom | Likely cause |
|---|---|
| PO fields stay empty after the BAPI call | The matching X structure flag is missing |
| PO number is returned but the PO does not exist | The commit was skipped or a rollback ran |
| GR/IR balance reappears after clearing | A late invoice matched an item you had already cleared |
Exercise
A goods receipt for 10 pieces was posted in March. The invoice arrives in April. What does the accrual do at the end of March, and why is it reversed in April?
Show answer
The March accrual records the liability and the cost for goods already received but not yet invoiced. It is reversed in April so that the real invoice posting does not count the same cost twice.
Exercise
After calling BAPIPOCREATE1, the RETURN table has a message of type E. What should the program do?
Show answer
Call BAPITRANSACTIONROLLBACK and do not commit, because an error message means the purchase order was not created correctly.