Skip to Content
1
Sep 30, 2020 at 04:11 PM

CAP: Modelling Arrayed Types

723 Views

Hi experts,

As suggested in a CAP's documentation, in order to Avoid Overly Normalized Models, I have created RemoteSystems entity with an “array of” called headerParameters.

entity RemoteSystems : Core.UserHist {
                key ID: Core.SystemID not null;
                remoteConnections: association to many RemoteConnections on remoteConnections.remoteSystem=$self;
                description: String(100);
                techInfo : Core.RemoteSystemInfoTs;
                timeout: Integer64 not null;
                headerParameters: array of {
                               name: String(50);
                               value: String(50);
                }
};

When deployed to SQL databases, “array of” fields are mapped to LargeString columns. (Arrayed-types)

LargeString has SQL data Type NCLOB. (Predefined-types).

In cns.json file, this field is converted in this way:

        "headerParameters": {
          "items": {
            "elements": {
              "name": {
                "type":"cds.String",
                "length": 50
              },
              "value": {
                "type": "cds.String",
                "length": 50
              }
            }
          }
        }

CAP’s documentation say:

Generic support in runtimes is added over time. It’s available in Node.js but not yet in Java. If not available, you need to add custom logic, for example, to serialize payloads into JSON strings and vice versa.

I’m working in node.js so it should work out-of-the box.

I’m trying to insert a record or via csv file or via rest client but I have problem with this field.

{
    "ID": "XXX_ERP",
    "description": "XXX erp SAP ",
    "techInfo_protocol": "https",
    "techInfo_sid": "XXX",
    "timeout": 2000,
    "headerParameters":  [{"name": "testName","value": "testValue"}]
}

Response with error is:

Console log shows this problem:

9/30/20 10:26:18.961 AM [APP/1-0] ERR   [2020-09-30T08:26:18.960Z | ERROR |
1095132]: Error stacktrace: Error: invalid column name: HEADERPARAMETERS_0_NAME     at Request.reject
(/hana/shared/yyy/xs/app_working/xxxxxxxxxx/executionroot/da47924a-ef8f-4f74-9f15-d9f79bbbe60b/app/node_modules/@sap/cds/lib/srv/Request.js:58:39)

Debugging code, problem seems to be in query convertion.

CAP translates properties “name” and “value” in fields:

How can I fix this problems or any suggestions?

Best

Alice

Attachments

ooyka.png (2.9 kB)
fk7lt.png (6.6 kB)