change_cds_view
Modify an existing CDS view in SAP systems. Locks the object, replaces the DDL source, activates, and releases the lock. Requires the view name and full new source code.
Instructions
Modify an existing CDS view (DDL source) in the SAP system. Locks the object, writes the new source, activates, and unlocks. Use get_cds_view first to read the current source.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | CDS view name (e.g. ZHANZ_MY_VIEW) | |
| source | Yes | Complete new CDS DDL source code including all annotations and define view statement | |
| system_id | No | SAP system ID (e.g. DEV). Omit to use default system. |
Implementation Reference
- src/adt-client.ts:1239-1314 (handler)The `changeCdsView` method in `AdtClient` class implements the core logic to modify an existing CDS view. It: 1) Fetches a stateful CSRF token, 2) Locks the DDL source object, 3) Writes the new source code, 4) Unlocks the object, 5) Activates the CDS view via activation API.
async changeCdsView(name: string, source: string): Promise<string> { await this.fetchStatefulCsrf(); const log: string[] = []; const nameLower = name.toLowerCase(); const nameUpper = name.toUpperCase(); try { // 1. Lock const lockResp = await this.http.post( `/sap/bc/adt/ddic/ddl/sources/${nameLower}?_action=LOCK&accessMode=MODIFY`, "", { headers: this.statefulHeaders({ Accept: "application/vnd.sap.as+xml" }), responseType: "text", validateStatus: () => true } ); const lockData = lockResp.data as string; const lockMatch = lockData.match(/<LOCK_HANDLE>([^<]+)<\/LOCK_HANDLE>/); if (!lockMatch?.[1]) { log.push(`Failed to lock DDL source ${nameUpper} (HTTP ${lockResp.status})`); log.push(lockData.substring(0, 500)); return log.join("\n"); } const lockHandle = lockMatch[1]; log.push(`Locked ${nameUpper} for editing`); // 2. Write source await this.http.put( `/sap/bc/adt/ddic/ddl/sources/${nameLower}/source/main?lockHandle=${encodeURIComponent(lockHandle)}`, source, { headers: this.statefulHeaders({ "Content-Type": "text/plain; charset=utf-8" }), responseType: "text", } ); log.push("Source code written"); // 3. Unlock (must unlock before activation) await this.http.post( `/sap/bc/adt/ddic/ddl/sources/${nameLower}?_action=UNLOCK&lockHandle=${encodeURIComponent(lockHandle)}`, "", { headers: this.statefulHeaders({ Accept: "application/vnd.sap.as+xml" }), responseType: "text" } ); log.push("Unlocked"); // 4. Activate const activateBody = `<?xml version="1.0" encoding="UTF-8"?> <adtcore:objectReferences xmlns:adtcore="http://www.sap.com/adt/core"> <adtcore:objectReference adtcore:uri="/sap/bc/adt/ddic/ddl/sources/${nameLower}" adtcore:name="${nameUpper}"/> </adtcore:objectReferences>`; const actResp = await this.http.post( "/sap/bc/adt/activation?method=activate&preauditRequested=true", activateBody, { headers: this.statefulHeaders({ "Content-Type": "application/xml", Accept: "application/xml", }), responseType: "text", validateStatus: () => true, } ); const actData = actResp.data as string; if (actData.includes('activationExecuted="true"')) { log.push("Activated successfully"); } else { const msgMatch = actData.match(/<msg:shortText>([\s\S]*?)<\/msg:shortText>/); log.push(`Activation: ${msgMatch?.[1] ?? `HTTP ${actResp.status}`}`); } } finally { await this.endStatefulSession(); } return log.join("\n"); } - src/mcp-server.ts:1297-1301 (registration)The `change_cds_view` tool handler in the MCP server's CallToolRequestSchema handler. Parses input via ChangeCdsViewSchema, calls `client.changeCdsView()`, and returns the log.
case "change_cds_view": { const { name: cdsName, source } = ChangeCdsViewSchema.parse(args); const log = await client.changeCdsView(cdsName, source); return { content: [{ type: "text", text: log }] }; } - src/mcp-server.ts:35-38 (schema)Zod schema `ChangeCdsViewSchema` defining input validation for the change_cds_view tool: requires `name` (string) and `source` (string).
const ChangeCdsViewSchema = z.object({ name: z.string(), source: z.string(), }); - src/mcp-server.ts:273-285 (registration)Tool registration in the ListToolsRequestSchema handler: defines 'change_cds_view' with name, description, and input schema listing properties (name, source, system_id).
{ name: "change_cds_view", description: "Modify an existing CDS view (DDL source) in the SAP system. Locks the object, writes the new source, activates, and unlocks. Use get_cds_view first to read the current source.", inputSchema: { type: "object" as const, properties: { name: { type: "string", description: "CDS view name (e.g. ZHANZ_MY_VIEW)" }, source: { type: "string", description: "Complete new CDS DDL source code including all annotations and define view statement" }, ...SYSTEM_ID_PROP, }, required: ["name", "source"], }, },