Friday, April 29, 2022

14.Enhancement











What is Enhancement in SAP?

  • Enhancement in SAP refers to the process of customizing or extending the standard SAP software without modifying its original code. 
  • When a company implements SAP, it comes with predefined standard objects provided by SAP. However, businesses often require additional functionality to meet specific needs that are not covered by the standard features. 
  • Enhancements enable organizations to introduce new functionalities or modify existing ones while preserving the integrity of the core SAP system.
  • Dictionary Object Enhancement: Used to add custom fields (Z-fields) to standard SAP tables.
  • Domain Value Enhancement: Allows adding new values to standard SAP domains that are not provided by SAP.
  • Source Code Enhancement: Used to insert custom logic into standard SAP programs. Ex: Adding validation rules to a standard SAP report.
  • Screen Enhancement: Enables adding fields to standard SAP screens.

Types of Enhancement:

  1. User Exits (Obsolete):
    • Available only in the SD module (Sales and Distribution).
    • SAP provides subroutines (PERFORM statements) that begin with USEREXIT_ in standard programs.
    • Requires an access key for implementation, hence it is called modification rather than an enhancement.
    • Downside: Changes do not persist after an SAP upgrade.
  2. Customer Exits:
    • Provides a custom way to enhance functionality of std.programs, function modules and screens.
    • Also known as Function Module Exits, Because Customer Exits are implemented thrw FM.
    • Types:
      • Menu Exits – Add custom menu options.
      • Screen Exits – Add custom fields to standard screens.
      • Function Module Exits – Extend SAP logic via function modules.
    • TCode: SMOD – Search for available customer exits.
    • TCode: CMOD – Create and configure enhancement projects.
  3. BAdI (Business Add-Ins):
    • Types: Old BAdIs and New/Kernal BAdIs
    • Flexible, object-oriented approach to enhancements, supporting multiple implementations.
    • Find BAdIs at SE18 using pkg or using class CL_EXIT_HANDLER in SE24 or using Get BAdI/ Call BAdI.
    • Implement BAdIs at TCode: SE19.
  4. Enhancement Options:
    • Implicit Enhancements
    • Explicit Enhancements
      • Enhancement Points
      • Enhancement Sections
  5. BTE (Business Transaction Events):
    • Used primarily in FI (Financial Accounting) modules.
    • Custom function module attached to the standard SAP program to enhance functionality.

SAP Recommended Usage by Enhancement Type

  • BAdIs (New/Kernal BAdIs)
    🔹 Use for most modern enhancements – especially in S/4HANA.
    🔹 Preferred method for flexible, object-oriented, multiple implementation support.

  • Customer Exits
    🔹 Use when SAP provides predefined exits (still valid in ECC & some S/4HANA areas).
    🔹 Recommended if BAdI is not available.

  • Enhancement Points (Implicit/Explicit)
    🔹 Use when no BAdI or Customer Exit is available.
    🔹 Use to enhance standard code without modifications (safe for upgrades).

  • BTE (Business Transaction Events)
    🔹 Use specifically for FI module enhancements where SAP exposes BTE points.
    🔹 Use when financial transaction enhancement is required and BAdI is not offered.

  • User Exits
    🔹 Not recommended by SAP.
    🔹 Use only in legacy SD scenarios where other options are unavailable.


________________________Lets See In Detail________________________


Customer Exit

Customer Exits are a type of SAP enhancement that allows adding custom functionality to standard SAP programs, function modules, and screens without modifying the original code.Customer Exits are also known as Function Module Exits.

Types of Customer Exits:

  1. Menu Exits – Add custom menu options to standard SAP applications.
  2. Screen Exits – Add extra fields or modify the layout of standard SAP screens.
  3. Function Module Exits – Extend SAP logic by enhancing function modules.
  • TCode: SMOD and SE24 – To find customer exits. SE24->Enhnc->Cust.Ext
  • TCode: CMOD – To Create and Implement enhancement projects.

To Find and Implement Funtion Module Exits:

Example: Implementing Validation in Material Master (MM01)
Requirement: If Material Type is NOF1, Then: Unit of Measure (UOM) must be FT2 (Sq. Ft.) and Material Group must be RS21312.

Step 1: Identify the Program Name for MM01
  • Open MM01 transaction → Go to System → Status → Program Name.

Step 2: Find the Package Name

  • Double-click the Program NameGoto → Object Directory Entry → Package Name.
  • Alternatively, use SE93:
    • Enter TCode MM01 → Find Program Name & Package Name.

Step 3: Search for Customer Exit

  • Open SMOD → Press F4 → Select Information System.
  • Enter the Package Name obtained from Step 2.
  • Review the available exits and select the one that fits the requirement.

Step 4: Create an Enhancement Project in CMOD

  • Open CMOD and create a new Project (ZMAT).
  • Go to Enhancement Assignment and enter the selected Customer Exit from SMOD.
  • Click Components → Double-click the EXIT_SAP* function module.
  • Double-click the Include Z* and add the required custom code.

Step 5: Implement the Validation Logic & Activate

  • Write the custom validation logic inside the include.
  •   IF wmara-mtart 'NOF1'.
        IF wmara-meins NE 'FT2'.
          MESSAGE 'For NOF1 Material, UOM must be FT2' TYPE 'E'.
        ENDIF.
        IF   wmara-matkl NE 'RS21312'.
          MESSAGE 'For NOF1 Material, Material Group must be RS21312' TYPE 'E'.
        ENDIF.
      ENDIF.

  • Activate the enhancement project in CMOD.

Step 6: Test the Implementation

  • Run MM01 and check if the validation logic is working as expected.


To Find and Implement Menu Exits:

Menu Exit allows adding a custom menu option to the SAP menu bar without modifying standard SAP code.

Example: Adding a "Call Smartform" option in SE38
  1. Identify the Menu Exit:

    • Open SE38SystemStatus.
    • Double-click on the menu options (e.g., Program, Edit, Goto, Utilities) to check if +CUS exists, confirming that a custom menu option can be added.
  2. Find the Package of the Program:

    • Open SE38, display any program.
    • Navigate to SystemStatus.
    • Double-click on the program name (e.g., SAPLS38E).
    • Go to Object Directory Entry and find the package name.
  3. Find Menu Exit Using SMOD:

    • Open SMOD → Press F4 → Select Information System.
    • Enter the package name found in the previous step.
    • Look for the Menu Exit (e.g., SEU00002).
  4. Implement Using CMOD:

    • Open CMOD → Create a project (e.g., ZSE38).
    • Assign the Menu Exit found in the previous step under Enhancement Assignment.
    • Click on Components → Select the provided menu exit (e.g., SAPLWBABAP).
    • Enter the Function Text (e.g., Call Smartform).
    • Navigate to the function module provided → Double-click on the Z-include.
    • Implement the required logic and activate it.
  5. Custom Logic in Z-Include:

    IF sy-ucomm = '+CUS'. CALL TRANSACTION 'SMARTFORMS'. ENDIF.

To Find and Implement Screen Exits:

To be update...



Limitations of Customer Exit in SAP
  • Single Enhancement Project per Customer Exit:

    • Only one enhancement project can be created for each customer exit.
    • Multiple implementations are not possible for the same customer exit.
  • Limited Flexibility:

    • Enhancement points are predefined by SAP, restricting where and how modifications can be made.
    • Customization is limited to available exits, making it less adaptable for complex business requirements.
  • Procedural Implementation:

    • Customer exits follow a procedure-oriented approach, meaning they rely on function modules and procedural coding rather than object-oriented principles
    • Implementation is done using custom includes(Z*) provided inside function modules associated with the enhancement.
    • The required logic is written inside these includes to extend the standard functionality.

    BAdI (Business Add-Ins).

    1. BAdI (Business Add-In) is an enhancement technique in SAP that allows multiple implementations and offers greater flexibility compared to customer exits. 
    2. It follows object-oriented programming (OOP) principles and is implemented through interfaces.
    3. More flexible than Customer Exits, supporting multiple implementations, filters and better performance.

    Transaction Codes:

    • SE18 / SE84 – Define or search for a BAdI.
    • SE19 – Implement the BAdI.
    Types of BAdIs:

    1. Classical BAdI (Old BAdI)
      • Definition: The BAdI approach introduced after customer exits as part of the enhancement framework.
      • System will automatically generate a Z-Class while creating implemetation of the classical BAdI.
    2. Kernel BAdI (New BAdI)
      • Definition: The newer and more advanced version of BAdI introduced in the Enhancement Framework after Classical BAdIs.
      • Kernal BAdI has enhancement spots, which act as containers for BAdI implementations.
      • We have to enter Z-Class name while creating implemetation of the New/Kernal BAdI.

      To Finding a BAdI: (SE18, SE84, Prog way for kernal, Prg way for classical)

      1. Open SE18 → Enter the BAdI name or package by pressing F4 to search for available BAdIs.
        • BAdIs without enhancement spots are Classical BAdIs.
        • BAdIs with enhancement spots are Kernel BAdIs.
      2. SE84->Enhancement->Bussiness Add-Ins->Defenition->Enter the BAdI name or package to search for available BAdIs.
      3. Finding a Kernel BAdI Programmatically:
        Kernel BAdIs are directly called in ABAP code using GET BADI and CALL BADI. You can find them dynamically by debugging.

        Steps to Identify a Kernel BAdI in a Transaction Code:

        1. Open the transaction (T-code) where you want to find the BAdI.
        2. Enter the necessary details and stop just before performing the action that triggers the BAdI.
        3. Activate the Debugger:
          • Enter /h in the command field and press Enter to start the global debugger.
        4. Set Breakpoints on Kernel BAdI Statements:
          • In the debugger, go to:
            Menu Bar → Breakpoints → Breakpoint At → Breakpoint At Statement

          • Enter GET BADI and CALL BADI as breakpoints.
        5. Press F8 (Continue) repeatedly to reach the first breakpoint.
        6. The debugger will stop at the GET BADI statement, revealing the BAdI instance being used.
        7. Continue pressing F8 until the CALL BADI statement is reached, where you can see the exact method being executed.
        Key Concepts:
        • GET BADI returns an instance of the BAdI implementation class.
        • CALL BADI executes the methods of the retrieved BAdI instance, triggering the custom business logic.
      4. Finding Classical BAdI using CL_EXITHANDLER (Programmatic Search)
        • Classical BAdIs are invoked using the proxy class CL_EXITHANDLER.
        • Methods like CL_EXITHANDLER=>GET_INSTANCE help identify the BAdI dynamically.

      Steps to Find BAdI in Code:

        1. Open SE24 → Enter class CL_EXITHANDLER.
        2. In display mode, go to the Methods tab.
        3. Double-click on GET_INSTANCE to view the source code.
        4. Set a breakpoint on: CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE
        5. Run the transaction code for which you want to find the classical BAdI.
        6. The debugger will stop at this method, helping you find the associated classica BAdI at exit.

      Implementation Types of BAdIs
      1. SAP Internal - Only for SAP internal uses, we cannot use.
      2. Single Implementation BAdI – Allows only one active implementation. 
      3. Multiple Implementation BAdI – Supports multiple active implementations running in parallel.
      4. Filter BAdI – Allows different implementations to be executed based on specific filter values.

      Example: Implementing Validation in Material Master (MM01) using classical BAdI.
      Requirement: If Material Type is NOF1, Then: Unit of Measure (UOM) must be FT2 (Sq. Ft.) and Material Group must be RS21312.
      To be update...

      Example: validating to add header text while creating mat creation using Kernal badi.
      To be update...



      Enhancement Options.

      Enhancement options define specific positions within the SAP Object Repository where enhancements can be implemented. These options can either be explicitly defined by the developer or provided by SAP.

      Types of Enhancement Options

      1. Implicit Enhancement Options

      • Provided by the framework and always exist at fixed positions in SAP standard programs.
      • They do not require an enhancement spot for activation.
      • Available at fixed positions, such as:
        1. Start and end of a program
        2. Subroutines
        3. Function Modules
        4. Methods in Classes
      • Usage:
        • Allows adding additional logic without modifying SAP standard code.
        • Cannot replace or change SAP standard logic.

      2. Explicit Enhancement Options

      • Defined by developers within an SAP program.
      • Managed using Enhancement Spots and enhanced using Enhancement Implementations.
      • Can be placed anywhere within the code.
      • Types of Explicit Enhancements:
        1. Enhancement Point:
          • Allows adding custom logic without modifying SAP standard code.
          • Does not provide default implementation.
        2. Enhancement Section:
          • Allows modification or replacement of SAP standard code.
          • Provides a default implementation, which can be overridden.

      Example 1 - Implicit Enhancement in VA02 (Sales Order Change Mode)

      Requirement:
      In VA02 (Change Sales Order), when a user enters a Material ID, the system should automatically populate the Order Quantity field from mara table as a default value.
      To be update...

      Example 2 - Explicit Enhancement(Enhc Pt) in MM01 

      Scenario:In MM01 (Material Master Creation), when entering the Material Type(form fit function class), an internal material ID should be provided. The first four digits of this ID represent the Plant Name.
      Business Requirement:Before proceeding, we need to validate whether the entered plant exists in the system. If the plant does not exist, an error message should be displayed.
      To be update...

      Example 3: Explicit Enhancement (Enhancement Section) in MM01

      Requirement:In MM01 (Material Master Creation), we need to assign a different number range for the Material ID based on the following condition: If Material Type = 'RAW MAT' (Raw Material) and Industry Sector = ' ' (Blank) then The Material ID should be assigned from a specific number range based on this condition.
      To be update...




      BTE (Business Transaction Events).

      BTE is Business Transaction Event, an enhancement technique designed primarily for the FI (Financial Accounting) module in SAP.
      It allows developers to add custom functionality using predefined interfaces by implementing custom function modules.

      Steps to Implement BTE in SAP
      1. Find a Suitable BTE Event
        • Go to transaction FIBF
        • Navigate to: Environment → Information System → Execute
        • Search and identify the relevant BTE event that matches your business requirement.
      2. Create a Custom Function Module
        • In the same screen, select the BTE event.
        • Click on Sample Function Module.
        • Copy it to a custom function module under your own function group.
        • Add your custom logic and activate it.
      3. Create and Activate a Product
        • Go to: FIBF → Settings → Products → Of a Customer → New Entries
        • Enter a unique Product ID and description.
        • Check the Active checkbox and save.
      4. Assign the Function Module to the BTE Event
        • Go to: FIBF → Settings → P/S Modules → Of a Customer → New Entries
        • Enter:
          • Event ID (e.g., 00001650)
          • Product ID (created in Step 3)
          • Function Module (created in Step 2)
        • Save your entries.

      Example: Add Customer Name Field in FBL5N Using BTE

      Business Requirement:
      In transaction FBL5N, the business needs to display the Customer Name at the line item level.

      15.Modern Syntax ( 7.4/7.5 Syntax )