SAP CPI call oData v2 service defined in SAP CAP project

I am developing a SAP CAP project, which includes an entity S4_DATA.

 

entity S4_DATA {
key ID : UUID;
EXIDV : String(20);
PARENT_DETAILS : Association to many S4_PARENTS
on PARENT_DETAILS.EXIDV = $self.EXIDV;
}

entity S4_PARENTS {
key LABELID : String(50);
key SERIALNO : Integer;
key ITEMNO : String(6);
EXIDV : String(20);
MATNR : String(40);
CHARG : String(10);
PARENT_LABELID : String(50);
PARENT_SERIALNO : Integer;
}

 

I expose it as OData service as per below:

 

using mynamespace from ‘../db/mynamespace’;
service CatalogService {
entity S4_DATA as projection on mynamespace.S4_DATA;
entity S4_PARENTS as projection on mynamespace.S4_PARENTS;
}

 

In s4_srv.js file, I have below codes to use OData v2 adapter:

 

cds.on(‘bootstrap’, app => app.use(odataV2()));

 

In same file, I also have an event handler for OData ‘CREATE’ operation on ‘S4_DATA’:

 

srv.before(‘CREATE’, ‘S4_DATA’, async (req) => {
process.stderr.write(`Request headers: ${JSON.stringify(req.headers)}n`);
process.stderr.write(`content-type: ${req.headers[‘content-type’]}n`);
if (req.data) {
process.stderr.write(`Request data: ${JSON.stringify(req.data, null, 2)}n`);
}
});

 

To locally simulate the call from SAP CPI, I use below test script:

 

### Mock SAP CPI Call Data01
POST http://localhost:4004/odata/v2/catalog/S4_DATA
Content-Type: application/xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<entry>
<content>
<properties>
<EXIDV>10000000000000800668</EXIDV>
<PARENT_DETAILS>
<ITEM>
<ITEMNO>000001</ITEMNO>
<EXIDV>10000000001000000948</EXIDV>
<MATNR>PGK-001</MATNR>
<CHARG>ABCD-44</CHARG>
</ITEM>
<ITEM>
<ITEMNO>000002</ITEMNO>
<EXIDV>10000000001000000949</EXIDV>
<MATNR>PGK-002</MATNR>
<CHARG>ABCD-55</CHARG>
</ITEM>
</PARENT_DETAILS>
</properties>
</content>
</entry>

 

The output from the test script are as follow:

 

[odata] – POST /odata/v4/catalog/S4_DATA
Request headers: {“connection”:”close”,”host”:”localhost:4004″,”content-length”:”371″,”accept-encoding”:”gzip, deflate”,”content-type”:”application/json;IEEE754Compatible=true”,”user-agent”:”vscode-restclient”,”x-cds-odata-version”:”v2″,”x-correlation-id”:”db52783b-5fc8-4a6e-9dc3-ac084d93269b”}
content-type: application/json;IEEE754Compatible=true
Request data: {
“EXIDV”: “10000000000000800668”,
“ID”: “06d14828-174b-4d07-be83-6defbe3a4a01”
}

 

From the output, I notice 2 things:
1. ‘content-type’ is “application/json” even though I set it as ‘application/xml’ in the test script.
2. The ‘PARENT_DETAILS’ is missing from ‘Request data’: “req.data”.

After some study I realize that the transformation (“xml” => “json”) is likely happening at the OData adapter level in SAP CAP.
I try to use below codes to intercepts all incoming requests before they reach the OData adapter, but after testing, I found that it is never triggered.

 

cds.on(‘bootstrap’, app => {
app.use((req, res, next) => {
process.stderr.write(‘Request receivedn’);
next();
});
app.use(odataV2());
});

 

Has anyone else experienced this issue in the past? Your feedback and suggestions would be highly valued.

Notes:
Below are some screen shot in SAP CPI, when CPI call OData service, it only allow xml as its payload instead of JSON.WayneSG_0-1721967631718.png

Scroll to Top