Technical Articles
Extending Electronic Outgoing Invoices for Government Tracking using In-App Extensibility
Introduction
Nowadays, technology and digitalization are powerful means of preventing and dealing with corruption. The public sector has been tremendously changed by the digital transformation, which has brought benefits like transparency, efficiency, better delivery of services and accountability.
In Italy, the government issues CUP and CIG codes to identify contracts or assignments with public investments. These codes help the government to track the financial data. Also, following the same purpose, a purchase order number reference is required in the accounting document, functionality which is not available in the standard solution, but that can be achieved as described in the following blog post.
- CUP (Codice Unico di Progetto) – Unique Project Code
- CIG (Codice Identificativo Gara) – Tender Identification Code
These codes and the customer purchase order ID needs to be reported in the electronic invoice.
After the accounting document is posted from “Create Outgoing Invoices” app, it’s transferred to eDocument Cockpit and the following tags have to be filled in the XML of eDocument Cockpit:
2.1.2 <DatiOrdineAcquisto>
2.1.2.2 <IdDocumento> – purchase order number (field required)
2.1.2.6 <CodiceCUP> – CUP code;
2.1.2.7 <CodiceCIG> – CIG code;
In order to bring the purchase order number into the XML line of IdDocumento, an approach would be to create a Custom Business Object that contains the Invoice Number and the Purchase Order Reference number.
Invoice Number | Purchase Order Reference |
This Custom Business Object will be available for a key user to fill the data from the generated UI. If needed, custom logic can be added at the Business Object nodes level for actions or validations.
Also, a BAdI enhancement is needed for bringing the Purchase Order Reference associated to the Invoice Number and to populate the IdDocumento XML field. We will get into more details in the BAdI Implementation section.
Prerequisites
You have administrative access to SAP S/4HANA Cloud and have implementation experience in the system. Coding experience is also necessary, since this extensibility solution requires implementation of a coding logic.
Authorizations
Business Role | Business Role ID |
Administrator | SAP _ BR _ ADMINISTRATOR |
Billing Clerk | SAP_BR_BILLING_CLERK |
In-App Extensibility Enhancement
Overview:
Custom Business Object Creation
Log in to SAP S/4HANA Cloud system with the business role as administrator.
Navigate to the Extensibility group: App Custom Business Objects, select “New” and add the name of the Custom Business Object. Save the identifier of the Custom Business Object because it will be used in the BAdI implementation, then select “Create”.
On the Edit Custom Business Object page, check the “User Interface” and “Back End Service” so that a key user will be able to add new records from this Business Object UI.
If validations or custom logic is necessary at the level of the Business Object item, also check the “Determination and Validation” box.
In the “Fields” tab, add the Invoice Number and Purchase Order Reference fields. Here a length of 50 characters was chosen for the Invoice Number and a length of 200 characters for the Purchase Order Reference. Depending on the configuration of the Invoice Numbers and Purchase Order numbers in your system, you can set these numbers accordingly. This Business Object will be populated with the Purchase Order References and the Accounting Document numbers (Invoice Number).
Save and Publish the Custom Business Object.
Assigning the Custom Business Object to a Business Catalog
In order to access the UI of this Custom Business Object, this has to be assigned to a business catalog, from which a key user can select the tile associated to it and fill the information.
Select the “Maintain Catalogs” link from the published Custom Business Object page.
Select the “Add” button from the Custom Catalog Extensions page.
Select the Business Catalog from the list.
Check the Business Catalog box and select the “Publish” button.
Add values to the Custom Business Object
Select the “Purchase Order References” tile from the Billing Documents group.
Select “Create” and add new values to the Custom Business Object.
BAdI Implementation
The appropriate BAdI enhancement should be done in the Document Compliance Business Context, in the BAdI called “Italy XML file filling”.
Select the “Custom fields and logic” app from the Extensibility group.
There select the “Document Compliance” business context, the “Italy: XML File Filling” BAdI Description and add the Implementation Description, then select “Create”.
For the complete section of coding, please check the note (Login required):
3012527 – Coding Example – Extending Electronic Outgoing Invoices for Government Tracking using In-App Extensibility
Testing
For testing, we need to check if the purchase order number corresponding to the invoice, which was previously saved into the Custom Business Object, is displayed under the IDDocumento tag in the XML file generated for the invoice.
First, we will check if the extensibility capability was enabled in the system. Then, using the eDocument cockpit app, we will generate an XML for an already issued invoice and then check the IDDocumento tag.
As a final validation, we will check the Custom Business Object and see if the pair of purchase order number and invoice number are matching what is displayed in the XML file.
Validate extensibility function
Check in the system that the extensibility function is available – validate also the key user namespace in the given usage
Testing the xml file creation for the newly enhanced fields
Open the app eDocument Cockpit
Select via the checkbox the already created customer invoice
Display Preview of XML File
Choose a directory to download
Open in the folder the newly created document with e.g. Notepad++
Search for <DatiContratto> or <IdDocumento> or for the new field:
<CodiceCUP>
<CodiceCIG>
You should now be able to see the newly enhanced fields with a corresponding entry.
Test via App Custom Business Objects
Check of the technical implementation – use for this a user with corresponding rights like e.g. the Business Role Administrator (Business Role ID SAP_BR_ADMINISTRATOR)
Open the newly created business object in the corresponding namespace – current name in the test system: YY1_PURCHASEORDERREFERENCE
For the validation of the purchase order references the newly created invoice numbers should be visible.
Conclusion
With these steps you are extending the electronic outgoing invoices for government tracking.
For this you are using the In-App extensibility including usage of a BAdI enhancement which is needed for bringing the purchase order reference associated to the invoice number and to populate the corresponding XML fields.
Thank you for reading this blog post. Time to test! Please leave your comment and feedback.
For further information about Extending Electronic Invoices for Italy watch this video and more on extending localization you can find here.
Hello Stefan,
First of all, nice blog.
I have a doubt indeed. Is this solution only included for S/4HANA? Or do we have a similar BADI for SAP ERP.
Currently I need to implement attachments in XML file for eDocument in Italy in SAP ERP with HCI, and I don't find any documentation available.
Thanks,
Alejandro
Hello Alejandro,
thank you for the positive feedback. The solution described in this blog and the comments focus only on SAP S/4HANA Cloud. The used BAdI definition EDOC_IT_XML_FILE is an eDocument enhancement related to S/4HANA Cloud and also only for Italy.
I would draw your attention to these two SAP Notes with more background information about the topic, I hope they are helpful for your search:
2696897 - eDocument Italy Troubleshooting Guide
https://launchpad.support.sap.com/#/notes/2696897
2750430 - eDocument Italy: Product Assistance (SAP S/4HANA Cloud 1902)
https://launchpad.support.sap.com/#/notes/2750430
Thank you
Stefan
Hi Stefan,
Thanks for your prompt answer.
Unfortunately, for SAP ERP I don't find content related in SAP Notes about this BADI definition to embed files into XML in eDocument Solution.
Not sure if opening an incident would be useful for that.
Kind regards,
Alejandro
Hello Alejandro,
Thank you, this should be useful.
We focus in this blog about how to extend the electronic outgoing invoices using the In-App extensibility, so mainly we explain the topic of extending two additional fields + logic in the order-to-cash scenario including government e-invoicing in a general way for SAP S/4HANA Cloud.
Kind regards,
Stefan