sap-consultant — SAP 只读查询工具(业务顾问版)
Python CLI wrapping the SAP ADT REST API — 只读查询版。面向 SAP 业务顾问:
查开发对象、读源码、查表结构和数据。本工具没有也不允许有任何写入 SAP 的能力
(无 create/sync/upload/delete/activate/format/transport-release/run-program)。
调用方式
cd <SKILL_DIR>/assets && python main.py <command> [options]
全局参数(置于命令之前):
| 参数 | 说明 |
|---|---|
--profile <name> |
使用指定配置 profile |
--verify-ssl |
启用 SSL 验证(默认关闭) |
安装与配置见 references/install.md。
Command Reference(11 个只读查询命令 + auth 密钥管理)
| Category | Command | Key Parameters | 说明 |
|---|---|---|---|
| Object | info |
--name --type |
对象元数据:状态/负责人/开发包/传输请求号 |
| Object | download |
--name --type --path |
源码导出到本地(只读导出,不回写) |
| Object | history |
--name --type |
对象版本历史 |
| Browse | list |
[--type --package --prefix] |
列出对象(按类型/包/前缀过滤) |
| Browse | whereused |
--name --type |
Where-Used 引用追踪 |
| Browse | search |
--query [--type] |
源码/对象搜索 |
| Diff | diff |
--name --type [--path] |
本地文件 vs SAP 源码对比(只读) |
| Data | show-table |
--name |
表字段结构(SE11 等价,只读) |
| Data | read-table |
--name [--fields --where --max-rows] |
表数据查询(SE16N 等价,只读) |
| Diag | syntax-check |
--name --type |
语法检查(只读诊断,不上传不激活) |
| Config | config show / list-profiles / set |
— | 配置管理 |
| Auth | auth login / logout / status |
— | 密码存取系统 keyring(推荐,配置文件不落明文) |
示例:
# 业务顾问典型场景
python main.py info --name ZMM_MATERIAL_QUERY --type class # 这是什么对象、激活没、谁负责
python main.py download --name ZSD_ORDER_RPT --type report --path ./out # 导出源码给顾问看
python main.py list --package ZSD --prefix Z* # 这个包里有哪些对象
python main.py whereused --name ZIF_ORDER_API --type interface # 谁在引用这个接口
python main.py show-table --name VBAK # 销售订单表有哪些字段
python main.py read-table --name VBAK --fields "VBELN,ERDAT,NETWR" --where "ERDAT = '20260101'" --max-rows 50
python main.py read-table --name KNA1 --where "LAND1 IN ('CN','US')" --max-rows 100
支持的对象类型(16 种,同 sap-cli)
report class interface function functiongroup domain dataelement table structure tabletype include cdsview messageclass view searchhelp lockobject
⚠️ Constraints (HARD RULES — DO NOT VIOLATE)
- 只读铁律:本工具只有查询命令。任何"改一下/上传/创建/删除/激活"请求一律拒绝,
告知用户此类操作需走 sap-cli(开发工程线)或 SAP GUI,本工具设计上不提供。 - 不绕过工具:不得用 requests/curl 直调 ADT 端点;只通过
python main.py <cmd>。 - 标准对象只读:
CL_*/CX_*/IF_*/SAPL*等标准对象仅允许查询——本工具本就只有查询,天然合规。 - 表数据仅 SELECT:
read-table走 ADT Data Preview(只读通道),无 INSERT/UPDATE/DELETE 能力。 - 凭据不入库:连接配置在
assets/config.ini(已 gitignore),不得提交到任何仓库。 read-table方言坑:--where运算符两侧必须留空格(f = 'x'✅,f='x'❌ 400);
多值过滤用IN;--fields逗号分隔;列名必须真实存在(DD02T 语言列是DDLANGUAGE不是LANGUAGE)。
Error Handling (Quick Reference)
| Error Pattern | Action |
|---|---|
| HTTP 400 (read-table SQL) | 方言问题:WHERE 运算符两侧加空格 / 字段逗号分隔 / 列名拼错(工具会带 SAP 原文) |
| HTTP 404 (info/download) | 对象不存在——确认名称/类型;function 名称格式是 组名/模块名 |
| HTTP 406 (info DDIC) | NW 7.40 媒体类型限制,工具已自动回退 */*;仍失败则为系统限制 |
| Login failed | 核对 config.ini(host/client/user/password)或环境变量 SAP_HOST 等 |
General flow: diagnose(参数/名称/网络)→ usage error: 修正重试 → system limit: 报告用户走 SAP GUI。
与姊妹仓的关系
- 本仓
sap-consultant-skill(只读查询线,给业务顾问):查对象、查数据,无写入。 - 姊妹仓
sap-cli-skill(开发工程线,给开发者/AI 工程师):完整 CRUD + 传输管理 + 闭环开发。 - 两仓共享 ADT 端点知识;写入能力只存在于 sap-cli-skill。若业务查询中发现对象需要修改,
明确告知用户转开发线处理,本工具不代写。
Version
1.0.1(源出 sap-cli-skill 2.5.1 只读裁剪版)