Sub topic 8
Creating and managing purchase orders
This chapter assumes you know the organizational units (company code, plant, purchasing organization, purchasing group), have supplier and material master data in place, and understand how a purchase requisition is created. You should be able to read basic ABAP.
What a purchase order is
A purchase order (PO) is a binding request from your purchasing organization to a supplier to deliver materials or services under stated conditions. It is the central document of procure-to-pay. Goods receipts, invoice receipts and payments all refer back to it.
A PO has two levels of structure:
- Header: supplier, document type, company code, purchasing organization, purchasing group, currency, payment terms and incoterms.
- Items: material or short text, plant, quantity, unit, price, item category and account assignment. Each item has one or more schedule lines that hold delivery dates and quantities.
The header values are defaults for the items. You can override most of them on an item.
Where the data comes from
A PO can be created in several ways. The route determines how much data is copied for you.
| Route | What is copied | Typical use |
|---|---|---|
| From a purchase requisition | Material, quantity, plant, delivery date, account assignment, source of supply | Planned or requested demand |
| From a contract or scheduling agreement | Supplier, price, validity, conditions | Repeat buying at agreed terms |
| From a quotation | Supplier and quoted prices | Competitive sourcing |
| Manually, without reference | Nothing. You enter it | One-off or urgent purchases |
| By interface (BAPI or API) | Whatever the caller supplies | Integration and mass creation |
When a source of supply is found, the system proposes conditions from the info record or contract. Without a source, you enter the price by hand.
Document types and item categories
The document type controls number ranges, field selection and which reference documents are allowed. NB is the standard PO. Other types, such as framework orders or stock transport orders, behave differently.
The item category controls what the item needs:
- Standard: a material delivered and invoiced.
- Service: services entered and accepted through service entry sheets.
- Subcontracting: components are provided to the supplier.
- Consignment: stock at your site belongs to the supplier until you consume it.
- Stock transfer: stock moves between your plants.
The account assignment category decides whether the item posts to stock or directly to a cost object. For example, category K posts to a cost center. The account assignment also determines which goods receipt and invoice accounting happens later, so a wrong choice here is hard to fix once postings exist.
Creating a PO in the Fiori app
In S/4HANA you normally use the Fiori app Manage Purchase Orders (or Create Purchase Order – Advanced). The transaction ME21N still works. The steps are the same in both:
- Choose the document type and enter the supplier.
- Enter organizational data: purchasing organization, purchasing group, company code.
- Add items, either manually or by pulling in requisitions.
- Check prices, delivery dates and account assignment.
- Resolve messages, then save or submit for release.
When you save, the system assigns the PO number and writes the document to the purchasing tables. The header is stored in EKKO, items in EKPO, and schedule lines in EKET.
Status and what you can change
A PO moves through states, and some of them restrict editing.
Rules that matter in practice:
- Quantity and price can usually be changed until follow-on documents exist. After a goods receipt, lowering the quantity below the received amount is not allowed.
- Changing price after invoicing affects only later invoices. Earlier ones are not recalculated.
- A change to a released PO can trigger the release strategy again, depending on whether the changed value falls under the strategy's change-release settings.
- You do not delete an item that has history. Instead set a deletion indicator (or a block indicator). The item stays visible but receives no further goods receipts or invoices.
- Setting the delivery completed indicator tells the system no more goods are expected, even if less than the ordered quantity arrived.
Output and communication
After the PO is saved and released, it is sent to the supplier through output management. The channel can be print, email or electronic exchange such as EDI. Output is controlled by message types and determination rules. A common error is a PO that is saved correctly but never sent because no output condition record matched. Check the output status in the PO header if a supplier says they did not get the order.
Important item controls
Several item fields control the later steps of the process:
- Goods receipt indicator: whether a goods receipt is expected.
- Invoice receipt indicator: whether an invoice is expected.
- GR-based invoice verification: whether each invoice line must match a specific goods receipt.
- Under- and overdelivery tolerance: how far the delivered quantity may deviate from the ordered quantity.
- Confirmation control key: whether the supplier must send order acknowledgements or shipping notifications.
If goods receipt is off for a standard item, the invoice can be posted without any receipt. This is intended for some services and expense items. It is a frequent source of unwanted two-way matches.
Reading PO history
Each posting for a PO item (goods receipt, invoice, delivery cost) is recorded in the PO history table EKBE. The VGABE field is the transaction or event type: 1 for goods receipt and 2 for invoice receipt. The following code lists the history for one PO.
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.Compare the sum of goods receipt quantities with the sum of invoice quantities per item to find items that are received but not yet invoiced, or the reverse.
Creating a PO with a BAPI
For integration, use BAPI_PO_CREATE1. It takes each data structure twice: once with values, and once with the same field names set to X in a structure ending in X. The X structure tells the BAPI which fields you supplied. If you fill a field but not its X flag, the value is ignored.
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
- Missing X flags in the BAPI. The value is silently dropped, and the PO is created with a default or an error about a required field.
- No source of supply found. The price is zero or the info record is missing for the supplier, material and plant combination. Create the info record or enter a manual price.
- Wrong account assignment category. The item posts to the wrong object later. Correct it before any goods receipt.
- Release strategy not triggered or not cleared. The PO stays blocked and cannot receive goods. Check the strategy's classification values, which usually depend on document type, group and value.
- Unexpected two-way match. The goods receipt indicator is off, so invoices post without a receipt.
- PO not delivered to the supplier. The output condition did not match, or the message status is not processed.
Exercise
A developer calls BAPIPOCREATE1 with a filled item structure containing material, plant and quantity, but leaves the item X structure empty except for the item number. The call returns no error messages. What happens to the item data, and what must be done before the PO is saved permanently?
Show answer
The BAPI ignores the material, plant and quantity because their flags in the X structure are not set to 'X', so the item is created without them or fails on required fields. Set the matching X flags (material, plant, quantity, plus poitemx) to abaptrue. Then check the RETURN table for E and A messages, and call BAPITRANSACTIONCOMMIT only if there are none, otherwise BAPITRANSACTIONROLLBACK.
Exercise
A PO item has been fully delivered, but 2 pieces of the ordered 100 never arrived and the supplier will not send them. How do you prevent the item from showing as open?
Show answer
Set the delivery completed indicator on the item. The system then treats the item as fully delivered even though only 98 pieces were received, and no more goods receipts are expected.