Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / MM ABAP / MM for ABAP Developers – Exits, BAdIs, BAPIs & S/4HANA

MM for ABAP Developers – Exits, BAdIs, BAPIs & S/4HANA

MM ABAP · Logistics ·

Open the interactive lesson →
  1. Where to enhance MM: choosing the technique
  2. Purchase requisition and purchase order BAdIs
  3. Customer exits in MM
  4. BAdIs for goods movements, invoices and the material master
  5. BAPIs: requisitions, orders, goods movements, invoices, materials
  6. IDocs in MM
  7. Purchase order output and forms
  8. Common custom reports
  9. S/4HANA for MM developers
  10. Interview questions

What an ABAP developer actually builds in MM: checks and defaults in the purchase requisition and purchase order BAdIs, custom fields in ME21N, logic in MIGO and MIRO, programs that create documents with BAPIs, IDoc interfaces with suppliers, purchase order output and custom reports – and how all of this changes in S/4HANA (MATDOC, 40-character material number, released CDS views, APIs and clean-core extensibility). General techniques: CORE ABAP › 10 Enhancements, 07 Interfaces, 11 Forms; the same patterns for SD: SD ABAP › 04. Business background: pages 01 – 03.

Part 1 – Where to enhance MM: choosing the technique

MM enhancement points in requisition, purchase order, MIGO, MIRO and the material master

Requirement

Technique

Where

Check or default fields in ME21N / ME22N

BAdI ME_PROCESS_PO_CUST

Part 2

Same for purchase requisitions (ME51N)

BAdI ME_PROCESS_REQ_CUST

Part 2

Own fields on the PO screen

Append CI_EKKODB / CI_EKPODB + MM06E005 or ME_GUI_PO_CUST

Parts 2.3, 3

Influence the release strategy

Exits M06E0004 (PO) / M06B0002 (PR); S/4HANA flexible workflow BAdIs

Part 3, page 02

Checks or own tab in MIGO

BAdI MB_MIGO_BADI / MB_CHECK_LINE_BADI

Part 4

Update own tables with the material document

BAdI MB_DOCUMENT_BADI

Part 4

Change or check the invoice in MIRO

BAdIs INVOICE_UPDATE, MRM_HEADER_CHECK, MRM_PAYMENT_TERMS

Part 4

Material master checks

BAdI BADI_MATERIAL_CHECK / exit MGA00001

Part 4

Create documents from a program

BAPIs

Part 5

EDI with suppliers

IDocs ORDERS, ORDRSP, DESADV, INVOIC

Part 6

S/4HANA, clean core

Custom Fields, released BAdIs (MM_PUR_S4_…), released CDS views and APIs

Part 9

  • MM has hardly any FORM-based user exits like SD's MV45AFZZ: use the BAdIs first, CMOD customer exits where no BAdI exists. Implement BAdIs in SE19, customer exits in CMOD after reading them in SMOD. How the techniques differ: CORE ABAP › 10 Enhancements.

Part 2 – Purchase requisition and purchase order BAdIs

2.1 ME_PROCESS_PO_CUST – the main purchase order BAdI

Called by the Enjoy purchase order (ME21N / ME22N / ME23N, also BAPI_PO_CREATE1 / BAPI_PO_CHANGE) at every change of header, item, schedule line or account assignment. Each method receives an object for the document part; read with GET_DATA( ), change with SET_DATA( ).

Method

When

Typical use

INITIALIZE / OPEN

Start of the transaction / document opened

Initialise own buffers

PROCESS_HEADER

Header data changed

Default or check header fields (IM_HEADER, IF_PURCHASE_ORDER_MM, data MEPOHEADER)

PROCESS_ITEM

Item changed

Default or check item fields (IM_ITEM, IF_PURCHASE_ORDER_ITEM_MM, data MEPOITEM)

PROCESS_SCHEDULE / PROCESS_ACCOUNT

Schedule line / account assignment changed

Delivery date or cost center rules

CHECK

Check button or save

Final checks over the whole document; set CH_FAILED = abap_true to stop the save

POST

Document is saved, number known

Write own Z tables (same LUW)

CLOSE

Document closed

Clear buffers

FIELDSELECTION_HEADER / _ITEM

Screen field control

Make fields display-only, mandatory or hidden

METHOD if_ex_me_process_po_cust~process_item.
INCLUDE mm_messages_mac.                         " macros for messages in the PO log

DATA(ls_item) = im_item->get_data( ).            " structure MEPOITEM

" Default: storage location 0001 for plant 1000
IF ls_item-werks = '1000' AND ls_item-lgort IS INITIAL.
ls_item-lgort = '0001'.
im_item->set_data( ls_item ).
ENDIF.

" Check: items of material group SERV need an account assignment
IF ls_item-matkl = 'SERV' AND ls_item-knttp IS INITIAL.
mmpur_message_forced 'E' 'ZMM' '001' ls_item-ebelp '' '' ''.
im_item->invalidate( ).                        " item stays red, the PO cannot be saved
ENDIF.
ENDMETHOD.
  • Use the macros of include MM_MESSAGES_MAC (mmpur_message_forced, mmpur_metafield) so the message appears in the PO message log and points to the field – a plain MESSAGE … TYPE 'E' would break the Enjoy transaction and the BAPI.
  • Never COMMIT WORK in these methods; POST runs inside the SAP LUW of the purchase order.
  • ME_PURCHDOC_POSTED (method POSTED) runs after the document has been posted – for follow-up actions that must not change the PO.

2.2 ME_PROCESS_REQ_CUST – purchase requisition

The same design for ME51N / ME52N / ME53N and BAPI_PR_CREATE / BAPI_PR_CHANGE: PROCESS_HEADER, PROCESS_ITEM (IF_PURCHASE_REQUISITION_ITEM, data MEREQ_ITEM), PROCESS_ACCOUNT, CHECK, POST, FIELDSELECTION_*. ME_REQ_POSTED runs after the requisition is saved.

2.3 Custom fields in ME21N

  • Add the ZZ fields to the customer includes CI_EKKODB (header, table EKKO) or CI_EKPODB (item, table EKPO).
  • Screen: either customer exit MM06E005 (subscreens of SAPMM06E, Part 3) or BAdI ME_GUI_PO_CUST, which adds an own tab: methods SUBSCRIBE (register the subscreen), MAP_DYNPRO_FIELDS, TRANSPORT_FROM_MODEL / TRANSPORT_TO_DYNP (PBO) and TRANSPORT_FROM_DYNP / TRANSPORT_TO_MODEL (PAI). SAP ships an example implementation (function group MEPOBADIEX).
  • ME_PROCESS_PO_CUST then checks the new fields like standard ones.
  • For BAPI_PO_CREATE1 / BAPI_PO_CHANGE: add the fields to BAPI_TE_MEPOHEADER(X) / BAPI_TE_MEPOITEM(X) and pass them in EXTENSIONIN (BAPIPAREX).
  • S/4HANA: the Custom Fields app (the procurement business contexts for the purchasing document header and item) does all of this without modification – the field appears in ME21N, the Fiori apps and the APIs (Part 9).

Part 3 – Customer exits in MM

Enhancement (SMOD)

Area

Use

MM06E005

Purchasing documents

Customer fields in the PO header / item: subscreens on SAPMM06E, function exits EXIT_SAPMM06E_006 / _007 / _008 (header), _016 / _017 / _018 (item), _012 (check before save)

MEREQ001

Purchase requisition

Customer fields in the requisition (CI_EBANDB)

M06E0004

PO release

Fill own fields of the release communication structure CEKKO, so the release strategy can use them

M06B0002

PR release

Same for the requisition (communication structure CEBAN)

MM06E001

EDI purchasing

Custom segments in outbound ORDERS / ORDCHG and inbound ORDRSP

MBCF0002

Goods movement

Fill the item text MSEG-SGTXT (EXIT_SAPMM07M_001)

MB_CF001

Goods movement

Called when the material document is updated (EXIT_SAPLMBMB_001)

LMR1M001

Invoice verification

User exits in logistics invoice verification (function exits EXIT_SAPLMR1M_*; read the components in SMOD)

MRMH0002

EDI incoming invoice

Determine supplier, company code, tax code or unplanned costs differently (EXIT_SAPLMRMH_011 – _015)

MGA00001

Material master

Additional checks when a material is saved

  • Steps: SMOD → read the components → CMOD → create a project → assign the enhancement → write the code in the Z include of the function exit → activate the project.
  • Customer exits are classic, on-premise only. In S/4HANA most of them still work but are not clean-core; prefer BAdIs or the released S/4HANA BAdIs (Part 9.3).

Part 4 – BAdIs for goods movements, invoices and the material master

BAdI

Area

Methods / use

MB_MIGO_BADI

MIGO

Own tab and fields (PBO_DETAIL / PAI_DETAIL, PBO_HEADER / PAI_HEADER), change lines (LINE_MODIFY), checks (CHECK_ITEM), own data at posting (POST_DOCUMENT); register in INIT

MB_CHECK_LINE_BADI

Goods movements

Check the material document lines before they are transferred to the lock table (CHECK_LINE, also for BAPI postings)

MB_DOCUMENT_BADI

Material document

MB_DOCUMENT_BEFORE_UPDATE (before the update task) and MB_DOCUMENT_UPDATE (in the update task) with tables XMKPF, XMSEG – write own tables, trigger follow-ups

INVOICE_UPDATE

MIRO

CHANGE_AT_SAVE (check, stop the save), CHANGE_BEFORE_UPDATE, CHANGE_IN_UPDATE

MRM_HEADER_CHECK

MIRO

Check the invoice header data

MRM_PAYMENT_TERMS

MIRO

Set payment terms or payment block (PAYMENT_TERMS_SET)

BADI_MATERIAL_CHECK

Material master

CHECK_DATA: validations when a material is saved (MM01 / MM02 and BAPI_MATERIAL_SAVEDATA)

  • Do not post another goods movement or call COMMIT WORK in MB_DOCUMENT_BADI – it runs inside the update of the first one. Start follow-up postings asynchronously (e.g. a background job or a qRFC).
  • Finding the right BAdI: breakpoint on CL_EXITHANDLER=>GET_INSTANCE (classic BAdIs) or on the statement GET BADI (new BAdIs) while running the transaction; SE18 / SE84 by package (ME purchasing, MB inventory management, MRM invoice verification); SPRO → Materials Management → … → Business Add-Ins per area.
  • Release strategy and output also have BAdIs, but these are mostly configuration-driven; in S/4HANA the flexible workflow for PR and PO has its own BAdIs for agent determination and conditions (page 02).

Part 5 – BAPIs: requisitions, orders, goods movements, invoices, materials

Procure-to-pay with BAPIs: requisition, purchase order, goods receipt, supplier invoice, each followed by a commit

BAPI / FM

Purpose

BAPI_PR_CREATE / BAPI_PR_CHANGE

Create / change a purchase requisition (ME51N logic)

BAPI_PO_CREATE1

Create a purchase order (ME21N logic, runs ME_PROCESS_PO_CUST)

BAPI_PO_CHANGE

Change a PO; delete an item with POITEM-DELETE_IND = 'L'

BAPI_PO_GETDETAIL1

Read a PO with items, schedule lines, account assignment, history

BAPI_PO_RELEASE / BAPI_PO_RESET_RELEASE

Release a PO with a release code / cancel the release

BAPI_GOODSMVT_CREATE

Post any goods movement (MIGO logic)

BAPI_GOODSMVT_CANCEL

Reverse a material document

BAPI_INCOMINGINVOICE_CREATE1

Post a supplier invoice with PO reference (MIRO); BAPI_INCOMINGINVOICE_PARK parks it

BAPI_MATERIAL_SAVEDATA

Create or extend / change a material (all views)

BAPI_MATERIAL_GET_DETAIL, BAPI_MATERIAL_STOCK_REQ_LIST

Read material data / the MD04 stock-requirements list

BAPI_TRANSACTION_COMMIT / _ROLLBACK

End the LUW – BAPIs never commit themselves

5.1 Example: create a purchase order

  • Every structure has an …X partner that marks the fields you filled; item and schedule keys are repeated in the X tables (PO_ITEMX, SCHED_LINEX = 'X').
  • Supplier numbers with leading zeros; the schedule line DELIVERY_DATE is a 10-character field in the user's date format – convert it with DATE = USER.
DATA ls_header   TYPE bapimepoheader.
DATA ls_header_x TYPE bapimepoheaderx.
DATA lt_items    TYPE STANDARD TABLE OF bapimepoitem.
DATA lt_items_x  TYPE STANDARD TABLE OF bapimepoitemx.
DATA lt_sched    TYPE STANDARD TABLE OF bapimeposchedule.
DATA lt_sched_x  TYPE STANDARD TABLE OF bapimeposchedulx.
DATA lt_return   TYPE STANDARD TABLE OF bapiret2.
DATA lv_po       TYPE bapimepoheader-po_number.

ls_header = VALUE #(
comp_code = '1000'
doc_type  = 'NB'                                 " standard purchase order
vendor    = '0000300001'
purch_org = '1000'
pur_group = '001'
currency  = 'EUR' ).
ls_header_x = VALUE #(
comp_code = 'X'
doc_type  = 'X'
vendor    = 'X'
purch_org = 'X'
pur_group = 'X'
currency  = 'X' ).

lt_items   = VALUE #( ( po_item = '00010' material = 'RM-100' plant = '1000'
stge_loc = '0001' quantity = 10 net_price = '12.50' ) ).
lt_items_x = VALUE #( ( po_item = '00010' po_itemx = 'X' material = 'X' plant = 'X'
stge_loc = 'X' quantity = 'X' net_price = 'X' ) ).

DATA(lv_date) = CONV d( sy-datum + 14 ).
lt_sched   = VALUE #( ( po_item = '00010' sched_line = '0001' quantity = 10
delivery_date = |{ lv_date DATE = USER }| ) ).
lt_sched_x = VALUE #( ( po_item = '00010' sched_line = '0001' po_itemx = 'X'
sched_linex = 'X' quantity = 'X' delivery_date = 'X' ) ).

CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader         = ls_header
poheaderx        = ls_header_x
IMPORTING
exppurchaseorder = lv_po
TABLES
return           = lt_return
poitem           = lt_items
poitemx          = lt_items_x
poschedule       = lt_sched
poschedulex      = lt_sched_x.

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.
MESSAGE |Purchase order { lv_po } created| TYPE 'S'.
ENDIF.
  • S/4HANA: for 40-character material numbers fill MATERIAL_LONG (and the X flag) instead of MATERIAL. Conditions go into POCOND / POCONDX; a PR reference into POITEM-PREQ_NO / PREQ_ITEM.

5.2 Example: goods receipt with BAPI_GOODSMVT_CREATE

GM_CODE

Transaction it replaces

Use

01

MB01

Goods receipt for purchase order

02

MB31

Goods receipt for production order

03

MB1A

Goods issue

04

MB1B

Transfer posting

05

MB1C

Other goods receipts

06

MB11

Reversal of goods movements

07

MB04

Subsequent adjustment for a subcontract order

DATA ls_head   TYPE bapi2017_gm_head_01.
DATA ls_code   TYPE bapi2017_gm_code.
DATA lt_item   TYPE STANDARD TABLE OF bapi2017_gm_item_create.
DATA lt_return TYPE STANDARD TABLE OF bapiret2.
DATA lv_mblnr  TYPE mblnr.
DATA lv_mjahr  TYPE mjahr.

ls_head = VALUE #( pstng_date = sy-datum
doc_date   = sy-datum
ref_doc_no = 'DN-4711' ).       " delivery note of the supplier
ls_code-gm_code = '01'.                            " GR for purchase order

lt_item = VALUE #( ( po_number = p_ebeln
po_item   = p_ebelp
move_type = '101'
mvt_ind   = 'B'               " B = movement for a purchase order
entry_qnt = 10
plant     = '1000'
stge_loc  = '0001' ) ).

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header  = ls_head
goodsmvt_code    = ls_code
IMPORTING
materialdocument = lv_mblnr
matdocumentyear  = lv_mjahr
TABLES
goodsmvt_item    = lt_item
return           = lt_return.

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.
MESSAGE |Material document { lv_mblnr } / { lv_mjahr } posted| TYPE 'S'.
ENDIF.
  • MVT_IND: B purchase order, F production order, blank for other movements (then give MATERIAL, and e.g. COSTCENTER for 201 or MOVE_STLOC for 311).
  • Call it once per LUW: commit (or roll back) before the next call. Test without posting with TESTRUN = abap_true.
  • MB_DOCUMENT_BADI and MB_CHECK_LINE_BADI run for BAPI postings too.

5.3 Invoices and materials

  • BAPI_INCOMINGINVOICE_CREATE1: HEADERDATA (INVOICE_IND = 'X' for an invoice, DOC_DATE, PSTNG_DATE, COMP_CODE, GROSS_AMOUNT, CURRENCY, CALC_TAX_IND), ITEMDATA per PO item (PO_NUMBER, PO_ITEM, REF_DOC / REF_DOC_YEAR / REF_DOC_IT for GR-based invoice verification, TAX_CODE, ITEM_AMOUNT, QUANTITY, PO_UNIT); returns INVOICEDOCNUMBER and FISCALYEAR. Tolerance checks and payment blocks work as in MIRO.
  • BAPI_MATERIAL_SAVEDATA: HEADDATA (material, industry sector, material type, view flags such as BASIC_VIEW, PURCHASE_VIEW, ACCOUNT_VIEW), CLIENTDATA / CLIENTDATAX (MARA), PLANTDATA / PLANTDATAX (MARC), VALUATIONDATA / VALUATIONDATAX (MBEW), table MATERIALDESCRIPTION (MAKT). RETURN is a single structure; all messages are in RETURNMESSAGES. Internal numbers first with BAPI_MATERIAL_GETINTNUMBER. In S/4HANA the product API API_PRODUCT_SRV is the clean-core alternative.

Part 6 – IDocs in MM

Purchase order out, order confirmation, shipping notification and invoice in

Message type

Basic type

Direction

Meaning

Processing

ORDERS

ORDERS05

Outbound

Purchase order to the supplier

Output type NEU with medium 6 (EDI); FM IDOC_OUTPUT_ORDERS; exit MM06E001

ORDCHG

ORDERS05

Outbound

PO change

Change output of the PO; FM IDOC_OUTPUT_ORDCHG

ORDRSP

ORDERS05

Inbound

Order confirmation of the supplier

Process code ORDR, FM IDOC_INPUT_ORDRSP; confirmations in EKES

DESADV

DELVRY03 (or later)

Inbound

Shipping notification → inbound delivery

Process code DELS; inbound delivery (VL31N) in LIKP / LIPS + confirmation in EKES

INVOIC

INVOIC01 / INVOIC02

Inbound

Supplier invoice → LIV document

Process code INVL, FM IDOC_INPUT_INVOIC_MRM; exit MRMH0002

MBGMCR

MBGMCR03

Inbound

Goods movement (calls BAPI_GOODSMVT_CREATE)

ALE, e.g. from a warehouse system

MATMAS / CREMAS / INFREC

MATMAS05 / CREMAS05 …

Both

Material, supplier, info record distribution (ALE)

–

  • Outbound PO IDocs are triggered by output determination: output type with medium 6 (EDI) and a partner profile (WE20, partner type LI = supplier) with message type ORDERS.
  • Custom data: extend the basic type with a Z segment (WE31 / WE30), fill it in the customer exit (MM06E001 outbound, MRMH0002 inbound invoice).
  • ALE / IDoc basics (ports, partner profiles, WE19 test tool, BD87 reprocessing): CORE ABAP › 07 Interfaces. In S/4HANA many companies connect suppliers through SAP Business Network or SAP Cloud Integration with SOAP / OData APIs instead of IDocs.

Part 7 – Purchase order output and forms

NACE application

Documents

Output type / program / form

EF

Purchase order

NEU; program SAPFM06P, FORM ENTRY_NEU; SAPscript MEDRUCK

EA

RFQ

NEU; SAPFM06P; MEDRUCK

EV / EL

Contracts / scheduling agreements

NEU / LPH1 …; SAPFM06P

ME

Inventory management (GR / GI slips)

WE01 / WE02 / WE03; program SAPM07DR; reprint with MB90

MR

Invoice verification (e.g. ERS notices)

Program and form per output type

  • Condition records for PO output: MN04 create, MN05 change, MN06 display; (re)send output: ME9F. The output record is in NAST (NAST-OBJKY = PO number).
  • Custom form: copy MEDRUCK (or build a Smart Form / Adobe form), copy SAPFM06P only if the data retrieval must change, and enter program, FORM routine and form in NACE → output type → processing routines (TNAPR). Layout details: CORE ABAP › 11 Forms.
  • SAPscript texts (PO header and item texts) are stored in STXH (header) and STXL (lines); read them with READ_TEXT (object EKKO / EKPO).
  • S/4HANA output management: purchase orders use BRF+-based output determination (Fiori app Output Parameter Determination) with Adobe form templates (e.g. MM_PUR_PURCHASE_ORDER) and form data providers as the alternative to NAST and SAPFM06P; on-premise, NAST-based PO output is still supported (choose per object type in Customizing: Output Control → Manage Activation of Object Type) – the same model as SD ABAP › 03.

Part 8 – Common custom reports

Report

Main tables / views

Standard alternative

Open purchase orders (not yet delivered)

EKKO + EKPO + EKET (MENGE > WEMNG), EKPO-ELIKZ / LOEKZ; I_PurchaseOrderItemAPI01

ME2M, ME2L, ME2N, ME80FN

GR/IR balances per PO item

EKBE summed by VGABE 1 (GR) and 2 (IR)

MB5S, Monitor GR/IR Account Balances

Stock per material and storage location

MARD (ECC) / MATDOC via NSDM views; I_MaterialStock_2

MMBE, MB52, MB5B

Material documents of a period

MKPF + MSEG / MATDOC; I_MaterialDocumentItem_2

MB51

Invoices per supplier

RBKP + RSEG

MIR6, Manage Supplier Invoices

Purchasing value per supplier

EKKO + EKPO (S011 / S012 in ECC LIS)

ME81N, procurement analytics

  • The open-PO SELECT on EKKO / EKPO / EKET is on page 02 (Part 4.2); the same report on released CDS views is in Part 9.2 below.

Part 9 – S/4HANA for MM developers

9.1 Simplifications that change your code

Area

ECC

S/4HANA

What to do in code

Material documents and stock

MKPF / MSEG + stock tables MARD, MCHB …

MATDOC; compatibility views NSDM_E_*

SELECTs still work; no writes to stock tables; new code on MATDOC or CDS views (page 03 Part 2)

Material number

MATNR 18 characters

MATNR 40 characters

No hard-coded lengths or offsets; BAPI fields …_LONG (MATERIAL_LONG)

Supplier master

XK01 / MK01 / FK01, LFA1 …

Business partner (BP, CVI); LFA1, LFB1, LFM1 still filled

Create / change suppliers via BP APIs (page 01)

Goods movement t-codes

MB01, MB1A, MB1B, MB1C, MB31, MB11 …

MIGO only

Batch inputs on MB* → BAPI_GOODSMVT_CREATE

Purchasing t-codes

ME21 / ME22 / ME23, ME51 / ME52 / ME53

Enjoy ME21N … ME53N, Fiori apps

Replace batch inputs with BAPIs

PO conditions

KONV

PRCD_ELEMENTS

Replace SELECTs on KONV

Release

Classic release strategy

Release strategy or flexible workflow for PR / PO

BAdIs of the flexible workflow

Services

ESSR / ESLL service entry sheets

Lean services (service items, Fiori service entry sheet)

Check reports on ESSR / ESLL

MRP

MD01 / MD02 classic MRP

MRP Live (MD01N), runs in HANA

Check MRP exits / BAdIs

Valuation

Material ledger optional, FAGLFLEXA

Material ledger mandatory, ACDOCA

Read values from ACDOCA / CDS views

Statistics

LIS S011, S012, S013, S031

Embedded analytics on CDS views

Replace LIS-based reports

Output

NACE / NAST, SAPFM06P

Output management (BRF+, Adobe); NAST still supported for POs on-premise

Part 7

  • Find affected custom code with ATC and the S/4HANA readiness checks / Custom Code Migration app (ABAP on HANA › 02 Migration & Performance).

9.2 Released CDS views and APIs

Released CDS view (VDM)

Content

I_PurchaseOrderAPI01 / I_PurchaseOrderItemAPI01

Purchase order header / items

I_PurchaseRequisitionItemAPI01

Purchase requisition items

I_MaterialDocumentHeader_2 / I_MaterialDocumentItem_2

Material documents (on MATDOC)

I_MaterialStock_2

Stock quantities by material, plant, storage location, stock type

I_Product, I_ProductDescription, I_Supplier

Master data

I_SupplierInvoiceAPI01

Supplier invoices

" Open PO items on released CDS views – works in ABAP Cloud too
SELECT FROM I_PurchaseOrderAPI01 AS po
INNER JOIN I_PurchaseOrderItemAPI01 AS it ON it~PurchaseOrder = po~PurchaseOrder
FIELDS po~PurchaseOrder, po~Supplier, it~PurchaseOrderItem, it~Material, it~Plant,
it~OrderQuantity, it~PurchaseOrderQuantityUnit
WHERE po~PurchasingOrganization          = @p_ekorg
AND it~IsCompletelyDelivered           = @abap_false
AND it~PurchasingDocumentDeletionCode  = @space
INTO TABLE @DATA(lt_open).

API

Protocol

Use

API_PURCHASEORDER_PROCESS_SRV

OData V2

Create, read, change purchase orders (deprecated in S/4HANA Cloud Public Edition since 2308 – successor API_PURCHASEORDER_2)

API_PURCHASEORDER_2

OData V4, RAP-based

Newer purchase order API

API_PURCHASEREQ_PROCESS_SRV

OData V2

Purchase requisitions

API_MATERIAL_DOCUMENT_SRV

OData V2

Post and read goods movements

API_MATERIAL_STOCK_SRV

OData V2

Read stock

API_SUPPLIERINVOICE_PROCESS_SRV

OData V2

Create and read supplier invoices

API_PRODUCT_SRV, API_BUSINESS_PARTNER

OData V2

Product master, suppliers as business partners

All released APIs and views are listed on the SAP Business Accelerator Hub (api.sap.com). CDS and OData basics: ABAP on HANA › 05 CDS Views.

9.3 Clean-core extensibility for MM

MM extension options in S/4HANA: key user, developer (ABAP Cloud), classic
  • Key user: Custom Fields on PO / PR / product and Custom Logic in released BAdIs such as MM_PUR_S4_PO_MODIFY_HEADER / MM_PUR_S4_PO_MODIFY_ITEM (change PO data) and MM_PUR_S4_PR_MODIFY_ITEM for requisition items.
  • Developer extensibility (ABAP Cloud): the same released BAdIs in ADT, released CDS views, own RAP apps; the purchase order is available as a RAP business object interface for EML (I_PurchaseOrderTP_2) – see RAP › 08 · EML.
  • Classic extensibility (on-premise only): ME_PROCESS_PO_CUST, MB_MIGO_BADI, CMOD exits, SAPscript forms, direct table reads – allowed, but not upgrade-stable. Choose the highest level that solves the requirement (Clean Core › 01 Clean Core).

Part 10 – Interview questions

Q1. Which BAdI do you use to validate a purchase order?

ME_PROCESS_PO_CUST: PROCESS_HEADER / PROCESS_ITEM for field checks and defaults, CHECK for checks over the whole document (CH_FAILED stops the save), POST to write own tables. Messages via the MM_MESSAGES_MAC macros and IM_ITEM->INVALIDATE( ).

Q2. How do you add a custom field to the purchase order?

Append it to CI_EKKODB / CI_EKPODB, add a screen with customer exit MM06E005 or BAdI ME_GUI_PO_CUST, check it in ME_PROCESS_PO_CUST, and for BAPIs extend BAPI_TE_MEPOITEM(X) for EXTENSIONIN. In S/4HANA use the Custom Fields app.

Q3. Which enhancements exist for MIGO?

MB_MIGO_BADI (own tab, line changes, checks, POST_DOCUMENT), MB_CHECK_LINE_BADI (line checks), MB_DOCUMENT_BADI (before / in the update of the material document), exits MBCF0002 (item text) and MB_CF001.

Q4. What is GM_CODE in BAPI_GOODSMVT_CREATE?

The transaction the posting is based on: 01 GR for PO, 02 GR for production order, 03 goods issue, 04 transfer posting, 05 other receipts, 06 reversal, 07 subcontracting adjustment. Together with movement type and MVT_IND it decides which fields are required.

Q5. Why does your second BAPI_GOODSMVT_CREATE call in a loop fail?

The BAPI must be called once per LUW: call BAPI_TRANSACTION_COMMIT (WAIT = 'X') or ROLLBACK after each document before the next call.

Q6. How do you create a purchase order from a program?

BAPI_PO_CREATE1 with POHEADER / POITEM / POSCHEDULE and their X structures, check RETURN for E / A, then BAPI_TRANSACTION_COMMIT with WAIT. The BAdI ME_PROCESS_PO_CUST runs as in ME21N.

Q7. Which IDocs are used in MM?

ORDERS (PO out, ORDERS05), ORDCHG (PO change), ORDRSP (order confirmation in → EKES), DESADV (shipping notification in → inbound delivery), INVOIC (supplier invoice in via IDOC_INPUT_INVOIC_MRM), MBGMCR for goods movements.

Q8. How is the purchase order printed?

ECC: NACE application EF, output type NEU, program SAPFM06P with SAPscript MEDRUCK (or a custom Smart Form / Adobe form), condition records MN04, output record in NAST. S/4HANA: output management with BRF+ and Adobe form templates; NAST-based output is still supported for POs on-premise.

Q9. Which BAdI changes the invoice in MIRO?

INVOICE_UPDATE (CHANGE_AT_SAVE for checks, CHANGE_BEFORE_UPDATE, CHANGE_IN_UPDATE); MRM_HEADER_CHECK for header checks; MRM_PAYMENT_TERMS for payment terms and blocks; exits LMR1M001 and MRMH0002 (EDI).

Q10. Your old report reads MKPF, MSEG and KONV and uses 18-character material numbers. What changes in S/4HANA?

MKPF / MSEG are served from MATDOC through compatibility views (works, but read MATDOC or I_MaterialDocumentItem_2 for new code); KONV is replaced by PRCD_ELEMENTS; MATNR has 40 characters, so remove fixed lengths and offsets and use the …_LONG BAPI fields.

Q11. How do you write an open purchase order report?

Join EKKO, EKPO and EKET: purchase orders (BSTYP F), items not deleted and not delivery-completed, schedule lines with WEMNG < MENGE. In S/4HANA or ABAP Cloud use I_PurchaseOrderAPI01 / I_PurchaseOrderItemAPI01.

Q12. How would you extend the purchase order in a clean-core way?

Custom Fields for new fields, Custom Logic or ADT implementations of released BAdIs (MM_PUR_S4_PO_…) for logic, released CDS views and APIs (API_PURCHASEORDER_PROCESS_SRV – OData V2, deprecated in Public Edition since 2308 – or its OData V4 successor API_PURCHASEORDER_2) for reading and integration – ME_PROCESS_PO_CUST and CMOD exits only on-premise when no released option exists.

🏠 Start Here · ◀ 03 · Inventory & Invoices · 05 · T-Codes & Tables ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP