Skip to Content

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

 

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    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:

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
         <soap:Header></soap:Header>
          <soap:Body>
               <soap:Fault>
                    <faultcode xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">soap-env:Server</faultcode>
                    <faultstring xml:lang="en">Error in the web service treatment; More details in the service error record on the provider page (UTC marker 20180314144916; transaction ID 15497D19BEB60200E005AA26E4A0BC34) The service provider can access the error log from SAP backend</faultstring>
               </soap:Fault>
          </soap:Body>
    </soap:Envelope>

    Do you know what could be happen? My Request is very simple:

    <?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sfin="http://sap.com/xi/SAPSCORE/SFIN">
         <soapenv:Header/>
         <soapenv:Body>
               <sfin:JournalEntryBulkCreateRequest>
                  <MessageHeader>
                      <CreationDateTime>2002-05-30T09:00:00</CreationDateTime>
                  </MessageHeader>
                  <JournalEntryCreateRequest>
                      <MessageHeader>
                         <CreationDateTime>2002-05-30T09:00:00</CreationDateTime>
                      </MessageHeader>
                      <JournalEntry>
                           <OriginalReferenceDocumentType>BKPFF</OriginalReferenceDocumentType>
                           <OriginalReferenceDocument></OriginalReferenceDocument>
                           <OriginalReferenceDocumentLogicalSystem></OriginalReferenceDocumentLogicalSystem>
                           <BusinessTransactionType>PP</BusinessTransactionType>
                           <AccountingDocumentType>SA</AccountingDocumentType>
                           <DocumentHeaderText>HeaderValue</DocumentHeaderText>
                           <CreatedByUser>XXX</CreatedByUser>
                           <CompanyCode>2410</CompanyCode>
                           <DocumentDate>2017-03-11T09:00:00</DocumentDate>
                           <PostingDate>2017-03-11T09:00:00</PostingDate>
                           <Item>
                               <GLAccount>00004200000</GLAccount>
                               <AmountInTransactionCurrency>
                               <Amount>100.00</Amount>
                               <currencyCode>EUR</currencyCode>
                               </AmountInTransactionCurrency>
                           </Item>
                     </JournalEntry>
                  </JournalEntryCreateRequest>
            </sfin:JournalEntryBulkCreateRequest>
         </soapenv:Body>
    </soapenv:Envelope>

    Thanks in advance.

    Regards.

    (0) 
    1. Venkatesh P

      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.

      (1) 
  2. William Fan

    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?

    (0) 

Leave a Reply