Journal Entry API & Extension – Implementing Custom Fields Using Substitution
Overview
This how-to guide will show how to use custom logic for Journal Entry substitution to populate 2 custom fields by splitting the data that is in a field in the submitted payload.
Because the Journal Entry API is a SOAP based API, it is not currently possible to extend custom fields to the API, thus this guide is more of a workaround to have custom fields populated that are required by business requirements in the S/4HANA Cloud system. An unused field on the API will be used on the API and then the custom field(s) are populated from this field using custom logic.
In this example, we’ll use the standard field for document item text to send a value that is really 2 custom fields. We assume the fields are of fixed width, so the custom logic will split FIELD1FIELD2 into 2 values for the custom fields.
In addition to the API link above, the following links are helpful for Journal Entries and using substitution:
Post Journal Entries from External Systems
This link provides the type of substitution available for Journal Entries.
Custom Field for Journal Entries
Substitution for Journal Entries
Interface Setup
For this scenario, an iFlow was created on SAP Cloud Platform Integration (CPI). Usually a 3rd party system would send Journal Entries to the iFlow but in this case the iFlow just exposes an HTTPS service to accept a JSON payload.
As shown in the above figure, a very basic iFlow was created to accept a JSON payload, convert to XML, map to the Journal Entry API and then post the journal entry to the S/4HC system.
The Journal Entry API uses communication arrangement SAP_COM_0002 which was configured as well in the S/4HC system.
S/4HANA CLOUD CONFIGURATION FOR SUBSTITUTION
You can find the documentation on extensibility (including how to create custom fields and custom logic) online: http://help.sap.com/s4hana -> SAP S/4HANA Cloud <latest version> Product Assistance Generic Information General Functions for the Key User Extensibility
Create Custom Fields
In this step, 2 custom fields will be created.
In S/4HC, navigate to Extensibility->Custom Fields and Logic
Click on the New icon
Complete the data for the custom field based on the requirements
Edit the field and enable the field as per your requirements.
For example, we will enable the fields for Accounting Journal Entry Item Cube and a few other screens where the field should be used.
Save and Publish the custom field
Repeat these same steps for field2
Implement Custom Logic
Navigate to Extensibility->Custom Fields and Logic app
Click on Custom Logic tab and create a new enhancement.
In this example, we’ll use the business context “Journal Entry Item”, definition “Journal Entry Item Extension Fields Substitution” and provide the other parameters.
There is sample code in the enhancement(s) already. You can leave all code in place that is provided to preserve the submitted values.
In this example, we’ll use a standard string function for ABAP to split the submitted field and populate the two custom fields from the documentitemtext on the API.
ls_acdoc_ext_out-yy1_customfield11_jei = lr_journalentryitem->documentitemtext+0(6).
ls_acdoc_ext_out-yy1_customfield2_jei = lr_journalentryitem->documentitemtext+6(6).
substitutiondone = abap_true.
Testing the Setup
To test the functionality, the Postman tool was used to call the iFlow on CPI. A JSON journal entry with two items is submitted as the payload.
The successful response:
I quickly created a custom query w on the Accounting Line Item Cube with the two custom fields added for validation purposes. The custom fields are populated with the journal entry.
That’s all for now!
Best Regards,
Marty
Good blog Marty.
Hi Marty,
I’ve tried to implement this scenario in my S/4 cloud system but all of my request returns the same system error:
Do you know what could be happen? My Request is very simple:
Thanks in advance.
Regards.
Hi,
Your DateTime format is wrong. It should be 2018-04-30T14:00:00Z. Also there should be one more item with Debit amount details.
hi,
I tried to post to https://<host name>:<port>/sap/bc/srt/scs/sap/journalentrycreaterequestconfi.... I keep getting 401 Unauthorized error.
I tried following URL and it is fine with GET.
https://<host name>:<port>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/$metadata
Do you know what could be the issue?
Hi,
How can we extend the app in on-premise system.
BADIs available does not have the custom fields.Please suggest