Custom Agent Determination in SAP Flexible Workflow for Supplier Invoice Approval
In SAP MM, supplier invoice approval is often handled using the Flexible Workflow. However, standard configuration may not fully cover complex approval requirements. In such cases, Custom Agent Determination can be implemented using BAdI MRM_WORKFLOW_AGENTS
.
This blog explains how to implement a custom approval workflow for supplier invoices (MIR7), including creating custom tables, CDS views, Fiori custom logic, and defining workflow conditions.
1. Create Custom Tables
Two custom tables are required:
a. Table for Mapping User Approval
Table: ZMMT007 (Supplier Invoice Approval Agent Assignment)
FUNCTION
– Function keyFUNDESC
– Function descriptionAPP_LVL
– Approval levelBUS_USR
– Business user
b. Table for Mapping Condition Approval
Table: ZMMT008 (Invoice Release Strategy)
ZREL_GROUP
– Release groupZREL_STRAT
– Release strategyZFUNCTION
– FunctionZSIGN
– Comparison signZCURR
– CurrencyZAMOUNT
– Amount threshold
2. Create Custom CDS Views
CDS views are required for retrieving approval mapping data. Example definitions:
@AbapCatalog.sqlViewName: 'ZIWFINVOICE'
define view ZI_SUPP_INV_WF as select from zmmt007 {
key function as Function,
fundesc as FuncDesc,
app_lvl as AppLvl,
bus_usr as BusUser
}
@AbapCatalog.sqlViewName: 'ZIWFINVOICEREL'
define view ZI_SUPP_INV_REL_MAP as select from zmmt008 {
key zrel_group,
key zrel_strat,
zfunction,
zsign,
zcurr,
zamount
}
Make sure to release CDS Views for usage in custom logic by setting the API State to Use System-Internally (Contract C1).
3. Implement Custom Logic in Fiori
Navigate to Custom Logic app in Fiori and create a new implementation:
- Business Context: Procurement: Flexible Workflow
- BAdI: Determination of Workflow Agents for Supplier Invoice
- Implementation ID: BADI MRM_WORKFLOW_AGENTS
Sample ABAP snippet for custom agent selection:
DATA: lt_wf TYPE TABLE OF ZI_SUPP_INV_WF,
lt_wf_rel TYPE TABLE OF zi_supp_inv_rel_map,
ls_wf_relx TYPE zi_supp_inv_rel_map.
SELECT * FROM I_SupplierInvoiceAPI01
WHERE SupplierInvoice = @supplierinvoice
AND FiscalYear = @FiscalYear
INTO TABLE @DATA(lt_SupplierInv).
IF ls_invoice-companycode = 'JSB'
AND ls_invoice-ACCOUNTINGDOCUMENTTYPE = 'RE'
AND ls_invoice-INVOICEGROSSAMOUNT >= 1.
SELECT * FROM zi_supp_inv_rel_map
WHERE zrel_group = 'WPO-GEN-WF'
AND zrel_strat = 'ALL'
INTO TABLE @lt_wf_rel.
ENDIF.
In the Filter tab, set the filter: workflowscenario = WS00800303
.
4. Define Flexible Workflow Conditions
In the Fiori app Manage Workflows for Supplier Invoices, configure the workflows according to business rules. For example:
a. Invoice With PO
- Company code = JSB
- Invoice is based on PO
- Steps: Level-1 and Level-2 Agent Determination via BAdI
b. Invoice Without PO < 10 Million
- Company code = JSB
- Amount < 10,000,000 IDR
- Steps: Level-1, Level-2, Level-3 Agent Determination
c. Invoice Without PO ≥ 10 Million
- Company code = JSB
- Amount ≥ 10,000,000 IDR
- Steps: Level-1 to Level-4 Agent Determination
Conclusion
By combining custom tables, CDS views, and Fiori custom logic, businesses can implement robust and flexible approval workflows for supplier invoices in SAP. This approach ensures compliance, supports complex approval hierarchies, and automates the agent determination process.
👉 If you’re also interested in other SAP MM workflow enhancements, check out our related article on SAP Invoice Splitting.