enhancement new

33
How to Guide for Enhancements NAME DESIGNATION Manish Verma Associate Consultant

Upload: vishal-godase

Post on 24-Jul-2015

53 views

Category:

Documents


3 download

DESCRIPTION

SAP ENHANCEMENT GUIDE

TRANSCRIPT

Page 1: Enhancement New

How to Guide for

Enhancements

NAME DESIGNATION

Manish Verma Associate Consultant

Page 2: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 2 of 33

REVISION HISTORY

Doc

Ver. #

Date

Prepared/Changed

By

Reviewed

By

Authorized by

Description

1.0 27.03.2012 Hari Prasad Vinod Kumar G.R Baselined

Page 3: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 3 of 33

Contents

1 Purpose ......................................................................................................... 4

2 Scope: ............................................................................................................ 4

3 Prerequisites ................................................................................................. 4

4 Introduction ................................................................................................... 4

5 Types of Enhancement. ................................................................................ 4

5.1 User Exit ......................................................................................................................... 4

5.2 Customer Exits: .............................................................................................................. 9

5.3 Business Add-Ins (BADI) .............................................................................................. 25

Page 4: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 4 of 33

1 Purpose

The purpose of this guide is to understand the enhancement concept that can be used to add the custom features inside the standard SAP programs.

2 Scope:

This document explains that how to find the Enhancement and how to implement that enhancement for custom use.

3 Prerequisites

Before using this document, the respective consultant should be aware of the include programs, function module and the ABAP OOPS concepts and also some knowledge of module pool.

4 Introduction

Enhancement is a way provided by the SAP using which we can provide the additional functionality to the standard SAP programs.

In other way we can say that enhancements are like the hooks in the standard program where we can attach our own code to provide the additional functionality.

Note:

We should always remember one thing that, enhancements are never referred to as a modification, i.e. it never alters the flow of the standard program. That's why we should never write such a code during the enhancements that can alter the flow of the standard program.

5 Types of Enhancement.

There are various types of enhancement technique that is provided by the SAP:

User Exit

Customer exit

Business Add-Ins(BADI)

Let‟s discuss all one by one:

5.1 User Exit

User exits allow us to add our own functionality to SAP standard program without modifying it.

Page 5: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 5 of 33

These are implemented in the form of subroutines and hence are also known as FORM EXITs. And these routines will be available in some include of the standard program that generally ends with the letter 'ZZ'(Eg MV45AFZZ).

The user exits are generally collected in includes and attached to the standard program by the SAP.

All User exit starts with the world “USEREXIT…….”

We generally write our all code in a include that will be present in the routine and will start with the letter 'Z'

Eg:

Form Userexit_..

Include ZXXXXXX.

EndForm.

The problem that lies here is in finding the correct userexit and how to find it if one exists for the required

purpose. Once the correct userexit is found the necessary customer code is inserted in the customer

include starting with the z.. in the form routine.

5.1.1. HOW TO FIND USEREXITS

There are number of ways to find the user exits

a) One way is find the program name of your transaction and go to the SE38 transaction and look for the word userexit. (using Find option - ctrl+f)

b) The other method of finding userexits is to find the include in case of SD/MM applications where the userexits are located, this can be found in the SAP reference IMG generally in the sub folder under SYSTEM MODIFICATION.(use Transaction SPRO)

Eg:

Go to SPRO transaction and click on the following options.

Page 6: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 6 of 33

Then using the following hierarchy you can get the user exit for the sales and distributions applications.

Each exit is provided with well documentation, using that you can find the one which will be suitable for your requirement.

c) To find userexits in SD module, go to object navigator (SE80) and select Package from the list and enter VMOD in it. All of the userexits in SD are contained in the development class VMOD.

Press enter and you will find all the includes which contain userexits in SD for different functions like PRICING, ORDER PROCESSING etc. Select the userexit according to the requirement and read the comment inserted in it and start coding.

E.g.

Let's take a scenario to add a validation in sale order creation (Tcode VA01), so that the quantity field for the line item should not be less than 2 units

Page 7: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 7 of 33

Go to the SE80 and select package and enter the VMOD.

Now you can see all the user exit available for the SD.(But you can modify only those subroutine which is already implemented or you have the access key to modify the routine)

In our case we have to implement the MV45AFZZ which have already a z….. include in the routine so we dont need the access key . So we can write our code there.

As we can see that there is a include ZMV45AFZZ_SAVE_DOCUMENT_PREP. So double click on the include and write the following code there.

data: lv_flag(1) type c.

Page 8: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 8 of 33

* exit if not SAVE if sy-ucomm ne „SICH‟. leave to screen sy-dynnr. endif.

* check line items clear lv_flag. loop at xvbap where updkz ne „D‟. * This checks for quantity less than 2 * As xvbap-kwmeng is pack with 3 decimal we are comparing with 2000 if xvbap-kwmeng < 2000. message i000(fb) with „quantity is less than 2′. lv_flag = „X‟. clear sy-ucomm. exit. endif. endloop.

if lv_flag = „X‟. leave to screen sy-dynnr. endif.

Now start the transaction VA01 and create a sales document and give the value in the quantity field less than 2.(you will get the message as following, if everything is fine)

Page 9: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 9 of 33

Note:

Certain application like Sales and distribution (SD) still provide this form of enhancement using userexit but this practice is no longer being followed for newer extensions.

There is a disadvantage with the user exit that user have the access of all global data(tables, structures, and so forth) of the program and can modify them ,that can alter the flow of the standard program and may lead to errors in further process.

And another disadvantage in the user exit is that, it requires the access key to implement the routines.

And also if you want to deactivate your changes then you have to navigate to the code and you have to delete or comment your code. (To overcome these disadvantages SAP came up with a new concept called Customer exit)

5.2 Customer Exits:

Customer exits are “hooks” provided by SAP within many standard programs, on which customers may “hang” custom functionality (Their own code) to meet the specific business requirements.

Or you can say that Customer exits are possibilities offered by SAP at strategic moments to call customer ABAP code so that we can enhance the standard.

These exits are function modules called by SAP, with fixed input and output parameters, and only containing an INCLUDE ZX... ABAP statement, which the client may create.

There are three main types of customer exits:

1. Function Module Exits 2. Screen Exits 3. Menu exits

1: Function Module Exit

It allows customer to add code via a function module at a specific location in an SAP application program

Syntax: CALL CUSTOMER-FUNCTION ‟004′

2: Menu Exit

Page 10: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 10 of 33

It allows customer to add items to a pulldown menu in a standard SAP program. These items may be used to call add-on programs or custom screens.

Format: +CUS (additional item in GUI status )

3 : Screen Exit:

It allows customer to add fields to a screen in an SAP program via a subscreen. The subscreen is called within the standard screen‟s flow logic.

Format: CALL CUSTOMER-SUBSCREEN CUSTSCR2

5.2.1 How to find an exit:

Main point in Customer exits is that how to find the Function module where you can write your own code.

Before we go to find the customer exit function module we should know that in the main program we call the function module using the following statement:

CALL CUSTOMER-FUNCTION ’XXX′

Here XXX is the three digit code. And the function module that will be called using this statement will be of following format:

'EXIT_YYYYYYY_XXX'

Here YYYYYYY is the program name that is calling the function module and XXX is the three digit code same as in call function call statement.

There are some approaches to find the appropriate customer exit is following:

5.2.1.1: Using Debugger

This is the best approach to find the customer exit.

Start the transaction in which you want to find out the exit.

Before executing the transaction, start the dynamic debugger using '/h' .

Now go to the debugger options 'breakpoint at statement' and set the break point at statement 'Call Customer Function '.

Now use the f8 and your program flow will stop at the each exit that are the available for this transaction.

Page 11: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 11 of 33

Find out the appropriate exit for your requirement by looking the import and export parameter of the function module.( later discussed in example )

5.2.1.2: Using report

This is another approach to find the exit for your requirement.

First find out the report that belongs to your transaction, for this use the following steps.(SystemStatus, there you can find the program of your transaction)

Now you have the report name, so go to the report and look for the 'CALL CUSTOMER-FUNCTION' statement .For this purpose use the find option that is available in the report.(ctrl+f)

It will list all the exit function module , So now you can find the appropriate function module by looking the import and export parameter.

Eg:

Suppose you want to see the exits that are available for the transaction VA01.

Go to the tcode VA01 then in menu select systemstatus.

Page 12: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 12 of 33

Get the program name and go to the program.

Click on the search option and give the "call customer-function" statement.

Page 13: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 13 of 33

So following are the customer exit that are available in your program.

5.2.1.3: Using SMOD

The SMOD transaction contains the actual enhancements (i.e a 8 digit code).

Using the tcode SMOD you can find user exit by following steps:

Go to the tcode SMOD .

Press f4 help and provide the package name of your transaction(that you can find in SE93 transaction).

Then it will display list of all the available enhancements.

Once you find the enhancement, you can get the function module related to that enhancement.

Eg:

Suppose you want to see the user exits that are available for the transaction VA01

Go to the tcode SE93 and give the your tcode.

Page 14: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 14 of 33

Get the package name.

Go to the tcode SMOD. Click on Utilities find

Page 15: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 15 of 33

Provide the package name and execute.

So we can identify the user-exits by matching the first 4 letters of each user-exit name with the last four letters of the program name.

In our case program name is “SAPMV454″ .

So in the following list we can see that there are 4 exits available for us that are starting with " V454".

Page 16: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 16 of 33

5.2.2 How to implement an exit:

Following are the steps that we have to follow:

First find out the customer exit by using any of the above described methods.

Go to the CMOD and create a project.

Go to the enhancement option and give the enhancement code that contain the user exit(enhancement code you can get from the SMOD transaction)

Note: These enhancements can only be used in 1 project.

Go to the Components screen (where the available customer exits are displayed).

Choose your function module and implement the include present in that, for that you need to provide the package and transport request.

Activate the include program. Go back to CMOD and activate the project.

5.2.2.1 E.g.:

Let's take a scenario to add a validation in sales order creation (Tcode VA01), so that the quantity field for the line item should not be less than 2 units.

Page 17: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 17 of 33

Go to the transaction VA01 and get the technical information of the quantity field.

By pressing F1 key after placing cursor on that field and then clicking on following icon.

After this you will see the complete detail of the field(here field element is "KWMENG" that is used in VBAP table)

So we need to look in the VBAP table. Now start the debugger and set the break point at statement "call customer-function" as following.

Page 18: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 18 of 33

Following window will appear

Now break point will be set at all customer exit .here we will get a 'call function 003' which has the VBAP table as parameter. So we can use it for our requirment.

Now go to SMOD transaction and get the enhancement code which is' V45A0003' in our case.

Now go to CMOD transaction and create a project. Give the sort text and click the option 'enhancement assignments' and provide the enhancement code.

Click on the components and duble click on the function module

Page 19: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 19 of 33

It will redirect you to function module. There is an include in which you write your code and activate the include and the project and run the VA01 transaction again and give the quantity less than 2 you will see the following message.

Page 20: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 20 of 33

5.2.2.2 E.g.

Before going to implement the screen exit we should know the following things :

We can find the screen exit using SMOD transaction by selecting the Screen exit option.

Along with the screen exit we also need the table exit , using that we will add the field in table also that we want to be added in the screen.

And also we need two function modules , one to fetch the data from the screen(it will be called in PBO) and another to display the data in the screen field(it will be called inPAI)

All these function modules and table exit will be available in the component list of the screen enhancement.

Let's take a scenario for the screen exit, in which we want to add a field in item level data in the transaction ME22N.

First find the screen exit from the above method in our case it is MM06E005.

Page 21: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 21 of 33

Now go to the transaction CMOD and enter a project name.

Click on Create and give the short description and click on the enhancement and give the enhancement code .

Now click on the component and you will see the following list .

It will show the Function EXITs, Screen EXITs and few includes for the table.

You can use the following table include to add your field in the table.(it will redirect you to se11).

Page 22: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 22 of 33

Add your field here and activate it(it may take some extra time)

As we have seen that there are many screen exit but each have different screen no.(here 0101 is for the header and 0111 is for the item detail )

Because we need to add the field in the item detail, click on the 0111 screen and it will redirect you to the SE51. So add you field there(in our case 'potype').

For this provide the label and click on the button Dict./Program fields(or press f6).

Page 23: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 23 of 33

Following window will appear give the 'EKPO_CI-POTYPE' in the table field option.(EKPO_CI table, POTYPE field)

After this we need to implement the two function modules

1. EXIT_SAPMM06E_016: To get the value from the screen field.

2. EXIT_SAPMM06E_018: To set the value to the screen field.

For the example purpose, put the following line of code in EXIT_SAPMM06E_016.

EKPO_CI-ZZPOTYP = „ABCD‟.

Save your project and start the transaction, you will see your custom field there(in the Customer Data Tab).

Page 24: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 24 of 33

Note:

Customer exits have several advantages over user exits as follows :

It is more restricted than user exit , means that the Data variable that a user can use is fixed by the SAP in the form of importing and exporting parameters.

By deactivating the project you can deactivate your changes, no need to remove or comment your code.

Access key is not required for enhancement.

Still there are some disadvantage in the customer exits like :

All users have to use the same function module.

Page 25: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 25 of 33

One enhancement can be used by only one project.(so to overcome this SAP comes with a new concept Business Add-Ins(BADI) which is based on the OOPS concepts)

5.3 Business Add-Ins (BADI)

BADI are the enhancement technique to the standard Transaction, which is based on the OOPS. 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.

BADI supports the multilevel system landscape (SAP, country-specific versions, industry solutions, partner, customer, and so on). You can create definitions and implementations of BADI at any level of the system landscape.

There are three types of BADI:

1. Single Instance

2. Multiple Instance

3. Filter BADI

Single Instance: For single instance there will be only one implementation for given BADI. And also we need the access key to implement the BADI.

Multiple Instances: For multiple instance we can provide more than one implementation and each will be executed one after the other. And execution order can be in any sequence.

Filter BADI: In filter BADI we provide a filter condition. For filter BADI there will be multiple implementations but among them only few will be executed according the filter condition.

You can identify you BADI type using SE18 Transaction .

Go to the Tcode SE18 and provide the BADI name and click on display.

Page 26: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 26 of 33

Here you can see the following option.

NOTE:

Each BADI have one interface and one adapter class.

We implement the interface and add custom code in the implementation of the interface method.

Whereas adapter class is created by the enhancement management, which have the following task:

Control:The adapter class calls the active implementations.

Filtering:If a Business Add-In is to be executed only under certain conditions, the adapter class ensures that only certain implementations will be executed.

(The adapter class method generated by add-in management decides if one or several active implementations should be called. If necessary, these implementations are subsequently executed. The application program ensures only that the adapter class method is called. The application program does not know which implementations are called.)

5.3.1 How to find the BADI:

Using CL_EXITHANDLER class:

Run your transaction for which you want to find the BADI. Start the debugger using '/h'. Put the break point at method GET_INSTANCE or GET_CLASS_NAME_BY_INTERFACE of class

CL_EXITHANDLER. Use f8 it will stop at each BADI and you can get BADI name in EXIT_NAME parameter of the method.

Page 27: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 27 of 33

Using SE84:

Go to the transaction SE84. Follow the following steps (Repository information systemenhancementdefinitions) Provide the package name and the list of all BADI will appear.

E.g. Suppose you want the BADI for VA01 transaction we know that package name is 'VA'.

Go to the TCODE SE84 and follow the following steps(Repository information systemenhancementdefinitions)

Now provide the package name and execute it.

Page 28: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 28 of 33

Following list will come with all available BADI.Select your BADI and impliment it in SE19.

Using SE18: In the same way as privious

Go to the SE18 and press f4 after selecting the BADI name radio button. Provide the package name and execute. You will get list of all BADI(if selection popup is not

coming then click on the NEW SELECTION)

5.3.3 How to impmliment a BADI

First find the your BADI using above methods.

Go to the transaction SE19 and provide the BADI name and click on the implementation.

Page 29: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 29 of 33

It will ask for the implimentation name give the implementationm name.

A class will created with the interface .

Select interface tab, select the your method and implement that.

Come back and activate the implementation .

Page 30: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 30 of 33

E.g. Let's take scenario that display an information message while user create a material for Material Group is 03.

First we need to find the BADI name, for this start the transaction MM10 and start the debugger. And navigate to the following steps.

Page 31: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 31 of 33

Now enter the class as CL_EXITHANDLER and method as GET_INSTANCE.

Press f8 check the method parameter exit_name, you will find a BADI with name BADI_MATERIAL_CHECK.

Go to the transaction se19 and provide the BADI name and click on implementation.

provide the implementation name.And press continue .

Page 32: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 32 of 33

Give the sort description ,and go to the interface tab and click on the method CHECK_DATA.

It will ask for the package name, give the package name and write the following code there.

Page 33: Enhancement New

Document No: PEOL/HWT/001 Ver: 1.0 Date of Creation

HOW TO GUIDE PROPRIETARY & CONFIDENTIAL

© PEOL – Expeditious Business Solutions, 2012

Page 33 of 33

Activate the method, come back and activate the implementation.

Now to see your changes go to the transaction and create the Material for Material Group is 03.