All about BAdIs

Experienced SAP consultants use the word “BAdI” frequently. In this post, I am going to explain what it is and its most common uses.

The BAdIs (Business Ad-ins) are tools for object-oriented programming in ABAP, that are used in SAP to implement validations and extensions to the SAP standard code in versions from 4.6c. For instance, the code generated by SAP in standard transactions (to order,…) cannot be changed (except to implement a SAP patch) since you would lose the support that SAP offers to its product. But imagine that when we finish a purchase order (PO) with transaction ME21N, we need to save certain data in a custom table called ZPORDER. For this reason we have the expansions (BAdIs, user exits, field exits, …). After all, they are just pieces of custom code that SAP allows us to introduce in its standard code to perform certain operations.

Do not confuse BAdIs with BApIs. The BApIs are simply ABAP functions available from transaction BAPI and called from other systems that perform specific operations with the parameters passed to them and can create purchase orders, modify, create material documents, …

Differences between BAdI and USER EXIT

  • BAdIs can be used as many times as needed, while USER EXITS can be used once time only. For example, if you assign a USER EXIT to a project with CMOD transaction, then you cannot assign it to another project. On the other hand, several developers can implement the same BAdI independently.
  • BAdIs are much more flexibles to the developer’s needs. We can define the exit points and the programming logic we need. It has all the properties of an object-oriented programming.
How to find the BAdI we need
There are several methods to find the BAdI we need, but I am going to explain a method based on transaction code ST05 (Performance Analysis).
This analysis technique is based on the fact that all BAdIs are registered in SAP tables. Thus, each time a BAdI is called the system go through those tables. The tables of the BAdIs are the following: SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. SAP always accesses those tables through the views V_EXT_IMP and V_EXT_ACT. Those views (tr. SE11) will be the basis of our analysis.
EXAMPLE:
Suppose we want to know what BAdIs are called in transaction BT “Mantain Business Partners”.

STEPS:

1.- Firstly, we have to check that no other user (tr. SM04) or background jobs (tr. SM50) are using the same user as you.
2.- Secondly, we have to enter in transaction ST05 (Performance Analysis) and set the indicator “Buffer trace”, after that we can press the button “Activate Trace”.
3.- Now the system is in “record” mode. Go to transaction BT, press the button “Organization” and fill in the fields with the following test data:
At the end, press the save button.
4.- Go back to the ST05 window and press the button “Deactivate trace” to finish the trace and press the button “Display Trace”. The popup “Set Restrictions for Displaying Trace” will appear.
5.- We have to filter the Trace by the objects: V_EXT_IMP and V_EXT_ACT. Which are our views.
Press the “Copy” button (F8), Fill Operations: OPEN and press “Enter”.
RESULT ANALYSIS:
We will obtain a Trace List like this:
All the “interface class names” of the view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for the “BAdI class interfaces”. The name of the BAdI starts after that IF_EX_. For instance, the name of the BAdI for IF_EX_ADDR_LANGU_TO_VERS is ADDR_LANGU_TO_VERS.
In transaction SE18 we can see the definition of the BAdI:
Advice: While the Trace execution, do not execute other transactions or commands in order to obtain the results as clean as possible.
However, we can see a list of the BAdIs availables following these steps:
– Go to transaction SE18
– Press F4 to open the matchcode
– Click on the “System information” icon
– Increase the maximum number of results to 999999
– Press the “OK” button

How to implement a BAdI
These are the two transactions we are going to work with BAdIs:
SE18 = BAdIs definition
SE19 = BAdIs implementation
Imagine that we have chosen the BAdI ME_PROCESS_PO_CUST and its method CLOSE which covers specific needs in the creation and modification of purchase orders, transactions ME21N and ME2N.
Therefore:
1.- Obtaining relevant information of the BAdI
  • Go to transaction SE18 with the BAdI ME_PROCESS_PO_CUST
  • Click on “Visualize”
  • Click on “Interface”
  • Double-click on “CLOSE”
  • Click on “Parameters” and go to IM_HEADER
In reference type we can see that its type is IF_PURCHASE_ORDER_MM
2.- Finding the available methods for each parameter
Suppose that we have chosen the BAdI ME_PROCESS_PO_CUST and the Interface POST
  • Go to transaction SE18 with the BAdI ME_PROCESS_PO_CUST
  • Click on “Visualize”
  • Click on “Interface”
  • Double-click on “POST”
We can see its parameters. Each of them has a reference type. The first of them is a simple type of data EBELN, the second IM_HEADER has the reference type IF_PURCHASE_ORDER_MM. With double-click on IM_HEADER the available methods will appear:
CREATE_ITEM
GET_DATA
GET_PREVIOUS_DATA
ETC.
With double-click on each method, we can see more details. For example:
  • Double-click on GET_DATA
  • Click on parameters
  • The parameter RE_DATA appears. It is a MEPOHEADER-type parameter.
  • Double-click on MEPOHEADER and we will see that is a header data stucture
It is important to know that at the beginin the implementation is not defined. The first time we enter in transaction SE19, we have to create the implementation with the same name that already has in SE18.
3.- Creating the implementation of the chosen BAdI
  • Go to transaction SE19
  • Click on “Create”
  • Enter the implementation name, for example ME_PROCESS_PO_CUST
  • Enter the definition name. It must be ME_PROCESS_PO_CUST
  • Select the AM2P package
  • Enter the transport order
  • Press the save button
  • Enter the SAP standard object modification password
  • Enter a short definiton. Usually the name of the transport order
  • Press the save button
  • Click on “Activate” and select all in order to recompile completely
4.- Modifying the source code of the implementation
  • Go to SE19 with the BAdI ME_PROCESS_PO_CUST
  • Click on Modify
  • Click on Interface
  • Double-click on CLOSE
  • Enter the password
  • Edit the text of the source code
Important: Do not forget the formal activation
– Go to SE19
– Click on Implementation
– Click on Activate
Advertisements

List of important SAP Tables

Important SAP tables list according to functional areas. In this link you can download an application which shows the relation between various SAP tables. Very useful!

Materials

MARA – Material Master: General data
MAKT – Material Master: Description
MARM – Material Master: Unit of Measure
MAPE  – Material master: Export control file
MARC – Material master: Plant data
MARD – Material master: Storage location
MAST – Material link to BOM
MBEW – Material valuation
MLGN – Material Master: WM Inventory
MLGT – Material Master: WM Inventory type
MDIP – Material: MRP profiles (field contents)
MKOP – Consignment price segment (old versions of SAP)
EBEW – Valuation of sales order stock
QBEW – Valuation of project stock
MVER – Material Master: Consumption <Plant>
DVER – Material Master: Consumption <MRP Area>
MVKE – Material Master: Sales <Sales Org, Distr Ch>
MLAN – Material Master: Tax indicator
MARC – Material Master: Plant data
MAPR – Material Master: Forecast
MARD – Material Master: Storage Location
MCH1 – Material Master: X Plant Batches
MCHA – Material Master: Batches
MCHB – Material Master: Batch Stock
MDMA – MRP Area data
DBVM – MRP Planning File Entry: MRP Area
MOFF – Outstanding Material Master Records (Maintenance status)

MARCH – Material Master C Segment: History
MARDH – Material Master Storage Location Segment: History
MBEWH – Material Valuation: History
MCHBH – Batch Stocks: History
MKOLH – Special Stocks from Vendor: History
MSCAH – Sales Order Stock at Vendor: History
MSKAH – Sales Order Stock: History
MSKUH – Special Stocks at Customer: History
MSLBH – Special Stocks at Vendor: History
MSPRH – Project Stock: History
MSSAH – Total Sales Order Stocks: History
MSSQH – Total Project Stocks: History

Vendors

LFA1 – Vendor Master: General data
LFB1 – Vendor Master: Company data
LFM1 – Vendor Master: Purchasing Data (Purchasing organization)
LFM2 – Vendor Master: Purchasing Data (Plant, Vendor sub-range)
WYT3 – Vendor Partner Functions

External Service Management

ASMD – Service Master: Basic Data
ASMDT – Service Short Texts

ESKL – Account assignment specification for service line
ESKN – Account assignment in service package
ESLH – Service package header data
ESLL – Lines in service package
ESSR – Service entry sheet header data
ESUC – External services management: Unplanned limits for contract item
ESUH – External services management: unplanned service limits header data
ESUP – External services management: unplanned limits for service packages
ESUS – External services management: Unplanned limits for service types

Purchasing

EBAN – Purchase requisition: items
EBKN – Purchase Requisition: account assignment
STXH – SAPScript Text Header
STXL – SAPScript Text Lines

EKKO – Purchasing document header
EKPO – Purchasing Document: Item
EKET – Purchasing Document: Delivery Schedules
MDBS – Material View of Order Item/Schedule Line (good to find open PO’s)
EKKN – Account assignment in purchasing document
EORD – Purchasing Source List
EIPA – Order price history record
EKAB – Release documentation
EKBE – Purchasing document history
EKBZ – Purchasing document history: delivery costs
EKPB – “Material to be provided” item in purchasing document

EINA – Purchase Info Record: General
EINE – Purchasing info record: purchasing organization data
KONP – Condition Item
KONH – Condition Header

Inventory Management

ISEG – Physical inventory document items

MKPF – Material document: Header
MSEG – Material document: item

RKPF – Reservation: Header
RESB – Reservation: Item

Invoice Verification

BSIM – Secondary index: documents for material
MYMFT – FIFO results table
MYML – LIFO material layer
MYMLM – LIFO material layer (monthly)
MYMP – LIFO period stocks, single material
MYMP1 – Receipt data LIFO/FIFO valuation
MYPL – LIFO pool layer
MYPLM – LIFO pool layer (monthly)
RBCO – Document item, incoming invoice account assignment
RBDIFFKO – Invoice Verification: conditions
RBDIFFME – Invoice Verification: quantity differences
RBDRSEG – Invoice Verification batch: invoice document items
RBKP – Document header: incoming invoice
RBKPB – Invoice document header (batch invoice verification)
RBTX – Taxes:incoming invoice
RBVD – Invoice document: summarization data
RBVDMAT – Invoice Verification: summarization data, material
RBWT – Withholding tax:incoming invoice
RKWA – Consignment withdrawals
RSEG – Document item, incoming invoice

Sales and Distribution

KONV – Conditions for Transaction Data
KONP – Conditions for Items
LIKP – Delivery Header Data
LIPS – Delivery: Item data
VBAK – Sales Document: Header Data
VBAP – Sales Document: Item Data
VBBE – Sales Requirements: Individual Records
VBEH – Schedule line history
VBEP – Sales Document: Schedule Line Data
VBFA – Sales Document Flow
VBLB – Sales document: Release order data
VBLK – SD Document: Delivery Note Header
VBPA – Sales Document: Partner
VBRK – Billing: Header Data
VBRP – Billing: Item Data
VBUK – Sales Document: Header Status and Administrative Data
VBUP – Sales Document: Item Status
VEKP – Handling Unit – Header Table
VEPO – Packing: Handling Unit Item (Contents)
VEPVG – Delivery Due Index

Customising and other master data

MDLV – MRP Areas
MDLG – MRP Areas – Storage Locations
MDLW – MRP Areas – Plants
MDLL – MRP Areas – Subcontractor
T023 – Material Groups
T024 – Purchasing groups
T030 – Standard Accounts Table (Automatic Account Determination)
T156 – Movement Type
T156T – Movement Type: Text

T16FS – Release Strategies
T16FT – Descriptions of Release Strategies
T16FV – Release Prerequisites
T16FD – Description of Release Codes
T16FK – Release Statuses
T16FC – Release Codes
AUSP – Release Procedure: Strategy values (cl20n, cl24n)
AGR_USERS – Assignment of roles to users
CDHDR & CDPOS – Change history of master data and documents
EDID4 – EDI information
TSTC – SAP Transaction Codes, lock/unlock: sm01, created: se93
TSTCT – Transaction codes TEXT

NAST – Message status


%d bloggers like this: