Lesson 4 of 4 · AI for SAP Consultants: Specs, ABAP, Testing and Support
Understanding, Writing and Reviewing ABAP With AI
Use AI to explain legacy ABAP, draft new code in modern syntax, review for performance and quality, and write ABAP Unit tests, while checking every object against the system.
ABAP developers spend a lot of time reading other people's code: old reports, user exits, enhancements and function modules written over many years. AI is very good at explaining code and suggesting improvements. It is less reliable at knowing which objects exist in your system and release. This lesson shows how to use it well.
Explaining legacy code
Paste the code (without client names, hard-coded passwords or real data) and ask for an explanation from the inside out:
Explain this ABAP code step by step for an ABAP developer new to this
system. Then summarise in 3 lines what it does, list database tables it
reads or changes, and point out anything that looks risky (performance,
missing error handling, hard-coded values).
"""
[paste code]
"""
For very old code, also ask: "Which statements here are obsolete in modern ABAP, and what would the modern equivalent be?"
Drafting new code
Give the AI the context it cannot guess: release, style rules and the real objects involved.
S/4HANA, ABAP 7.5x syntax. Write a method that reads open purchase order
items for a given vendor and plant and returns them as a table.
Use these objects (confirmed in our system): [list table/CDS view and
fields]. Requirements: inline declarations, new Open SQL syntax with host
variables (@), no SELECT inside loops, proper exception handling with a
custom exception class ZCX_... Add comments only where logic is not
obvious.
Important: the AI may invent function modules, BAPIs, classes or fields. Check every object it uses in the system (for example SE11, SE37, SE24 or the ABAP Development Tools in Eclipse) before you rely on it. If you did not give it the object names, assume they need checking.
Reviewing code for quality and performance
Review this ABAP code as a senior ABAP developer. List issues in order of
severity: performance (e.g. SELECT in loops, missing WHERE conditions,
SELECT *), correctness, error handling, security (e.g. dynamic SQL built
from user input, missing authority checks) and readability. Give the line
and a suggested fix for each.
"""
[paste code]
"""
Use the AI review in addition to the standard tools: the ABAP Test Cockpit (ATC) and Code Inspector checks your organisation uses. They know your system's rules; the AI does not.
Writing ABAP Unit tests
Tests are often skipped under deadline pressure. AI can draft them quickly:
Write ABAP Unit tests for this class method. Cover the normal case, an
empty input, and an invalid vendor. Use test doubles for database access
where appropriate, following the pattern used in this example from our
project: [paste an existing test class if you have one].
Run the tests and make sure they can fail: change the logic slightly and confirm a test breaks.
CDS views and SQL
AI can help design and explain CDS views and Open SQL, as long as you give it the real data model:
Explain this CDS view in plain language: what data it returns, the joins
and associations, and any performance concerns. [paste CDS source]
Always test queries on realistic data volumes in a development or quality system before transport.
Rules for code on client projects
- Follow the client's policy on using external AI tools with their code. Some forbid it; some provide approved tools.
- Never paste code containing credentials, client-identifying data or sensitive business logic into tools that are not approved.
- AI-generated code goes through the same review, ATC checks, testing and transport process as any other code.
Practice task
Take one legacy program or method you support. Get a step-by-step explanation and a quality review from AI, verify each finding in the system, and draft ABAP Unit tests for one method. Fix one real issue the review found, through your normal process.
Key takeaways
- AI is excellent at explaining legacy ABAP and suggesting modern equivalents.
- Give the release, style rules and real object names when asking for new code.
- Verify every function module, BAPI, class and field in the system.
- Combine AI review with ATC and Code Inspector, and test before transport.
Finished this lesson?Mark it complete to track your progress on this device.