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.

      Step 1: Identify the Appropriate BTE Event
      • Go to Tcode: FIBF
      • Navigate to: Environment → Information System → Execute
      • Search for a suitable event based on your requirement.
      • For FI line item and header commonly used enhancements, are:
        • Event 00001650Line Item Display: Add to data per line
        • Event 00001640Line Item Display: Additional header lines

      Step 2: Enhance Standard Structures

      To include the Customer Name in the output, we have add field to the structures mentioned in the BTE events documentation:

      • Add field NAME1 to the structures: RFPOS and RFPOSX using append structure.
      • Use Program: RFPOSXEXTEND via SE38 to regenerate and activate the updated structure.

      Step 3: Create a Custom Function Module
      • Go back to FIBF → Environment → Information System → Execute
      • Select Event 00001650
      • Click on Sample Function Module
      • Copy the sample FM to a custom FM (e.g. ZSAMPLE_INTERFACE_00001650) under a custom function group
      • Implement logic to fetch Customer Name (e.g., from table KNA1) and populate the new field
      • Activate the function module

      Step 4: Create and Activate a Product
      • Go to: FIBF → Settings → Products → Of a Customer → New Entries
      • Enter:
        • Product ID: e.g., ZFI_CUST
        • Description: e.g., FBL5N Enhancement - Add Customer Name
        • Check the Active checkbox
      • Save

      Step 5: Assign Product to BTE Event
      • Go to: FIBF → Settings → P/S Modules → Of a Customer → New Entries
      • Enter:
        • Event: 00001650
        • Product: ZFI_CUST
        • Function Module: ZSAMPLE_INTERFACE_00001650
      • Save your entries

      Step 6: Test in FBL5N
      • Go to Tcode: FBL5N
      • Execute the report
      • Click on Change Layout
      • Find and add the new field (e.g., Customer Name) to the report output
      • The new field should now display the corresponding values



      REAL TIME EXAMPLES

      Example 1: Material Master Screen Enhancement (Adding Custom Field)

      Objective:
      To enhance the Material Master screen by adding a custom field using a combination of SPRO and ABAP coding.

      Steps:

      1. Append Custom Fields to MARA Table:
        • Create an append structure and add your custom fields to the MARA table.
      2. Create Function Group via SPRO (Not SE80):
        • Navigate through SPRO to create the Function Group.
        • This ensures the system copies the standard Function Group (FG) to a customer-specific Function Group.
      3. Add custom fields to Screen 0001:
        • The Function Group will contain default screens 0001 and 0002.
        • Add the custom field to screen 0001.
      4. Implement PBO and PAI Logic:
        • Write the necessary PBO (Process Before Output) and PAI (Process After Input) logic in the TOP include of the Function Group.
      5. Add the Custom Screen in Standard data screen via SPRO:
        • Using SPRO, include your custom screen in the standard data screen sequence.
      6. Test the Enhancement:
        • Create a new Material to verify that the custom field appears and behaves as expected.

      Step By Step Procedure:

      1. Append Custom Fields to MARA Table

        • Go to SE11 → Open MARA table
        • Use Append Structure to add custom fields (e.g., ZZ* fields)

      1. Create Function Group via SPRO (Not SE80)

        • Navigate:
          SPRO → SAP Reference IMG → Logistics General → Material Master → Config Material Master → Create program for customized subscreen

        • Choose Retail → Execute
        • Enter Custom Function Group name (e.g., ZMDG4) and description → Save
        • Now go to SE80 → Select Function Group → Enter ZMDG4 → Right-click → Activate
        • This creates default screens 0001 and 0002 and a TOP include program.

      1. Add Custom Fields to Screen 0001

        • In SE80 → Open Screen 0001 of ZMDG4 → Change Mode → Layout
        • Add a Box using the toolbox → Name it as RERA AREA → Assign to group (e.g., GRP1)
        • Use Dictionary Program Fields Window icon(F6) to fetch fields from MARA (ZZ* fields)
        • Add fields inside the box → Assign to group (GRP1) → Save → Activate

      1. Write Logic in the TOP Include

        • In the function group include (e.g., LZMDG4TOP), create modules:
        • MODULE modify_screen in PBO:
          • Controls edit/display mode depending on Tcode (e.g., MM03 = display mode)
          • This controls whether the custom field is in display or edit mode.
            MODULE modify_screen OUTPUT. IF sy-tcode = 'MM03'. " Display mode LOOP AT SCREEN. IF screen-group1 = 'GRP1'. " Group name used in layout screen-input = 0. MODIFY SCREEN. ENDIF. ENDLOOP. ENDIF. ENDMODULE.
        • MODULE get_data in PBO:
          • Use standard FM MARA_GET_SUB to fetch data
        • MODULE set_data in PAI:
          • Use standard FM MARA_SET_SUB to update data
        • Save → Check → Activate

      1. Register Custom Subscreen via SPRO

        • Go to:
          SPRO → Logistics General → Material Master → Config Material Master → Define Structure of Data Screens for Each Screen Sequence

        • Select the Standard Industry tab page
        • On the left, double-click Data Screen → Then select e.g., Basic Data 1
        • Under the subscreen list, locate screen 0001 → Replace the program name from SAPLMGD1 to your custom FG (e.g., SAPLZMDG4)
        • Save your changes to a transport request

      1. Test the Enhancement

        • Go to MM01, MM02, or MM03
        • Check that your custom fields are now visible on the screen
        • Create a new material and verify the custom field is working as expected

      Summary:

      SAP offers several types of enhancements:

      • 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.

      • Source Code Enhancement: Used to insert custom logic into standard SAP programs.

      • Screen Enhancement: Enables adding fields to standard SAP screens.

      specific enhancement technologies In-Short:

      • User Exits: These are subroutines provided by SAP ( starting with USEREXIT_ ) within standard SD (Sales and Distribution) module programs. Implementing them requires an access key and is considered a modification, as changes may not persist after SAP upgrades. SAP does not recommend their use except in legacy SD scenarios when other options are unavailable.

      • Customer Exits: These provide a way to enhance the functionality of standard programs, function modules, and screens through function modules. They are also known as Function Module Exits.

        • Types include Menu Exits (add custom menu options), Screen Exits (add custom fields to screens), and Function Module Exits (extend SAP logic).

        • Transaction codes SMOD (search for exits) and CMOD (create/configure enhancement projects) are used.

        • Limitations include only one enhancement project per customer exit, limited flexibility due to predefined exit points, and a procedural implementation approach.

      • BAdI (Business Add-Ins): This is a flexible, object-oriented approach supporting multiple implementations. There are two types:

        • Classical (Old) BAdIs: Introduced after customer exits. A Z-class is automatically generated during implementation. They can be found using SE18, SE84, or programmatically via class CL_EXIT_HANDLER.

        • Kernel (New) BAdIs: A more advanced version with enhancement spots as containers for implementations. You have to enter a Z-class name during implementation. They can be found using SE18, SE84, or programmatically using GET BADI and CALL BADI statements (debugging is often used).

        • Transaction codes SE18/SE84 (define/search) and SE19 (implement) are used.

        • BAdIs support SAP Internal, Single Implementation, Multiple Implementation, and Filter-dependent implementations.

        • SAP recommends using New/Kernel BAdIs for most modern enhancements, especially in S/4HANA, due to their flexibility and support for multiple implementations.

      • Enhancement Options: These define specific positions where enhancements can be implemented.

        • Implicit Enhancements: Provided by the framework at fixed positions (e.g., start/end of programs, subroutines, function modules, methods) and do not require an enhancement spot. They allow adding logic without modifying standard code but cannot replace existing logic.

        • Explicit Enhancements: Defined by developers and managed using Enhancement Spots and Implementations.

          • Enhancement Points: Allow adding custom logic without modifying standard code and do not provide a default implementation.

          • Enhancement Sections: Allow modification or replacement of standard code and provide a default implementation that can be overridden.

        • SAP recommends using Enhancement Points/Sections when no BAdI or Customer Exit is available. They are safe for upgrades.

      • BTE (Business Transaction Events): Primarily used in the FI (Financial Accounting) module. Custom function modules are attached to standard SAP programs to enhance functionality.

        • Transaction code FIBF is used to find events, create products, and assign function modules.

        • SAP recommends using BTEs specifically for FI module enhancements where BTE points are exposed and when financial transaction enhancement is required and a BAdI is not offered.

      Points to Remember:

      • Enhancement in SAP is the process of customizing or extending standard SAP software without modifying its original code.

      • SAP offers various enhancement techniques including Dictionary/Domain/Source Code/Screen Enhancements, User Exits, Customer Exits, BAdIs (Classical and Kernel), Enhancement Options (Implicit and Explicit with Points and Sections), and BTEs.

      • User Exits are obsolete and not recommended by SAP, primarily available in the SD module, require an access key, and their changes do not persist after upgrades.

      • Customer Exits use function modules to extend standard functionality in programs, function modules, and screens. Key T-codes are SMOD (find) and CMOD (implement). They have limitations like single implementation and predefined exit points.

      • BAdIs are a flexible, object-oriented approach supporting multiple implementations. New/Kernel BAdIs are the preferred method for modern enhancements, especially in S/4HANA. Key T-codes are SE18/SE84 (find) and SE19 (implement).

      • Enhancement Options allow adding or replacing code at defined positions within SAP programs. Implicit enhancements are at fixed positions and cannot replace code, while explicit enhancements (Points and Sections) are developer-defined. Use them when no BAdI or Customer Exit is available; they are safe for upgrades.

      • BTEs are used primarily for FI (Financial Accounting) module enhancements by attaching custom function modules to standard programs. The key T-code is FIBF.

      • Understanding the appropriate transaction codes (SMOD, CMOD, SE18, SE19, FIBF) is crucial for finding and implementing different types of enhancements.

      • SAP recommends using New/Kernel BAdIs for most modern enhancements, Customer Exits when predefined exits are available and no BAdI exists, Enhancement Points/Sections when no BAdI or Customer Exit is available, and BTEs specifically for FI module enhancements where BTE points are exposed. User Exits are not recommended.


































      No comments:

      Post a Comment

      15.Modern Syntax ( 7.4/7.5 Syntax )