Implementing Customer Exit for Invoices with Service Type Line Items

Objective

After completing this lesson, you will be able to implement a Customer Exit for Invoice to support Service Invoice functionality.

Implementing Customer Exti for Invoices with Service Type Line Items

The Customer Exit mechanism in SAP ABAP is a powerful way to customize SAP standard functionality without modifying the core code. This ensures your enhancements are upgrade-safe, maintainable, and business-specific.​​

You can insert custom business rules, validations, or calculations specific to your organization’s needs. Customer exits remain intact during upgrades because they are isolated in dedicated includes or function modules. Customer exits support various use cases, such as Menu Exits, Screen Exits, Function Module Exits, and Field Exits.​​

Customer exits are part of the SAP enhancement framework, which includes BAdIs (Business Add-Ins) and Enhancement Points. They work together to provide developers with flexibility while keeping the system standard-compliant.​​

Since customer exits reside in their own namespace (e.g., ZX*, Z*), they are easy to document, review in audits, and transport between systems. ​

In SAP, an INCLUDE is provided inside a Customer Exit to offer customers a safe and structured place to write custom code without directly modifying SAP standard programs. The INCLUDEs in Customer Exits act like a secure sandbox for your custom logic — eliminating the risk of breaking standard code and remaining fully protected during upgrades.​​

The INCLUDE statement modularizes code by inserting the content of one ABAP program or code block into another. It functions like are usable container for code and is especially helpful for organizing large programs.​​

The INCLUDE statement instructs the ABAP runtime to insert the source code from the specified include program at that point during compilation.​​

The advantages of INCLUDE statements are: ​

  • Modularity: Breaks large programs into smaller, logical blocks, making the code easier to understand and manage. ​
  • Reusability: Allows common logic, declarations, and routines to be written once in an include and reused across multiple programs or function modules.​
  • Maintainability: INCLUDE statements isolate specific functionality, enabling updates or bug fixes in one place without affecting unrelated code. ​
  • Enhancement support: SAP often places enhancement points inside INCLUDES, making them ideal for customer-specific extensions (for example, implicit enhancements). ​
  • Version control and transport simplicity: Smaller INCLUDE files simplify tracking changes and managing transports in a controlled manner.​
Visual of the advantages of INCLUDE statements.

The Managed Gateway AddOn INCLUDE offers various statements to address specific requirements for integrating the backend SAP system with SAP Ariba. There are three INCLUDE statements included in this customer exit for the invoice that you need to implement:​

  • INCLUDE ARBCIG_INCL_INCOMING_INVOICE01 IF FOUND has logic for parking Service Invoices and non-PO invoices. This INCLUDE helps those customers to park invoices who have a service PO with GR-based IV and do not have an SES reference in the invoice. Customers also need to ensure that the INV_HDR_PRK_NOSES_POGRX_ENBLD parameter is enabled.​
  • INCLUDE ARBCIG_INCL_INCOMING_INVOICE03 IF FOUND manages hierarchy and the line numbers in the service invoice. It uses SRVMAPKEY to form the correct service hierarchy.​ ​
  • INCLUDE ARBCIG_INCL_INCOMING_INVOICE02 IF FOUND handles accounting information in the non-PO invoices. In the non-PO invoices, shipping and handling charges added as service lines on the invoice need to be posted to G/L directly, and for that, additional information needs to be fetched in an extension segment. This INCLUDE reads the data from the extension segment and does the needful. ​

The standard SAP Invoice IDoc (INVOIC) doesn’t support invoices with service line items or non-PO invoices with shipping and handling charges, so you need to implement these three exits to handle this functionality. The customer exits under enhancement MRMH0002 are updated to include the parking of non-PO invoices without accounting details received from SAP Business Network.​

Follow these steps to implement Customer Exits for Invoice:​​

  1. Using the transaction code SPRO, navigate to Integration with Other SAP Components>Managed Gateway for Spend&Network for Buyer>SAP Business Network Integration>Application Specific Settings>Invoice.​

    Image of step 1.
  2. Expand the Invoice section and select IMG-Activity for Implement Customer Exit for Invoices with Service Type Line Items.Image of step 2.
  3. On the Project Management of SAP Enhancements screen, enter the value or name in the Project field, for example ZTEST1,and select the Create button.Image of step 3.
  4. On the Attributes of Enhancement Project ZTEST1 screen, enter a meaningful description in the Short Text field, and select the Enhancement assignments button.Image of step 4.
  5. On the SAP Enhancements in Enhancement Project ZTEST1 screen, enter the Enhancement name MRMH0002, and choose the Enter key.Image of step 5.
  6. Return to the Attributes of Enhancement Project ZTEST1 screen and select the Components button.Image of step 6.
  7. On the Display ZTEST1 screen, double-click the User Exit EXIT_SAPLMRMH_011.Image of step 7.
  8. On the Function Builder: Display EXIT_SAPLMRMH_011 screen, scroll-down to locate INCLUDE ZXM08U22, position your cursor on ZXM08U22, and double-click on it.Image of step 8.
  9. On the ABAP Editor: Display Include ZXM08U22 screen, select Display <-> Change button from the menu bar at the top.Image of step 9.
  10. On the ABAP Editor: Change Include ZXM08U22 screen, enter the INCLUDE statement INCLUDE ARBCIG_INCL_INCOMING_INVOICE01 IF FOUND.
  11. Select the Activate button from the menu bar at the top.Image of steps 10 and 11.
  12. Return to the Display ZTEST1 screen and double-click the User Exit EXIT_SAPLMRMH_014.Image of step 12.
  13. On the Function Builder: Display EXIT_SAPLMRMH_014 screen, scroll-down to locate INCLUDE ZXM08U25, position your cursor on ZXM08U25, and double-click on it.Image of step 13.
  14. On the ABAP Editor: Display Include ZXM08U25 screen, select Display <-> Change button from the menu bar at the top.Image of step 14.
  15. On the ABAP Editor: Change Include ZXM08U25 screen, enter the INCLUDE statement INCLUDE ARBCIG_INCL_INCOMING_INVOICE03 IF FOUND.
  16. Select the Activate button from the menu bar at the top.Image of steps 15 and 16.
  17. Return to the Display ZTEST1 screen and double-click the User Exit, EXIT_SAPLMRMH_015.Image of step 17.
  18. On the Function Builder: Display EXIT_SAPLMRMH_015 screen, scroll-down to locate INCLUDE ZXM08U26, position your cursor on ZXM08U26, and double-click. Image of step 18.
  19. On the ABAP Editor: Display Include ZXM08U26 screen, select Display <-> Change button from the menu bar at the top.Image of step 19.
  20. On the ABAP Editor: Change Include ZXM08U26 screen, enter the INCLUDE statement INCLUDE ARBCIG_INCL_INCOMING_INVOICE02 IF FOUND.
  21. Select the Activate button from the menu bar at the top.Images of steps 20 and 21.
  22. Return to the Project Management of SAP Enhancements screen and select the Activate project button.Image of step 22.

Summary

Customer Exits let you add business rules, validations, and calculations without changing SAP standard code. Your changes stay upgrade-safe and easy to maintain. Customer Exits are part of the SAP enhancement framework, along with Business Add-Ins and enhancement points. They help you extend functionality while staying compliant.​

Exit code lives in the customer namespace (Z* or ZX*), which simplifies audits, documentation, and transports. INCLUDEs give you a safe, structured place to write exit code. They support modularity, reusability, maintainability, enhancement points, and simpler transports. ABAP inserts the INCLUDE’s code at compile time.​

The standard INVOIC IDoc does not handle service line items or non‑purchase‑order invoices with shipping and handling charges. You must implement three Managed Gateway AddOn INCLUDEs for invoices to cover these cases.​

For invoices from SAP Business Network, implement these in enhancement MRMH0002:​

  • ARBCIG_INCL_INCOMING_INVOICE01 has logic for parking Service Invoices and non-PO invoices. This INCLUDE helps those customers to park invoices who have a service PO with GR-based IV and do not have an SES reference in the invoice. Customers also need to ensure that the INV_HDR_PRK_NOSES_POGRX_ENBLD parameter is enabled.​
  • ARBCIG_INCL_INCOMING_INVOICE03 manages hierarchy and the line numbers in the service invoice. It uses SRVMAPKEY to form the correct service hierarchy.​ ​​
  • ARBCIG_INCL_INCOMING_INVOICE02 handles accounting information in the non-PO invoices. In the non-PO invoices, shipping and handling charges added as service lines on the invoice need to be posted to G/L directly, and for that, additional information needs to be fetched in an extension segment. This INCLUDE reads the data from the extension segment and does the needful. ​