Introduction
In this Blog post will be described, how to extract list of Journal Entries, created for the last week from S/4HANA Cloud via CDS View.
For this scenario following apps will be used:
- View Browser
- Custom CDS View
- Customer communication scenario
- Communication user
- Communication system
- Communication agreement
Additional we will Postman for testing.
Preparation
First of all we will check, which standard CDS view fits perfectly to extract data about Journal Entries. For this we can use
View Browser app and make a search by "
Journal Entry". We also need to filter only released views:
I_JournalEntryOperationalView CDS View will fit perfectly for the scenario:
Then we can move to
Custom CDS View app.
Before start with the main custom CDS View we have to prepare one, which will help us to extract delta. It will be of Standard type and also will have I_JournalEntryOperationalView CDS View as data source:
In the
Elements we can leave all Key fields, and then we need one additional field to calculate time detla:
Expression for Delta field would be as following:
DATS_DAYS_BETWEEN(cast( $session.system_date as ABAP.DATS ), I_JournalEntryOperationalView.ClearingDate)
Now we can save and publish the CDS View.
Creating main CDS View
Now let´s create custom CDS view for data extraction. It will be of
External API type and contain 2 data sources:
I_JournalEntryOperationalView and recently created
CDS view for delta calculation.
These data sources will be joined by the following conditions:
In the
Elements tab we will need all key fields and 2 additional: Clearing date and
DeltaClearingDate from earlier created
Delta CDS View:
As the final step for this part we need to provide filter: we need to check, if
DeltaClearingDate greater or equal 7 days.
It is important to mention, that entry should be "-7", as we calculate the difference. Additionally we can add filter to exclude records with empty clearing date:
You can check, if the logic works correctly with
Preview button in bottom right corner.
Now you can save and publish CDS View.
Preparing communication environment
The first step of this part is to add created CDS View to custom communication scenario. So in the app
Custom Communication Scenarios press New, provide meaningful Scenario ID and Description, and on the next screen add created CDS View as Inbound Service:
Check and
publish the scenario.
As the next step – we need
communication system with
communication user. These settings we can do in the app
Communication Systems:
Provide any
name to the System and on the next screen fill fields
Host Name,
Logical System and then Scroll down to the part
Users for Inbound Communication:
Click on the “+” symbol and select then “
New user“:
Provide any
User Name and
Description, click
Propose Password and note down entered User name and the proposed password:
Then click
Create and
Ok.
Save the Communication System.
Going further we need c
ommunication arrangement. To create it we will use the app
Communication Arrangements:
Here we need to enter the
name of the
Custom Communication Scenario, we created earlier.
And the only thing we need to provide in the Communication Arrangement further is
Communication System, which we created. Corresponding Communication User will be mapped automatically.
Copy OData V2 link from this page.
Testing in Postman
Create
new Tab in Postman and
enter the copied link. Provide
credentials on
Authorization tab of the Inbound Communication User, you created earlier. Click
Send to test the API:
If the response status is 200 OK,
extend the URL with “
/$metadata” and
send the request again. Find
EntityType Name in the response and
copy it:
Extend the
URL with the copied name and
delete “Type” in the end of the URL,
send the request again:
Finally, in the reply you can
find the Journal Entries, created for the last week.
Make sure, that such data is available in the system before testing.