Qwen4 for ABAP: local AI models in a field test with opencode, MCP and Clean ABAP rules
Can local AI models like Qwen4 write ABAP? Our field test with opencode, MCP and Clean ABAP rules on a real SAP system: setup, results and conclusions.
In short: Local AI models such as Qwen4 can work directly with an SAP system through an MCP server, and they pick up coding guidelines surprisingly well. For developing ABAP on their own in the SAP Product Compliance space, however, the two models we tested were not good enough. They invent tables and fields, and when the system contradicts them, they distrust the tool instead of their own assumption.
Why we tried local AI models
For ABAP development on our SAP S/4HANA 2025 test system we work with Claude Code and our own MCP server. MCP stands for Model Context Protocol, an open standard that lets an AI agent call tools. Through our server the AI reads source code, DDIC structures, Customizing and documentation, checks code with the syntax check and the ATC (ABAP Test Cockpit), and writes objects to the system once approved. How this worked during a release upgrade is described in our field report on the S/4HANA 2025 upgrade with AI.
The obvious question: how far can you get with a model that runs entirely in-house, without code or data ever leaving the network?
Briefly explained: tokens, context window and more
A few terms come up again and again below:
- Token: the unit in which a language model reads and writes text. A token is part of a word, a short word or a punctuation mark. A rule of thumb for English text: one token is about three quarters of a word, or three to four characters. German text tends to need more tokens, because German words are longer on average and compounds such as “Spezifikationsdatenbank” (specification database) split into several tokens. Source code also needs more tokens because of special characters and identifiers. That is why “tokens per second” is the usual measure of a model’s speed.
- Context window (context size): how much text the model can see at once, measured in tokens. Everything counts: the task, the rules, the conversation so far and every tool result, such as a source file it has read. “128k” stands for around 128,000 tokens. Once the window is full, the agent summarises older parts, and details get lost.
- Reasoning: Many models “think” in intermediate steps before answering. These thoughts are made of tokens too and take time. Levels such as
highorlowcontrol how extensively the model reasons. - Parameters: the learned weights of a model, a rough measure of its size. A model name suffix such as “35B-A3B” means 35 billion parameters in total, of which only around 3 billion are active per token. That makes the model fast.
- Quantisation: labels such as Q8_0 or Q4_K_M describe how strongly the weights are compressed, here to about 8 or 4 bits per value. This saves memory at the cost of some accuracy.
Background: local AI models and Qwen4
Local AI models are language models whose weights can be downloaded freely (open weights). They run on your own hardware, for example with llama.cpp, LM Studio, Ollama or MLX. The advantages: code and data stay in-house, there is no cost per request, and you are not tied to a single provider. The drawbacks: you need powerful hardware and some setup effort, and the models are usually smaller than the large cloud models.
Qwen4 is the new model family from Alibaba’s Qwen team. Qwen4-35B-A3B, released on 4 December 2026, is the first openly available model in the series, under the Apache 2.0 licence, which also permits commercial use. It is a so-called mixture-of-experts model: of its 35 billion parameters, only around 3 billion are active per token. According to the vendor it handles text, images and video and has a context window of more than one million tokens. Alibaba says it roughly keeps pace with the much larger Qwen3.8-Flash-Next. Independent tests were not yet available at release. In our test, exactly these two models go head to head.
The setup
- SAP system: SAP S/4HANA 2025 (FPS02) with Product Compliance, our own test system
- Hardware for the models: Mac Studio with M3 Ultra and 256 GB of memory
- Models:
- Qwen4-35B-A3B (Q8_0) on a llama.cpp server
- Qwen3.8-Flash-Next (Q4_K_M, around 112 GB) on LM Studio
- Gateway: Open WebUI as a shared, OpenAI-compatible interface
- Agent: opencode as the coding agent in the terminal
- Tools via MCP:
- our S/4 MCP server with source code, DDIC, syntax check, ATC, where-used list and Customizing
- Atlassian’s MCP server for Confluence
- Rules: our Clean ABAP guideline as
AGENTS.md. That covers all MUST rules, such as “no SELECT inside a LOOP”, “reports only call a controller class” and “test run as a separate method instead of a flag”, plus project rules like package assignment.
Pitfalls during setup
A few findings that should save others some time:
- The context limit sits in more than one place. According to the vendor, the model handles well over 128k tokens. It was still limited, twice: in the llama-server start parameter (
-c 131072) and in opencode’s model definition. Both values have to match, otherwise opencode compacts too early or the request fails. We went up to 512k. - launchd does not reload changed services. A
kickstartrestarts the service with the old configuration held in memory. Onlybootoutfollowed bybootstrappicks up the change. - Don’t set tokens only in the shell. opencode updated itself during the test and restarted its background service. The token for the MCP server only lived in a manually exported environment variable, and suddenly the server was “unreachable”. A file with permissions 600 that opencode reads via
{file:…}is more robust. - Every model has its own reasoning levels. Qwen4 knows
xhigh,high,lowandoff, but nomedium. Flash-Next knowsxhigh,mediumandlow, and without a setting it thinks at the highest level. This is in the model’s chat template, not in the agent’s documentation. - A thinking budget caps outliers. With
--reasoning-budget 4096, Qwen4 thinks for at most 4,096 tokens per step. Without that cap, some steps spent almost 12,000 tokens on pure reasoning.
The test: an ABAP report with built-in traps
The task was deliberately ordinary and contained several traps:
Write an ABAP report that reads the assigned specifications for a list of material numbers from the classic product database (Product Compliance Classic, formerly EH&S) and displays them as an ALV. There should be a “test run” checkbox. Name the package it belongs in.
Based on the guideline we expected: the correct package, a controller class instead of logic in the report, simulate( ) and run( ) instead of a test-run flag, explicit field lists instead of SELECT *, exceptions and message classes instead of literals, English code with a short comment per method, unit tests for the business logic, and finally code that passes the syntax check without errors.
Results of the local models
| Run | Generation speed | Time per step | Result |
|---|---|---|---|
Qwen4-35B, reasoning high | approx. 49 tokens/s | up to more than 4 minutes | complete code, good structure, several syntax errors |
Qwen4-35B, low + thinking budget | approx. 64 tokens/s | 2–17 seconds | gets lost in syntax probes, aborted |
Qwen3.8-Flash-Next, medium | approx. 40 tokens/s | first step over 9,000 tokens of reasoning | invents a table, aborted |
Qwen4 on high surprised us positively in terms of structure. The package was right. There was a controller class and a repository behind an interface, injected through the constructor. The model even built the test run as simulate( )/run( ) against the instructions and justified the deviation with the guideline. It explicitly put new objects such as the message class up for discussion. But the code would not have activated as it was. It accessed fields that do not exist in table MAKT, contained faulty declarations, and unit tests were missing. Its reason: “read-only, no business logic”, even though the repository contains the selection of the latest change state. And the summary claimed “data model verified in the system”, although part of it had never been checked.
Qwen4 on low was much faster but became unsure of itself. It looked for fields of the specification header in the assignment table. When the field list from the system did not contain them, it concluded: “The field list appears to be incomplete.” It then sent dozens of syntax probes to prove the opposite.
Flash-Next reasoned for more than 9,000 tokens before its first tool call. In the end it placed the link between material and specification in a table that does not exist in the system.
What we learned
How a model works matters more than what it knows. Every model gets field names wrong, large ones included. What matters is whether it checks its assumptions in the system, distinguishes “unverified” from “verified”, and trusts the source over its own memory when the two disagree. That is exactly where both local models failed.
Rules get through, verification steps don’t by themselves. The guideline in AGENTS.md visibly shaped the structure. The syntax check, on the other hand, was not used on the model’s own initiative in the first run, even though it was in the instructions.
Size isn’t everything, specialisation is. Qwen4-35B-A3B uses only around 3 billion active parameters per token. ABAP, and the Product Compliance data model in particular, probably appear rarely in training data. The larger Flash-Next did not make up for that.
Speed and thoroughness pull against each other. With less reasoning, Qwen4 became up to ten times faster per step but lost track of the data model.
Conclusion: what local AI models are good for in ABAP
For reading, explaining and looking things up, local models with an MCP server make sense: explaining code and where-used lists, summarising dumps and job logs, looking up Customizing. There the system supplies the facts and the model only has to put them in context. And everything stays in-house.
For writing ABAP we continue to rely on Claude Code with specialised agents for backend, frontend and testing. Not because the model is never wrong: Claude, too, occasionally reaches for a field name that does not exist. The difference lies in exactly what the local models lacked in the test:
- Look it up first, then write. In our day-to-day work the model looks up tables and fields in the system before they end up in the code. If the field list contradicts its assumption, it corrects the assumption rather than doubting the tool.
- Checking is part of the process. The syntax check is a fixed part of the working instructions: code is corrected until it is error-free, and only then handed over. ATC and unit tests come on top.
- Four eyes, even for AI. A dedicated review agent checks the MUST rules before anything reaches a human. Nothing is written to the system without approval.
The price: unlike with the local models, the code leaves the house. That is why we use this setup on our own S/4HANA test system, which holds no client data. There we try out new tools and approaches before we recommend them to our clients.
Outlook: fine-tuning Qwen4
Local models are evolving fast, and our test setup is in place. Next, we want to find out whether fine-tuning, that is, additional training on our own examples, can make Qwen4 better at ABAP. This is not only about more knowledge of ABAP and the Product Compliance data model. The way of working matters at least as much: look things up in the system first, then write, and trust the source when the two disagree. We will check whether it works with the same task and report on it here.
Has your AI already invented a table, with complete confidence? In a free 30-minute initial call, a senior consultant works out with you how AI can contribute to your ABAP development without anyone guessing the data model. What we take on for custom development is described on our SAP development service page.
Further reading
- Our SAP development service
- S/4HANA 2025 upgrade with AI: our field report
- Case studies from client projects
As of December 2026. Field test on our own test system; the figures come from the server logs of this session. The explanation of why the models struggle with ABAP is an assessment, not a measurement. Local models evolve quickly; the results apply to the versions named.