Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Abap Enhancement

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44
At a glance
Powered by AI
The key takeaways are that enhancement allows adding custom functionality to standard SAP applications without modifying the original code. The main types of enhancement discussed are user exits, customer exits, screen exits, menu exits and function module exits.

The different types of enhancement discussed are user exits, customer exits, screen exits, menu exits and function module exits.

User exits have limitations like they cannot be reused, will be overwritten during upgrades and it is easy to manipulate data. Customer exits do not affect standard SAP code or updates but are not available for all programs.

ABAP ENHANCEMENT

The enhancement concept allows you to add your own functionality to SAP's standard
business applications without having to modify the original applications.
To modify the standard SAP behavior as per customer requirements, we can use
enhancement framework.
SAP does not promote modifications to their standard codes, but they provide some exits
(include files, function modules, sub-screens) for developers to include their own functionalities.
Hence through enhancement (Exits) the developers can be able to add few changes to the existing
SAP codes without affecting the standard codes.
Types of Enhancement:
 User Exits
 Customer Exits
 Screen Exits
 Menu Exits
 Function Module Exits
 Field Exits --> Obsolete
 New Enhancement Framework
 Implicit
 Explicit
 Enhancement Points.
 Enhancement Sections.
 BADI’s - For enhancing methods and object.
User Exits:
User Exits actually comes under Modification of standard SAP codes and they are available
only for SD Modules.
An ABAP developer needs an access key to modify the user exits provided by SAP.
These are implemented in the form of sub-routines and hence known as FORM EXITS.
The user exits are generally collected in includes and attached to the standard program by the SAP.
User-exits are empty subroutines that SAP Developers have provided for you. You can fill them with
your own source code.
All User exits start with the word USEREXIT_...
FORM USEREXIT_XXXX....
INCLUDE ZZUSEREXIT.......
ENDFORM.
How to Identify a User Exit?
User exits can be found in the following ways:
Go to Object Navigator (SE80), select Package and put VMOD (Application development R/3
SD customer modification) and press enter. You will find all the includes for user exits in SD. You will
get User exits for Sales order, Delivery, Billing, Pricing etc.
Limitations of User Exit:
 User Exits Cannot be Re-usable.
 Will be overwritten during Upgrade.
 Read / Change almost every Data Object which is defined Globally in the Program.
 Very Easy to manipulate the Data which could result in Erroneous outcome.
Customer Exits:
Unlike user exits the Customer Exits are implemented as function modules and can be
enhanced without access key.
SAP creates customer exits for specific programs, screens, and menus within standard applications.
These exits do not contain any functionality. Instead, the customer exits act as hooks. You can hang
your own add-on functionality onto these hooks.
Customer exits are nothing but a include in customer name space will be provided in the function
module which starts with CALL CUSTOMER. You can fill them with your own source code.
User exits generally refer to the SD module while customer exits refer to all modules like MM, SD,
PP, FICO etc.
Advantage:
 They do not affect the standard SAP source code.
 They do not affect software updates.
Disadvantage:
 Customer exits are not available for all programs and screens found in the SAP System. You
can only use customer exits if they already exist in the SAP System.
Types of Customer Exits:
 Function Module Exits
 Screen Exits
 Menu Exits
 Field Exits --> Obsolete
Function Module Exits:
The exit is implemented as a call to a function module. The code for the function module is
written by the developer. You are not writing the code directly in the function module, but in the
include that is implemented in the function module.
Format: CALL CUSTOMER-FUNCTION '910'.
The naming standard of function modules for function module exits is:
EXIT_<program name>_<3-digit suffix>
Examples:
Before enhancement any country code can be used.
The enhancement can be implemented within the include file given inside the function module.

Modifying code to accept only US country code.

After Enhancement only the country code US can be used.


Screen Exits:
Allow customer to add fields to a screen via a sub screen in an SAP program. The sub screen
is called within the standard screen's flow logic.
Format: CALL CUSTOMER-SUBSCREEN CUST_SCR1.
Example:
Create a project in CMOD with enhancement PPCO0012.

Go to components Double click on screen exit SAPLCOKO1 it will take you to

The screen number 0100 program name SAPLXCO1.

Design your screen as per the requirement in screen layout.

For PBO use the function module EXIT_SAPLCOKO1_001


For PAI use the function module EXIT_SAPLCOKO1_002

Now in order to declare the screen fields globally

Go to function group XC01 in SE80, declare in the include ZXCO1TOP

Use the E_COCI_AUFK exporting parameter to append the values to Structure CI_AUFK, which will
get saved in AUFK when the production Order gets saved.
Create the Custom field in the structure CI_AUFK.

Create the production order using the transaction CO01.

Custom tabs appear as follows

Now when you create the production order the value entered in the custom field gets saved along
with the production order data in AUFK table.

Menu Exits:
Menu exits allow you to add your own functionality to menus. Menu exits are implemented
by SAP and are reserved menu entries in the GUI interface. The developer can add his/her own text
and logic for the menu.
Function codes for menu exits all start with "+".
Format: +CUS (additional item in GUI status)
Example:
Identify the menu exit from the standard transaction, i.e. through SMOD.

Go to transaction SMOD. and press F4.

Choose from information system, if you get a screen as shown below.

You will get the below screen. Enter the package name in Package and press enter.

(You will get the package name using attributes of the program for the transaction)
These are the list of exits available and MCP20003 is the Menu exit.

Go to the initial screen of SMOD transaction and enter the enhancement name and select the option
component and click on display to check the list of components from the enhancement.
You will get the components of the exit.

Note: since the function codes for the menu options are already available, it is enough to provide
the meaningful descriptions. But this enables the options only and the functionality can be linked in
the function code.

Execute the COMD transaction and provide the project name and click on Create button if the

project is not yet created. Else deactivate the project by clicking on and open the project in
change mode.
Now click on the enhancement assignments.

Provide the enhancement name, save it and click on components

Now you will get the components of the exit. Double click on required function code i.e. +CU1.
Provide the function text, which is to be displayed as the menu option and click on Copy.

Once the test is provided, we need to link the functionalities for the already activated function codes
through the function module exits.

Double click on the function module exit EXIT_SAPMMCP6_003.

Now double click on include ZXSOPU03. It will ask for creation click on Yes.
Save it as a local object and write the code as shown below. And activate it.

Now back to the initial screen of COMD and activate the project

Note: Make sure that the project is always activated and so that the additional functions get
activated.

Testing the Enhancement:


We need to execute the corresponding standard transaction to make sure that the
additional options are available and the corresponding functions are called.

Execute the transaction MC94. Enter the planning type and press enter

Enter the Material group and Material number. Now click on Active version.

Now you will get a screen as shown below.

Now in Menu go to Extras -> Customer functions you can find the Menu item “Create program -
SSR3KOR” which is created now.
Click on Create program – SSR3KOR. You will get SE38 screen where you can create a program.

Field Exits: (Obsolete)


A field exit is an old enhancement technology linked to a screen input field (only dynpro
technology is supported) which executes custom ABAP code, that is allowed to:

 Change the value of the field


 Trigger an error message on that field

A field exit applies to a given data element and a given dynpro or all dynpro’s, and is active
for all clients.

It is called just after the user has pressed a key (see below how it works).
It calls a function module with a special name that needs to be registered via program RSMODPRF
(see below how to implement).

Field exit technology is deactivated by default since NetWeaver 6.10 and is obsolete since SAP Basis
4.6a.

How it works:

The field exits cannot be called in releases 6.10 (and after) if the "abap/fieldexit" profile
parameter is set to 0

Here are the moments where the field exits are called,

 The user presses Enter, a function key or click a button


 Conversion of the input field from external to internal format
 CALL OF FIELD EXITS on input-capable fields which are NOT part of a step-loop
 Call PAI modules placed before the step-loop
 STEP-LOOP
o CALL OF FIELD EXITS on input-capable fields which are part of the step-loop
o Call PAI modules placed inside the step-loop
 Call PAI modules placed after the step-loop

Restrictions:

If the PAI contains a "FIELD <field name> MODULE <module name> ON REQUEST" about an
input field which has also a field exit, and only the field exit changes the value, then the module is
not called

If the relationship between the field and the DDIC is deactivated, the field exit is not called

Implementing a Field Exit:

In releases 6.10 and after, the "abap / fieldexit" profile parameter must be changed from 0
to 1 (transaction RZ10 or RZ11), and the system must be restarted so that to take this change into
account

Cross-client customizing must be allowed in the client where development is done

First, you must get some information about the field for which you want to execute a field exit

Display screen where you need to add an exit to a field, press F1 and display technical information,
write down data element name + dynpro/program name

Note: If 2 dynpro numbers are displayed, use the one at the top (for information: this happens when
the field belongs to a "sub-screen"; the top dynpro number is the sub-screen number, while the
bottom number is the main screen number, used for batch input)

Run transaction SE38, execute the program RSMODPRF

Enter the data element of the field to be enhanced.

Note: if you just want to display all existing field exits, leave the data element field blank.

It then displays a screen with function module FIELD_EXIT_<data_element>. Note: you may change
the name by adding a 1 character or 1-digit suffix, like this:
FIELD_EXIT_<data element> [_<one digit or one letter>]

Press Create

You must assign this function module to a function group and to a package of the customer
namespace (most common is to have Y or Z as the first character)

This function module must have "INPUT" importing parameter, and "OUTPUT" changing parameter,
both without type

OUTPUT is received with the same value as INPUT

You may change the OUTPUT parameter or send an error message which interrupts the dynpro logic

Go back to RSMODPRF selection screen, let the selection screen input fields blank, EXECUTE IT, then
your field exit is displayed (and all the others).

Check box of your field exit, you have the option to assign it to a particular dynpro (combination
dynpro/data element). Default screen name is "GLOBAL" (valid for all dynpros).

Check box of your field exit, and select menu Fieldexit | Activate. Note: You have to enter a
workbench transport request (object of type R3TR XDYN)

It's done. Be careful when you have several application servers.

After transport of the field exit in a target system, you must call program RSMODFDG in the target
system (any client) to activate the field exit

Miscellaneous:

If several fields have the same data element in the same dynpro, the field exit will apply to
all of them.

Break-points are ignored in field exits with the classic debugger (but it works with the new
debugger).

If you execute the following ABAP statements during the field exit, the program will dump: CALL
SCREEN, CALL DIALOG, CALL TRANSACTION, SUBMIT, MESSAGE W... and MESSAGE I..., COMMIT
WORK, ROLLBACK WORK, COMMUNICATION RECEIVE, STOP, REJECT, EXIT FROM STEP-LOOP.

Methods to find out customer Exits:

There are numbers of way by using we can find out Customer Exits.

Method 1: Call customer Exit

If you are searching customer exits based on the particular transaction.

Go to Transaction. Ex: VA01.


Then system-> status

Double click on Program(screen).

Find(Cntrl + F)

Then use Call customer and select in the main program radio button tab and press Enter.
We can find out all the possible Customer exits based on this transaction.

Method 2: SMOD

Go to Transaction SMOD (SAP Enhancement).

Then Utilities-> Find

Give the Package name and Execute (F8).


For a Purchase Order package is ME.

We can find out all the possible Enhancement (Customer exits) based on this package.
Method 3: SE84
Go to Transaction SE84.

Select Enhancements -> Customer Exits -> Enhancements

Give Package and Execute. We can find out all the possible Enhancement (Customer exits) based on
this Package.

Method 4: SE81
Go to Transaction SE81.

Click on the Module name (ex: SD).

Then from the top menu select Edit -> Select sub tree +/-.

Select Information System.

A new Screen will appear, it looks like SE84.

Then select Enhancements -> Customer Exits ->Enhancements.


Double click on Enhancements and Execute.

We can find out all the possible Enhancement (Customer exits) based on this Module.

Method 5: ST05

Go to Transaction ST05. Select Table Buffer Trace & Activate Trace.

Then go to the transaction, based on which you want to see the customer exits.

Come back to ST05, Deactivate Trace & display Trace.

Then go to FIND & write text EXIT_ & press ENTER.


We can find out all the possible Enhancement (Customer exits) based on this Transaction. This is not
a good technique to find out customer exits because all the possible exits may not be found out
using this technique.

SAP Enhancements (SMOD):

This transaction is used to see the list of objects in an enhancement. It is a container which
holds many related objects within it.

If you Double click on TEST button, you will get below screen.

From the above screen shot we can say that the Function Exit is already implemented (Green light)
but in Inactive stage (Red light).

Project Creation (CMOD):

This Transaction is used to create a project. Project is also a container, which holds several
Enhancements. If we identify the User Exits and write down the code only within it, then the
functionality will not be worked. That is why we require adding the enhancement into a project &
making it active.

CMOD Transaction is used to create a project.

Select Enhancement assignments and you add your Enhancement in this project.

You can add multiple Enhancements in one project. But you can't add one enhancement in multiple
projects. Then error message will be generated.

Error message generate, because Enhancement V45A0002 is already exist in another project.

From screen short no: 2 of CMOD description, if we click on Components, we will get the list of
Customer exits belongs to these enhancements.
Both Green-light shows that the exit is already implemented & is Active stage.

New Enhancement Framework:


Implicit Enhancement:
Throughout the ABAP system, enhancement options are automatically available at certain
pre-defined places.
Some of the implicit options are:
 At the end of all the programs (Includes, Reports, Function pool, Module pool, etc.),
after the last statement.
 At the beginning and end of all FORM subroutines.
 At the end of all Function Modules.
 At the end of all visibility areas (public, protected and private) of local class.
To view all the implicit options available in a source code, choose ‘Edit -> Enhancement Operations
-> Show Implicit Enhancement Options’ from the editor.

You don’t need to have an explicitly defined enhancement spot in order to implement these
enhancements.
Just position the cursor on any of these implicit points and choose ‘Create Enhancement’ from the
menu to
implement it.
Example:
1. In SE37.
2. Screen will look something like this.

3. Select Enhance Source Code Icon.

4. Screen will come white & fonts will come Gray, select Show Implicit Enhancement Options.

5. Yellow lines will come, place your cursor on the yellow strip & create enhancement.
6. Choose the declaration type of enhancement.
7. Now place your required code in this section.

8. Here we have placed one popup to confirm


9. Activate the function module & run you will find the implemented enhancements.

Explicit Enhancement:
The Implicit enhancement options are provided at specific source code places explicitly by
SAP (Note that these enhancement definitions can also be created by partners and customers in
their code).
There are two types of Explicit Enhancement options available.
 ENHANCEMENT-POINT
 ENHANCEMENT-SECTION
Enhancement Point:
There can be multiple active implementations of an Enhancement-Point, in which case all
the implementations will be executed with no guarantee in the order of execution.
Enhancement Section:
When the Enhancement-Section is implemented, only the implementation gets executed
and the original code doesn’t get executed. This is a new technique, which didn’t exist previously in
any of the old ways of enhancing, to exclude any standard SAP code from execution. Because of this,
there can be only one active implementation of an Enhancement-Section.
Example:
Incase of explicit enhancement, we can add our enhancements at any place as per our
requirement.

Well in our case I don't have any standard program so I am using a Z program & enhancing the code.

Before starting an explicit enhancement, we have to create:


 One enhancement spot.
 In the enhancement spot we have to implement spot.
 All these tasks to be done under one package.
 So, I am creating one package in se80 first.

1. Right click & create Enhancement Spot.

2. Give the name of Enhancement Spot.

3. Now activate the enhancement spot.

4. Right click Enhancement Spots & implement it.


5. Activate the implementation, Go to SE38 & place the cursor where enhancement is required.

6. Enter Enhancement implementation name in Enhancement Spot name & Package name.
7. Now enhancement-point will come in your code with Grey Fonts.

8. Select Enhance

9. Place the cursor on enhancement-point & create enhancement.

10. Give enhancement Implementation name.


11. Place your code & activate.

12. Now run the program you will find the enhancement.

BADI – Business Add In: (Classes and Objects Enhancement)


A BADI is a point of extension that acts like a 'hook' where we can add custom codes. BADI is
the most sophisticated enhancement option since it is object-oriented.
BADI (Business Add-In) is a new SAP Object Oriented enhancement technique which is used
to add our own business functionality to the existing SAP standard functionality.
Why BADI?

In contrast to the earlier enhancement techniques, BADI follows Object Oriented approach
to make them reusable. A BADI can be used any number of times where as standard enhancement
techniques can be used only once.

For example, if we assign an enhancement to one custom project, then that enhancement
cannot be assigned to any other custom projects. To overcome this drawback SAP has provided a
new enhancement technique called BADI.

BADI T-Codes:

SE-18: BADI Definition.

SE-19: BADI Implementation.

Types of BADI's:
While creating a BADI using the T-code SE18, it provides the pop-up screen to select the type
of BADI to be used is as shown below.

There are two types of BADI's.

1. Multi use BADI:

With this option, any number of active implementations can be assigned to the same definition
BADI. By default, this option is checked.

If we want the BADI for multiple use

If you have multiple-use BADI definitions, the sequence must not play any role.

The drawback in Multiple use BADI is, it is not possible to know which BADI is active especially in
country specific version.

2. Filter dependent BADI:

Using this option, we can define the BADI's according to the filter values to control the add-in
implementation on specific criteria.

Ex: Specific country value.

How to Find BADI's in SAP system:

Method 1:

1. Go to SE 24 transaction, type CL_EXITHANDLER and then click on display.


2. Double click on GET_INSTANCE method.

3. Put a break-point on class method CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE.

4. Run any transaction on which we want find the BADI's say VA01.
5. Give the transaction name VA01 and press enter.
6. It will automatically take you to the break-point which we have set the in the SE24 transaction.
Each time if you press F8 a list BADI names will be displayed.

7. You can find the BADI name in field EXIT_NAME and if you double click on it, we can get the
corresponding BADI name before hit the corresponding screen. Based on the requirement find the
BADI name and accordingly implement your functionality using the transaction se19.

Method 2:

Go to transaction SE84 and click on Enhancements. Then double click on Business Add-Ins.

For example, if you want to find the BADI's for the standard transaction ME22n, the
procedure is as follows. This example shows, finding the way of BADI names by providing the
Package of ME22n.

1. Go to transaction ME22n. Select the System option from the menu and then click on Status.
It displays the following information.
2. Double click on the program name i.e. SAPLMEGUI. It will take you into the program and
click on Go to tab from the Menu. There we can find the package name of the standard
transaction ME22n.Copy and paste it in the package filed.

3. Now Press F8, a list of BADI names will be displayed as shown below. Select the appropriate
BADI name and implement it based on the business requirement using the transaction SE19.
Method 3:

Finding the BADI names using SE18 transaction

1. Go to transaction SE 18. Select F4 help for the definition name and click on Information
System button as shown below.

2. A pop-up screen will be displayed and give the package name for any standard transaction
say VA02. Finding the package is explained above. Please refer above method to find the
package name. The package name for VA02 transaction is 'VA.'
3. A list of BADI names will be displayed for the transaction VA02. Select the appropriate BADI
name and implement it using T-code SE19.

Example:

This Example explains how to implement BADI's. Here I am trying to show how to add custom
screen to the ME23N Transactions using BADI's.

The procedure is as explained below.

- Find the BADI using the method 1 as shown above.


The BADI name to add the custom screen to ME23n is 'ME_GUI_PO_CUST'.

- Go to T-code SE19 and create an implementation ZME_GUI_PO_CUST and then click on create
button

- Give the Definition name "ME_GUI_PO_CUST" and continue, give short text, save

- Click on Interface Tab, you can find the implementation class name as
ZCL_IM_ME_GUI_PO_CUST2.

- Click on ZCL_IM_ME_GUI_PO_CUST2, which will take you to SE24.

- Add "MMMFD" in the Type Group Section of properties tab.

- Go to Attributes section and declare the following attribute

- SUBSCREEN1 Constant Public Type MEPO_NAME Name of a View 'ITEMSCREEN1 '.

- Go to Methods section, you can find the BADI interface methods.


- Double click on the method "IF_EX_ME_GUI_PO_CUST~SUBSCRIBE", this method is having 3
parameters

Go to the code section of the method and add the following code there.

Code for IF_EX_ME_GUI_PO_CUST~SUBSCRIBE:

DATA: ls_subscriber LIKE LINE OF re_subscribers.

*--FIRST SCREEN POPULATION

*--we want to add a customer subscreen on the item detail tab

CHECK im_application = 'PO'.

CHECK im_element = 'ITEM'.

*--each line in re_subscribers generates a subscreen. We add one subscreen

*--in this example

CLEAR re_subscribers[].

*--the name is a unique identifier for the subscreen and defined in this

*--class definition

ls_subscriber-name = subscreen1.

*--the dynpro number to use

ls_subscriber-dynpro = '0002'.

*--the program where the dynpro can be found

ls_subscriber-program = 'ZME_GUI_PO_CUST_SCREEN'.

*--each subscreen needs itsown DDIC-Structure

ls_subscriber-struct_name = 'ZMARA'.
*--a label can be defined

ls_subscriber-label = 'Cust BADI'.

*--the position within the tabstrib can be defined

ls_subscriber-position = 7.

*--the height of the screen can be defined here. Currently we support two

*--screen sizes:

*--value <= 7 a sevel line subscreen

*--value > 7 a 16 line subscreen

ls_subscriber-height = 7.

APPEND ls_subscriber TO re_subscribers.

*--Save and check and back

*--Double click on method IF_EX_ME_GUI_PO_CUST~MAP_DYNPRO_FIELDS.

*--Add the following code in the method.

*given the field catalog of structure ZMARA we have to

*establish a mapping to metafields which are used for field selection

*purposes and error handling Standard definitions can be found in type

*pool MMMFD. It is important for customer fields to use integer

*constants above 90000000 for the metafield.

FIELD-SYMBOLS: <mapping> LIKE LINE OF ch_mapping.

LOOP AT ch_mapping ASSIGNING <mapping>.

CASE <mapping>-fieldname.

WHEN 'MATNR'. <mapping>-metafield = mmmfd_cust_08.

WHEN 'MTART'. <mapping>-metafield = mmmfd_cust_09.

WHEN 'MATKL'. <mapping>-metafield = mmmfd_cust_10.

ENDCASE.

ENDLOOP.

 The metafield mapping important for field selection and error handling purpose.
 Save, check and back
 Activate the Implementation class.
 Activate the BADI Implementation.

Now create a structure in SE11 with the name ZMARA.

Add the following fields in the structure.


Now Create a Program with the Name 'ZME_GUI_PO_CUST_SCREEN' and create a screen with sub
screen type with the number 0002.

Add the fields on to screen from ZMARA program 'ZME_GUI_PO_CUST_SCREEN'.


**

De comment the PBO module in screen flow logic and create the module in above program.

Add the following code in program ZME_GUI_PO_CUST_SCREEN.

TABLES: ZMARA.

DATA: call_subscreen TYPE sy-dynnr,

call_prog TYPE sy-repid,

call_view TYPE REF TO cl_screen_view_mm,

call_view_stack TYPE REF TO cl_screen_view_mm OCCURS 0.

*---------------------------------------------------------------------*

* FORM SET_SUBSCREEN_AND_PROG *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

* --> DYNNR *

* --> PROG *

* --> VIEW *

* --> TO *

* --> CL_SCREEN_VIEW_MM *

*---------------------------------------------------------------------*

FORM set_subscreen_and_prog USING dynnr TYPE sy-dynnr


prog TYPE sy-repid

view TYPE REF TO cl_screen_view_mm.

call_subscreen = dynnr.

call_prog = prog.

call_view = view.

ENDFORM.

*&---------------------------------------------------------------------*

*& Module STATUS_0002 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE STATUS_0002 OUTPUT.

SELECT SINGLE * FROM MARA

INTO CORRESPONDING FIELDS OF ZMARA

WHERE MATNR = '100-100'.

ENDMODULE. " STATUS_0002 OUTPUT .

 The sub-routine "set_subscreen_and_prog" is must with the same signature.


 This routine is called from BADI to call the sub screen.
 Activate the screen & program.
 Now Go to T-Code ME23N to test the application.
 You can find a new tab is added in the item level with the name CUST BADI.
Final Output:

You might also like