GetLocalMacros
Retrieve local macros source code from an ABAP class, supporting active or inactive version reading.
Instructions
Retrieve local macros source code from a class (macros include). Supports reading active or inactive version. Note: Macros are supported in older ABAP versions but not in newer ones.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| class_name | Yes | Parent class name (e.g., ZCL_MY_CLASS). | |
| version | No | Version to read: "active" (default) for deployed version, "inactive" for modified but not activated version. | active |
Implementation Reference
- The main handler function that executes the GetLocalMacros tool logic. Creates an ADT client, reads local macros source code for a given class name and version, and returns the result.
export async function handleGetLocalMacros( context: HandlerContext, args: GetLocalMacrosArgs, ) { const { connection, logger } = context; try { const { class_name, version = 'active' } = args as GetLocalMacrosArgs; if (!class_name) { return return_error(new Error('class_name is required')); } const client = createAdtClient(connection, logger); const className = class_name.toUpperCase(); logger?.info(`Reading local macros for ${className}, version: ${version}`); try { const localMacros = client.getLocalMacros(); const readResult = await localMacros.read( { className }, version as 'active' | 'inactive', ); if (!readResult || !readResult.readResult) { throw new Error(`Local macros for ${className} not found`); } const sourceCode = typeof readResult.readResult.data === 'string' ? readResult.readResult.data : JSON.stringify(readResult.readResult.data); logger?.info(`✅ GetLocalMacros completed successfully: ${className}`); return return_response({ data: JSON.stringify( { success: true, class_name: className, version, macros_code: sourceCode, status: readResult.readResult.status, }, null, 2, ), } as AxiosResponse); } catch (error: any) { logger?.error( `Error reading local macros for ${className}: ${error?.message || error}`, ); let errorMessage = `Failed to read local macros: ${error.message || String(error)}`; if (error.response?.status === 404) { errorMessage = `Local macros for ${className} not found.`; } else if (error.response?.status === 423) { errorMessage = `Class ${className} is locked by another user.`; } return return_error(new Error(errorMessage)); } } catch (error: any) { return return_error(error); } } - TOOL_DEFINITION constant defining the tool name, availability, description, and inputSchema with required class_name and optional version parameter.
export const TOOL_DEFINITION = { name: 'GetLocalMacros', available_in: ['onprem', 'cloud', 'legacy'] as const, description: 'Retrieve local macros source code from a class (macros include). Supports reading active or inactive version. Note: Macros are supported in older ABAP versions but not in newer ones.', inputSchema: { type: 'object', properties: { class_name: { type: 'string', description: 'Parent class name (e.g., ZCL_MY_CLASS).', }, version: { type: 'string', enum: ['active', 'inactive'], description: 'Version to read: "active" (default) for deployed version, "inactive" for modified but not activated version.', default: 'active', }, }, required: ['class_name'], }, } as const; - src/lib/handlers/groups/HighLevelHandlersGroup.ts:865-868 (registration)Registration of the GetLocalMacros tool in the HighLevelHandlersGroup, mapping the tool definition to its handler with context.
{ toolDefinition: GetLocalMacros_Tool, handler: withContext(handleGetLocalMacros), }, - src/handlers/compact/high/compactRouter.ts:185-188 (registration)Registration in the compact router, mapping 'LOCAL_MACROS' -> 'get' to the handleGetLocalMacros handler.
LOCAL_MACROS: { get: handleGetLocalMacros as unknown as CompactHandler, update: handleUpdateLocalMacros as unknown as CompactHandler, delete: handleDeleteLocalMacros as unknown as CompactHandler, - Import of the tool definition and handler from the implementation file into the HighLevelHandlersGroup.
import { TOOL_DEFINITION as GetLocalMacros_Tool, handleGetLocalMacros, } from '../../../handlers/class/high/handleGetLocalMacros';