
api-access.
You can refer this blog to form a connection with SAP S/4HANA Cloud. Consume Remote Services from SAP S/4HANA Cloud Using CAP
Sales Order CAP Application
cds import ./API_SALES_ORDER_SRV.edmx
"cds": {
"requires": {
"API_SALES_ORDER_SRV": {
"kind": "odata-v2",
"model": "srv/external/API_SALES_ORDER_SRV",
"csrf": true,
"csrfInBatch": true,
cds watch
You can now see the api-sales-order-srv service with all its entities under Service Endpoints.
using {API_SALES_ORDER_SRV as order} from '../srv/external/API_SALES_ORDER_SRV';
service SalesOrderService @(path : '/Sales') {
entity SalesOrder as projection on order.A_SalesOrder;
};
@protocol: 'rest'
service OrderPostService {
@open
type object {};
action Create_Order(Order : object) returns object;
}
using {API_SALES_ORDER_SRV as order} from '../srv/external/API_SALES_ORDER_SRV';
service SalesOrderService @(path : '/Sales') {
entity SalesOrder as projection on order.A_SalesOrder;
};
@protocol: 'rest'
service OrderPostService {
@open
type object {};
action Create_Order(Order : object) returns object;
}
{
"systemName": "<set in mta.yaml>",
"communicationArrangement": {
"communicationArrangementName": "SAP_COM_0109",
"scenarioId": "SAP_COM_0109",
"inboundAuthentication": "BasicAuthentication",
"outboundAuthentication": "BasicAuthentication",
"communicationSystem": {
"communicationSystemHostname": "default.com",
"outboundCommunicationUser": {
"username": "DefaultUser",
"password": "DefaultPassword"
}
}
}
}
npm install @sap-cloud-sdk/http-client @sap-cloud-sdk/util
const cds = require('@sap/cds');
module.exports = cds.service.impl(async function (srv) {
const { SalesOrder, Create_Order } = this.entities;
// connects to the remote service
const order = await cds.connect.to('API_SALES_ORDER_SRV');
// Handle GET call
srv.on('READ', 'SalesOrder', async req => {
const order = await cds.connect.to('API_SALES_ORDER_SRV');
return order.run(req.query);
});
// Handle POST call
srv.on('Create_Order', async(req) => {
// Extract the Sales Order payload from the request data
const OrderData = req.data.Order;
// Map the POST request on remote service
const SalesOrderResponse = await order.run(INSERT.into('SalesOrderService.SalesOrder', [OrderData]));
// Return the response
return SalesOrderResponse;
});
});
cds mta add
resources:
- name: SalesOrder-order
type: org.cloudfoundry.managed-service
parameters:
skip-service-updates:
plan: true
parameters: true
tags: true
service: s4-hana-cloud
service-plan: api-access
system-name: XXXXXXXXXXXXXXXXXXXXXXX
path: ./order-service-config.json
config:
systemName: XXXXXXXXXXXXXXXXXXXXXXX
- name: SalesOrder-destination
type: org.cloudfoundry.managed-service
parameters:
config:
HTML5Runtime_enabled: true
init_data:
instance:
destinations:
- Authentication: NoAuthentication
Name: ui5
ProxyType: Internet
Type: HTTP
URL: https://ui5.sap.com
existing_destinations_policy: update
version: 1.0.0
service: destination
service-plan: lite
and update the srv dependancy as shown below
mbt build -t ./
cf deploy SalesOrder_1.0.0.mtar
@host = <<Your service url after deployment>>
@protocol = https
###
POST {{protocol}}://{{host}}/order-post/Create_Order
Content-Type: application/json
{
"Order":
{
"SalesOrderType": "OR",
"SalesOrganization": "1710",
"DistributionChannel": "10",
"OrganizationDivision": "00",
"SoldToParty": "1000180",
"PurchaseOrderByCustomer": "CAP Application-Mujeeb",
"CustomerPaymentTerms": "",
"to_Partner": [
{
"PartnerFunction": "SP",
"Customer": "1000187"
}
],
"to_Item": [
{
"Material": "LXF001",
"RequestedQuantity": "10"
}
]
}
}
Sales Order from S/4 Public cloud
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
21 | |
16 | |
10 | |
9 | |
8 | |
7 | |
7 | |
5 | |
5 | |
5 |