# Badi Enhancement

> Help with BAdI (Business Add-In) development and the ABAP enhancement framework including new BAdIs, fallback classes, filter-based BAdIs, enhancement spots, enhancement implementations, key user extensibility, classic BAdIs, and the new enhancement framework. Use when users ask about BAdI, BAdIs, Business Add-In, enhancement spot, enhancement implementation, enhancement framework, BAdI filter, B…

- **Type:** Skill
- **Install:** `agentstack add skill-likweitan-abap-skills-badi-enhancement`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [likweitan](https://agentstack.voostack.com/s/likweitan)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [likweitan](https://github.com/likweitan)
- **Source:** https://github.com/likweitan/abap-skills/tree/main/skills/badi-enhancement

## Install

```sh
agentstack add skill-likweitan-abap-skills-badi-enhancement
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# BAdI & Enhancement Framework

Guide for using BAdIs (Business Add-Ins) and the ABAP enhancement framework to extend SAP standard functionality.

## Workflow

1. **Determine the user's goal**:
   - Finding an existing BAdI to implement
   - Creating a custom BAdI definition
   - Implementing a BAdI
   - Understanding classic vs. new enhancement framework
   - Using key user extensibility
   - Extending standard code via enhancement spots

2. **Identify the framework**:
   - New BAdI framework (preferred, ABAP Cloud compatible)
   - Classic BAdI framework (legacy, `SE18`/`SE19`)
   - Enhancement spots and implementations
   - Key user extensibility (no-code)

3. **Guide implementation** following best practices

## BAdI Framework Overview

### New vs. Classic BAdIs

| Aspect               | New BAdI Framework              | Classic BAdI Framework |
| -------------------- | ------------------------------- | ---------------------- |
| **Transactions**     | ADT or `SE18`/`SE19`            | `SE18`/`SE19`          |
| **Enhancement Spot** | Required container              | Not applicable         |
| **Multiple Use**     | Always multiple-use             | Configurable           |
| **Filter**           | Filter types supported          | Filter values          |
| **Fallback Class**   | Supported                       | Not available          |
| **ABAP Cloud**       | Supported (released BAdIs only) | Not available          |
| **Recommendation**   | Use for all new development     | Maintain existing only |

## Creating a Custom BAdI

### Step 1: Create Enhancement Spot

```
ADT: New → Other ABAP Repository Object → Enhancements → Enhancement Spot
Name: Z_ENH_SPOT_TRAVEL
```

### Step 2: Define the BAdI Interface

```abap
INTERFACE zif_badi_travel_validate
  PUBLIC.
  METHODS validate
    IMPORTING
      is_travel       TYPE zstravel
    CHANGING
      ct_messages     TYPE bapiret2_t
    RAISING
      cx_badi_not_implemented.
ENDINTERFACE.
```

### Step 3: Define the BAdI in Enhancement Spot

In the enhancement spot, add a BAdI definition:

| Property           | Value                                 |
| ------------------ | ------------------------------------- |
| **BAdI Name**      | `ZBADI_TRAVEL_VALIDATE`               |
| **Interface**      | `ZIF_BADI_TRAVEL_VALIDATE`            |
| **Multiple Use**   | Yes (allows multiple implementations) |
| **Fallback Class** | `ZCL_BADI_TRAVEL_FALLBACK` (optional) |

### Step 4: Create Fallback Class (Optional)

```abap
CLASS zcl_badi_travel_fallback DEFINITION
  PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES zif_badi_travel_validate.
ENDCLASS.

CLASS zcl_badi_travel_fallback IMPLEMENTATION.
  METHOD zif_badi_travel_validate~validate.
    "Default behavior when no implementation is active
  ENDMETHOD.
ENDCLASS.
```

### Step 5: Call the BAdI in Your Code

```abap
"Get BAdI handle
DATA lo_badi TYPE REF TO zif_badi_travel_validate.

GET BADI lo_badi.

"Call BAdI — loops through all active implementations
CALL BADI lo_badi->validate
  EXPORTING is_travel   = ls_travel
  CHANGING  ct_messages = lt_messages.
```

### With Filters

```abap
"Define BAdI with filter
"In Enhancement Spot: add filter type COUNTRY (type LAND1)

"Get BAdI with filter
GET BADI lo_badi
  FILTERS country = ls_travel-country.

CALL BADI lo_badi->validate
  EXPORTING is_travel   = ls_travel
  CHANGING  ct_messages = lt_messages.
```

## Implementing an Existing BAdI

### Step 1: Find the BAdI

Methods to find a BAdI:

- **ADT search**: Search for BAdI name or enhancement spot
- **Transaction `SE18`**: Browse BAdI definitions
- **Breakpoint on `GET BADI`**: Set breakpoint at `CL_BADI_INTERNAL_FACTORY=>GET_BADI` to find BAdIs called during a process
- **Documentation**: Check SAP documentation or community for BAdI names

### Step 2: Create Enhancement Implementation

```
ADT: New → Other ABAP Repository Object → Enhancements → Enhancement Implementation
Name: Z_ENH_IMPL_TRAVEL_CHECK
Enhancement Spot: Z_ENH_SPOT_TRAVEL (or SAP's spot)
```

### Step 3: Create BAdI Implementation Class

```abap
CLASS zcl_badi_impl_travel_check DEFINITION
  PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES zif_badi_travel_validate.
ENDCLASS.

CLASS zcl_badi_impl_travel_check IMPLEMENTATION.
  METHOD zif_badi_travel_validate~validate.
    "Custom validation logic
    IF is_travel-begin_date get_system_date( ).
      APPEND VALUE #(
        type       = 'E'
        id         = 'Z_TRAVEL'
        number     = '001'
        message_v1 = 'Travel begin date must be in the future'
      ) TO ct_messages.
    ENDIF.
  ENDMETHOD.
ENDCLASS.
```

## BAdIs in ABAP Cloud / RAP

In ABAP for Cloud Development, BAdIs follow a specific pattern:

### Released BAdIs

- Only SAP-released BAdIs can be implemented
- Search for released BAdIs in ADT: `api:badi`
- Common in RAP scenarios for extending standard RAP BOs

### RAP BAdI Pattern

```abap
"BAdI for extending SAP Fiori apps / RAP BOs
"Implement the released BAdI interface
CLASS zcl_my_rap_badi DEFINITION
  PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_some_released_badi.
ENDCLASS.

CLASS zcl_my_rap_badi IMPLEMENTATION.
  METHOD if_some_released_badi~some_method.
    "Custom logic
  ENDMETHOD.
ENDCLASS.
```

### Dynamic BAdI Calls

```abap
"Dynamic GET BADI with BAdI name in variable
DATA lo_badi TYPE REF TO cl_badi_base.
DATA(lv_badi_name) = 'ZBADI_MY_BADI'.

GET BADI lo_badi TYPE (lv_badi_name).

"Dynamic CALL BADI with method name in variable
CALL BADI lo_badi->('VALIDATE')
  EXPORTING is_data = ls_data.
```

## Enhancement Spots and Implementations

Beyond BAdIs, the enhancement framework supports:

### Explicit Enhancement Points

SAP defines explicit points in standard code where custom logic can be inserted:

```abap
"In SAP standard code:
ENHANCEMENT-POINT z_enh_point SPOTS z_enh_spot.

"In your enhancement implementation:
ENHANCEMENT z_my_enhancement.
  "Your custom code here
  IF lv_condition = abap_true.
    "Custom logic
  ENDIF.
ENDENHANCEMENT.
```

### Explicit Enhancement Sections

```abap
"SAP code with replaceable section:
ENHANCEMENT-SECTION z_section SPOTS z_enh_spot.
  "Default code (can be replaced)
  lv_result = lv_a + lv_b.
END-ENHANCEMENT-SECTION.

"Your replacement:
ENHANCEMENT z_my_section_impl.
  "Custom replacement code
  lv_result = lv_a * lv_b.
ENDENHANCEMENT.
```

## Key User Extensibility

No-code/low-code extension capabilities available via SAP Fiori:

| Capability                    | Description                                 |
| ----------------------------- | ------------------------------------------- |
| **Custom Fields**             | Add fields to standard business objects     |
| **Custom Logic**              | Add validation/determination logic via BRF+ |
| **Custom CDS Views**          | Create simple analytical views              |
| **Custom Business Objects**   | Create simple transactional objects         |
| **Custom Analytical Queries** | Build queries on existing CDS views         |

## Best Practices

1. **Prefer new BAdI framework** over classic BAdIs
2. **Use filters** to scope implementations to specific contexts
3. **Implement fallback classes** for default behavior
4. **Keep implementations focused** — one concern per implementation
5. **Document the BAdI** with clear interface documentation
6. **Test implementations** independently using ABAP Unit
7. **In ABAP Cloud**, only implement released BAdIs

## Output Format

When helping with BAdI/enhancement topics, structure responses as:

```markdown
## BAdI / Enhancement Guidance

### Framework

- Type: [New BAdI / Classic BAdI / Enhancement Spot / Key User]
- Context: [ABAP Cloud / Standard ABAP]

### Implementation

[Step-by-step with code examples]

### Testing

[How to verify the enhancement works]
```

## References

- BAdI Cheat Sheet: https://github.com/SAP-samples/abap-cheat-sheets/blob/main/35_BAdIs.md
- Enhancement Framework: https://help.sap.com/docs/abap-cloud/abap-development-tools-user-guide/enhancement
- Key User Extensibility: https://help.sap.com/docs/sap-s4hana-cloud/extensibility

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [likweitan](https://github.com/likweitan)
- **Source:** [likweitan/abap-skills](https://github.com/likweitan/abap-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-likweitan-abap-skills-badi-enhancement
- Seller: https://agentstack.voostack.com/s/likweitan
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
