GitHub Copilot custom instructions for ABAP

By ABAP for Agents · Updated

TL;DR

  • Put short, always-relevant ABAP rules in .github/copilot-instructions.md: target release, no invented SAP objects, a self-check list.
  • Put topic rules in .github/instructions/NAME.instructions.md with applyTo: "**/*.abap" so they only apply to ABAP files.
  • On github.com, path-specific instructions are currently used by Copilot cloud agent and Copilot code review. Repository-wide instructions apply more broadly.
  • Use a prompt file in .github/prompts/ for repeatable tasks like a clean-core review in VS Code chat.
  • Check the references list of a Copilot Chat answer to confirm copilot-instructions.md was used.

Out of the box, GitHub Copilot knows ABAP syntax reasonably well, but not your release, your namespace or which SAP objects exist in your system. Repository custom instructions fix that for everyone who works in the repository, which in ABAP usually means an abapGit repository.

The three kinds of instruction files

According to GitHub's documentation, Copilot supports three kinds of repository instructions:

FileApplies to
.github/copilot-instructions.mdAll requests made in the context of the repository
.github/instructions/NAME.instructions.mdRequests involving files that match the applyTo pattern
AGENTS.md (anywhere in the repo)Agents; the nearest one in the directory tree takes precedence

When a path-specific file matches and a repository-wide file also exists, Copilot uses both. That makes a clean split for ABAP: a short core in copilot-instructions.md, details in path-specific files.

A layout that works for ABAP

This is the layout of our free lite rules for Copilot:

.github/
  copilot-instructions.md                  core + self-check
  instructions/
    10-release-syntax.instructions.md      applyTo: "**/*.abap"
    20-abap-sql.instructions.md            applyTo: "**/*.abap"
    60-obsolete.instructions.md            applyTo: "**/*.abap"
  prompts/
    abap-clean-core-review.prompt.md

Repository-wide instructions

copilot-instructions.md is plain Markdown with no frontmatter. Because it's included broadly, keep it to the rules that matter on every ABAP request:

# ABAP instructions

## Establish the target before writing code
- Language version: ABAP for Cloud Development or Standard ABAP.
- Product: S/4HANA or ECC. Release: SAP_BASIS, e.g. 7.50 or 7.58.
- If unknown, assume the lowest plausible release.
- Never mix syntax from different releases in one answer.

## Never invent SAP objects
- No invented function modules, BAPIs, classes, CDS views or tables.
- Name every SAP object you rely on so it can be checked.

## Self-check before answering
- Table expressions don't set sy-subrc: use line_exists( ) or OPTIONAL.
- BAPIs report errors in RETURN. No COMMIT WORK inside RAP.
- No !=, ++ or "text" string literals.

Add one line with your actual system ("S/4HANA 2023, Standard ABAP") and most wrong-release answers disappear.

Path-specific instructions with applyTo

Each path-specific file starts with a frontmatter block containing applyTo, a glob pattern. Several patterns can be separated by commas.

---
applyTo: "**/*.abap"
---
# ABAP SQL
- Escape every host variable with @ and separate lists with commas.
  Strict mode is all-or-nothing within one statement.
- FOR ALL ENTRIES with an empty driver table ignores the whole WHERE
  clause and reads all rows. Always guard: IF itab IS NOT INITIAL.
- FOR ALL ENTRIES removes duplicate rows: select all key fields.
- SELECT SINGLE is for a full primary key.

If you keep CDS sources or behavior definitions in the repository, add their file extensions to applyTo. abapGit and the ABAP file format use different extensions, so check what's actually in your repository.

Where it works: GitHub's documentation currently says that on github.com, path-specific instructions are only supported by Copilot cloud agent and Copilot code review. In VS Code, Copilot Chat applies them when files matching the pattern are part of the request. If you want Copilot code review or the cloud agent to skip a file, the frontmatter accepts excludeAgent: "code-review" or excludeAgent: "cloud-agent".

Prompt files for repeatable tasks

Some instructions are tasks rather than rules. A code review against Clean ABAP and the clean core levels A to D is a good example. Put it in a prompt file and run it on demand in VS Code chat by typing / and the prompt's name:

---
description: Review ABAP code for Clean ABAP, ABAP Cloud readiness and
  clean core level (A-D) and return a prioritized findings list.
---
# Task: Clean ABAP + clean core review
Return a table: # | Severity | Line/object | Finding | Why | Fix.
1. Correctness: unguarded FOR ALL ENTRIES, SELECT SINGLE without the
   full key, missing sy-subrc checks after SELECT, COMMIT WORK in RAP.
2. Clean core level of each SAP object. Mark unknown ones "verify".

Code review on pull requests

Copilot code review reads the repository instructions too, which is where ABAP rules pay off for teams using abapGit with pull requests. GitHub notes that when reviewing a pull request, Copilot reads the instructions from the head branch, so you can test a change to the instructions in the same pull request. Custom instructions for code review are enabled by default and can be switched off in the repository's Copilot settings.

A short review rule that catches real bugs:

When reviewing ABAP, flag as blocking:
- FOR ALL ENTRIES without an IF itab IS NOT INITIAL guard
- SELECT inside LOOP
- sy-subrc checked after a table expression
- COMMIT WORK in RAP behavior handlers or savers

Check that the instructions are used

In Copilot Chat, expand the list of references at the top of an answer. If .github/copilot-instructions.md is listed, the repository instructions were used. Then try a release-specific prompt:

Write ABAP for SAP_BASIS 7.40 SP05 that reads VBAK for a list
of sales order numbers in an internal table.

A good answer states the release, declares the target table (inline INTO TABLE @DATA(...) needs 7.40 SP08) and guards the FOR ALL ENTRIES.

AGENTS.md as the shared option

If your team also uses Cursor, Claude Code or Codex, consider keeping the core rules in AGENTS.md, which Copilot reads as well. Avoid putting the same text in both AGENTS.md and copilot-instructions.md, so you don't maintain two copies that drift apart. See Claude Code and AGENTS.md for ABAP for that setup, and ABAP mistakes AI coding assistants make for the full list of patterns worth covering.

Instructions guide Copilot; they don't enforce anything. Keep ATC and ABAP Unit as the gate.

Get the rules

Start with the free rules: ABAP for Agents Lite (MIT) has the core rules from this guide, ready for Cursor, Claude Code, GitHub Copilot, Windsurf and AGENTS.md, in English and Portuguese.

Need more? The full Rules Pack (v1.1) has 300+ rules across 20 topics (adding performance, security, RAP, CDS, OData and Fiori, ABAP Cloud and clean core, LUW and locks, BAPIs, ABAP Unit and S/4HANA migration) plus 8 agent skills, with free updates. It is 19 € at launch (29 € after).

Get notified about updates

New rules when SAP or the AI tools change: about one short email a month. No spam.

We'll send you a confirmation email first (double opt-in); you're only subscribed after you click the link. Unsubscribe anytime with one click. Emails are sent via Kit.