Skip to main content
Glama
ethanhan2014

SAP ADT MCP Server

by ethanhan2014

create_abap_program

Create a new ABAP program in an SAP system by providing a name, source code, and description. The program is automatically activated and can be stored in a specified package or local objects ($TMP). Optionally, target a specific system ID.

Instructions

Create a new ABAP program/report in the SAP system. Creates the program, writes source code, and activates it. By default creates in $TMP (local objects, no transport required).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesProgram name (must start with Z or Y, e.g. ZHANZ_TEST)
descriptionYesShort description of the program (max 70 chars)
sourceYesABAP source code. Must start with REPORT statement.
packageNoDevelopment package (default: $TMP for local objects)
system_idNoSAP system ID (e.g. DEV). Omit to use default system.

Implementation Reference

  • The `createAbapProgram` method on the AdtClient class — the actual handler that creates an ABAP program via SAP ADT REST API. It: 1) creates the program shell via POST, 2) locks the object, 3) writes source code via PUT, 4) unlocks, 5) activates the program.
      async createAbapProgram(name: string, description: string, source: string, pkg = "$TMP"): Promise<string> {
        await this.fetchStatefulCsrf();
        const log: string[] = [];
    
        try {
          // 1. Create program shell
          const xml = `<?xml version="1.0" encoding="UTF-8"?>
    <program:abapProgram xmlns:program="http://www.sap.com/adt/programs/programs"
      xmlns:adtcore="http://www.sap.com/adt/core"
      adtcore:type="PROG/P" adtcore:description="${this.escapeXml(description)}"
      adtcore:language="EN" adtcore:name="${name.toUpperCase()}"
      adtcore:masterLanguage="EN" adtcore:responsible="${this.config.username.toUpperCase()}">
      <adtcore:packageRef adtcore:name="${pkg}"/>
    </program:abapProgram>`;
    
          await this.http.post("/sap/bc/adt/programs/programs", xml, {
            headers: this.statefulHeaders({
              "Content-Type": "application/vnd.sap.adt.programs.programs+xml; charset=utf-8",
              Accept: "application/vnd.sap.adt.programs.programs+xml",
            }),
          });
          log.push(`Created program ${name.toUpperCase()} in package ${pkg}`);
    
          // 2. Lock
          const lockResp = await this.http.post(
            `/sap/bc/adt/programs/programs/${name.toLowerCase()}?_action=LOCK&accessMode=MODIFY`,
            "",
            { headers: this.statefulHeaders(), responseType: "text" }
          );
          const lockMatch = (lockResp.data as string).match(/<LOCK_HANDLE>([^<]+)<\/LOCK_HANDLE>/);
          const lockHandle = lockMatch?.[1];
          if (!lockHandle) throw new Error("Failed to obtain lock handle");
          log.push("Locked for editing");
    
          // 3. Write source
          await this.http.put(
            `/sap/bc/adt/programs/programs/${name.toLowerCase()}/source/main?lockHandle=${encodeURIComponent(lockHandle)}`,
            source,
            {
              headers: this.statefulHeaders({ "Content-Type": "text/plain; charset=utf-8" }),
              responseType: "text",
            }
          );
          log.push("Source code written");
    
          // 4. Unlock
          await this.http.post(
            `/sap/bc/adt/programs/programs/${name.toLowerCase()}?_action=UNLOCK&lockHandle=${encodeURIComponent(lockHandle)}`,
            "",
            { headers: this.statefulHeaders(), responseType: "text" }
          );
          log.push("Unlocked");
    
          // 5. 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/programs/programs/${name.toLowerCase()}" adtcore:name="${name.toUpperCase()}"/>
    </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 if (actData.includes("<msg:shortText>")) {
            const msgMatch = actData.match(/<msg:shortText>([\s\S]*?)<\/msg:shortText>/);
            log.push(`Activation warning: ${msgMatch?.[1] ?? "check messages"}`);
          } else {
            log.push(`Activation response: ${actResp.status}`);
          }
        } finally {
          await this.endStatefulSession();
        }
    
        return log.join("\n");
      }
  • The `create_abap_program` case in the CallToolRequestSchema handler. Parses input with CreateProgramSchema, then calls `client.createAbapProgram(progName, description, source, pkg ?? "$TMP")`.
    case "create_abap_program": {
      const { name: progName, description, source, package: pkg } = CreateProgramSchema.parse(args);
      const log = await client.createAbapProgram(progName, description, source, pkg ?? "$TMP");
      return { content: [{ type: "text", text: log }] };
    }
  • The `CreateProgramSchema` Zod schema defining the input validation for create_abap_program: name (string), description (string), source (string), and optional package (string).
    const CreateProgramSchema = z.object({
      name: z.string(),
      description: z.string(),
      source: z.string(),
      package: z.string().optional(),
    });
  • Tool registration entry in the ListToolsRequestSchema handler. Declares the tool name 'create_abap_program', its description, and input schema with properties: name, description, source, package, and system_id.
    {
      name: "create_abap_program",
      description: "Create a new ABAP program/report in the SAP system. Creates the program, writes source code, and activates it. By default creates in $TMP (local objects, no transport required).",
      inputSchema: {
        type: "object" as const,
        properties: {
          name: { type: "string", description: "Program name (must start with Z or Y, e.g. ZHANZ_TEST)" },
          description: { type: "string", description: "Short description of the program (max 70 chars)" },
          source: { type: "string", description: "ABAP source code. Must start with REPORT statement." },
          package: { type: "string", description: "Development package (default: $TMP for local objects)" },
          ...SYSTEM_ID_PROP,
        },
        required: ["name", "description", "source"],
      },
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses creation, source writing, and activation. No annotations provided, so description carries full burden. Lacks details on permissions, overwriting behavior, or error conditions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences with no fluff. Front-loaded with main action: 'Create a new ABAP program/report in the SAP system.'

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema or annotations. Description adequately explains creation but does not mention return values, error handling, or post-creation state. Could include activation confirmation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema covers all 5 parameters with descriptions (100% coverage). Description adds the key constraint that source must start with REPORT statement, which is not in schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it creates a new ABAP program/report, writes source code, and activates it. It distinguishes from siblings like change_abap_program and create_abap_class by specifying creation behavior.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Mentions default package $TMP for local objects without transport, implying use for local testing. Does not explicitly exclude scenarios or compare to alternatives like change_abap_program.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ethanhan2014/sap-adt-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server