cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Consume a Parameterized Table from S4 as External service in CAPM

richadwivedi
Explorer
0 Kudos
333

Hi Everyone, 

I've one use case, where I have parameterised service in s4 and consuming that in SAP CAPM  project to read data, but not able to successfully read data getting below error

Error: Invalid call to "Service.Entityset". You need to navigate to Set
[remote] - Error: Error during request to remote service: Request failed with status code 500


S4 Url format(in which getting data)
https://..../S4ServiceName/EntitySetName(param1='abc')/Set

Service.cds file

 

EntitySetName(param1 :api.EntitySetName:param1) as
projection on api.EntitySetName{
key Set.val1,
key Set.val2,
Set.val3,
....
};

 

Server.js

 

srv.on('READ', ['EntitySetName'], async req => {
  const api = await cds.connect.to('S4_metadata');
        try {
            const params = req.query.SELECT.from.ref[0].args;
            const projection = req.target.projection.from.ref[0].substr(req.target.projection.from.ref[0].lastIndexOf(".") + 1);
            let modifiedFromClause = { ref: [{ id: projection, where: [] }, "Set"] };
            for (let param in params) {
                modifiedFromClause.ref[0].where.push({ ref: [param] }, "=", { val: params[param].val }, ",");
            }
            modifiedFromClause.ref[0].where.splice(-1);
            req.query.SELECT.from = modifiedFromClause;
        } catch (e) {
            console.log(e.message);
            throw new Error("PARAMETERIZED_REQUEST_PROCESSING_EXCEPTION");
        }
        return api.run(req.query);
    });

 

Please provide the correct way to consume these kind of services.

Accepted Solutions (0)

Answers (0)