Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

User Exit for

Former Member
0 Kudos

Can anyone send some examples on code written in includes of user exits with respect to any one transaction also.

Thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sunil,

There is no special way to write code in a FM user exit. You can write code the way you write in a FM.

You can use the import/export parameters of that FM which are avialable, you cannot add new parameters.

You need to activate the enhancement through SMOD only then that FM will get triggered through the program.

Regards,

Pankaj Sharma

6 REPLIES 6

Former Member
0 Kudos

Hi,

Create A project first in CMOD by entering the Enhancment. Save and activate.

Go to that fun module, double click on the Include, it will ask to create it or not.Say yes.

SO you will be take to the source code.

Check the Importing paramters/tables. Use those structrues/fields in those structures to fetch further data from other tables and write the code and populate the fetched data into the Exporting parameters/tables.

reward if useful

regards,A

nji

Former Member
0 Kudos

Sunil,

Step by Step user exits.

User exits

1. Introduction

2. How to find user exits

3. Using Project management of SAP Enhancements

1. Introduction

User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to

a functionmodule. The code for the function module is writeen 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.

The naming standard of function modules for functionmodule exits is: EXIT_<program name><3

digit suffix>

The call to a functionmodule exit is implemented as: CALL CUSTOMER.-FUNCTION ❤️ digit suffix>

Example:

The program for transaction VA01 Create salesorder is SAPMV45A

If you search for CALL CUSTOMER-FUNCTION i program SAPMV45A you will find ( Among other user

exits):

CALL CUSTOMER-FUNCTION '003'

exporting

xvbak = vbak

xvbuk = vbuk

xkomk = tkomk

importing

lvf_subrc = lvf_subrc

tables

xvbfa = xvbfa

xvbap = xvbap

xvbup = xvbup.

The exit calls function module EXIT_SAPMV45A_003

2. How to find user exits

Display the program where you are searching for and exit and search for CALL CUSTOMER-EXIT

If you know the Exit name, go to transaction CMOD. Choose menu Utillities->SAP Enhancements.

Enter the exit name and press enter.

You will now come to a screen that shows the function module exits for the exit.

3. Using Project management of SAP Enhancements

We want to create a project to enahance trasnaction VA01

Go to transaction CMOD

Create a project called ZVA01

Choose the Enhancement assign radio button and press the Change button

In the first column enter V45A0002 Predefine sold-to party in sales document . Note that an

enhancement can only be used i 1 project. If the enhancement is allready in use, and error message

will be displayed

Press Save

Press Components. You can now see that enhancement uses user exit EXIT_SAPMV45A_002.

Double click on the exit.

Now the function module is displayed. Double click on include ZXVVAU04 in the function module

Insert the following code into the include: E_KUNNR = '2155'.

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

Goto transaction VA01 and craete a salesorder. Note that Sold-to-party now automatically is "2155" .

A Short Tutorial on User Exits

Content Author: Abhishek

User exits :

1. Introduction

2. How to find user exits

3. Using Project management of SAP Enhancements

1. Introduction:

User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to a functionmodule. The code for the function module is writeen 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.

The naming standard of function modules for functionmodule exits is:

EXIT_<program name><3 digit suffix>

The call to a functionmodule exit is implemented as:

CALL CUSTOMER.-FUNCTION ❤️ digit suffix>

Example:

The program for transaction VA01 Create salesorder is SAPMV45A

If you search for CALL CUSTOMER-FUNCTION i program

SAPMV45A you will find ( Among other user exits):

CALL CUSTOMER-FUNCTION '003'

exporting

xvbak = vbak

xvbuk = vbuk

xkomk = tkomk

importing

lvf_subrc = lvf_subrc

tables

xvbfa = xvbfa

xvbap = xvbap

xvbup = xvbup.

The exit calls function module EXIT_SAPMV45A_003

2. How to find user exits?

Display the program where you are searching for and exit and search for CALL CUSTOMER-EXIT

If you know the Exit name, go to transaction CMOD.

Choose menu Utillities->SAP Enhancements. Enter the exit name and press enter.

You will now come to a screen that shows the function module exits for the exit.

3. Using Project management of SAP Enhancements, we want to create a project to enahance trasnaction VA01 .

- Go to transaction CMOD

- Create a project called ZVA01

- Choose the Enhancement assign radio button and press the Change button

In the first column enter V45A0002 Predefine sold-to party in sales document.

Note that an enhancement can only be used in 1 project. If the enhancement is already in use, and error message will be displayed

Press Save

Press Components. You can now see that enhancement uses user exit EXIT_SAPMV45A_002. Double click on the exit.

Now the function module is displayed. Double click on include ZXVVAU04 in the function module

Insert the following code into the include: E_KUNNR = '2155'.

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

Goto transaction VA01 and craete a salesorder.

Note that Sold-to-party now automatically is "2155"

What is User Exits and Customer Exits?

Difference between user exits & customer exits:

User exit - A user exit is a three character code that instructs the system to access a program during system processing.

SXX: S is for standard exits that are delivered by SAP. XX represents the 2-digit exit number.

UXX: U is for user exits that are defined by the user. XX represents the 2-digit exit number

Customer exit - The R/3 enhancement concept allows you to add your own functionality to SAP’s standard business applications without having to modify the original applications. SAP creates customer exits for specific programs, screens, and menus within standard R/3 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. *-- Mani

The following document is about exits in SAP :-

The R/3 enhancement concept allows you to add your own functionality to SAP’s standard business applications without having to modify the original applications.

SAP creates user exits for specific programs, screens, and menus within standard R/3 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.

Types of Exits

There are several different types of user exits. Each of these exits acts as hooks where you can attach or "hang" your own add-ons.

Menu Exits

Menu exits add items to the pulldown menus in standard SAP applications. You can use these menu items to call up your own screens or to trigger entire add-on applications.

SAP creates menu exits by defining special menu items in the Menu Painter. These special entries have function codes that begin with "+" (a plus sign). You specify the menu item’s text when activating the item in an add-on project.

Screen Exits

Screen exits add fields to screens in R/3 applications. SAP creates screen exits by placing special subscreen areas on a standard R/3 screen and calling a customer subscreen from the standard screen’s flow logic.

Function Module Exits

Function module exits add functions to R/3 applications. Function module exits play a role in both menu and screen exits.

When you add a new menu item to a standard pull down menu, you use a function module exit to define the actions that should take place once your menu is activated.

Function module exits also control the data flow between standard programs and screen exit fields. SAP application developers create function module exits by writing calls to customer functions into the source code of standard R/3 programs.

These calls have the following syntax:

CALL CUSTOMER-FUNCTION ‘001’.

Field Exits

Field exits allow you to create your own programming logic for any data element in the Dictionary. You can use this logic to carry out checks, conversions, or business-related processing for any screen field. Example: The data element BBBNR identifies a company’s international location number. You might want to set up your R/3 System so that all international location numbers are larger than 100.

The field exit concept lets you create a special function module that contains this logic.

You assign the special function module to the data element BBBNR. You then assign the module to any programs and screens in which users can add new international location numbers. When you activate your field exit, the system automatically triggers your special routine whenever a user enters a company location number.

In 4.6c, you can use "RSMODPRF" program to create field exits.

An example of a user exits :-

MODULE user_exit_0001 INPUT

CASE okcode.

WHEN 'BACK OR EXIT'.

CASE sy-dynnr.

WHEN '100'.

SET SCREEN 0.

LEAVE SCREEN.

WHEN '200'.

        • Note that you can write any code that satisfy your needs. ****

        • But in this case, this was wrote as a sample code for reference sake. ****

        • And you can test it. ****

SET SCREEN 100.

LEAVE SCREEN.

ENDCASE.

ENDCASE.

Don't forget to reward if useful...

Former Member
0 Kudos

hi,

for tcode: FSPO

*&---------------------------------------------------------------------*
*&  Include           ZXF03U01
*&---------------------------------------------------------------------*

** This customer exit used to resolve the error in the
** SAP standard transaction.
** SAP Transaction is 'FSP0'.
** Issue description: If there is an error in the FSP0 transaction process
** like ' The entries in not available in TF100 table.
** Then If user clicks 'CANCEL' button, the Pop-up message will be
** Polulated with YES or NO button for SAVE option.
** By mistake user click 'YES' option, the invalid data gets stored in
** SAP table through FSP0 transaction.
** It should be eliminated.

  data: w_tf100 like tf100.

*** This is only Applicable for 'FSP0' transaction only.

  IF sy-tcode = 'FSP0'.

* IF ktoplaccount-KTOPL = 'ALL1'.

    if ktoplaccount-SAKNR is not initial.
** The below logic added to exclude exclude S, L and R accts.
      if ktoplaccount-SAKNR+0(4) = 'LIFE' OR
         ktoplaccount-SAKNR+0(4) = 'STAT' OR
         ktoplaccount-SAKNR+0(4) = 'REIN'.

      else.
        select single * from TF100 into w_tf100
        where ITEM = ktoplaccount-SAKNR.

        if syst-subrc ne 0.
          SET SCREEN 0.
          LEAVE SCREEN.
        endif.
      endif.
    endif.
* endif.
  ENDIF.

regards,

pankaj singh

        • please dont forget to give points if helpful

Former Member
0 Kudos

hi sunil

take va01 for example

for this ,one of the exits is V45A0001, in this put a break point for the zinclude

FUNCTION EXIT_SAPFV45S_001.

*"----


""Lokale Schnittstelle:

*" IMPORTING

*" VALUE(REQUESTED_DELIVERY_DATE) LIKE VBAK-VDATU

*" VALUE(ENTERED_MATERIAL) LIKE VBAP-MATNR

*" VALUE(REQUESTED_DELIVERY_QUANTITY) LIKE VBAP-KWMENG

*" VALUE(SALES_UNIT) LIKE VBAP-VRKME OPTIONAL

*" VALUE(DELIVERED_QUANTITY) LIKE VBAP-KLMENG OPTIONAL

*" VALUE(DELIVERING_PLANT) LIKE VBAP-WERKS OPTIONAL

*" VALUE(STORAGE_LOCATION) LIKE VBAP-LGORT OPTIONAL

*" EXPORTING

*" VALUE(CONFIRMED_QUANTITY_MAIN_ITEM) LIKE VBEP-BMENG

*" TABLES

*" ALTERNATIVE_MATERIALS STRUCTURE STPOX

*" EXCEPTIONS

*" NO_ALTERNATIVES_FOUND

*"----


INCLUDE ZXVVAU02. " Put a break point here

ENDFUNCTION.

now when you are using the tcode VA01 see where exactly the application is going into debugging mode.this way you will come to know which user exit is triggering where and according to the requirement you can add your piece of code in the respective user exit.

and the fields which vary inside this include are the importing and exporting parameters which you are cing above inside Function endfunction .

Kindly reward points if helpful.

Regards

zarina

Former Member
0 Kudos

Hi Sunil,

There is no special way to write code in a FM user exit. You can write code the way you write in a FM.

You can use the import/export parameters of that FM which are avialable, you cannot add new parameters.

You need to activate the enhancement through SMOD only then that FM will get triggered through the program.

Regards,

Pankaj Sharma

Former Member
0 Kudos

Hi Sunil,

This example code is based on enhancement SUSR0001.This enhancement uses function exit EXIT_SAPLSUSF_001 .

Enhancement : SUSR0001 User Exit after logon to SAP system.

When the User logs in the system, this exit is called each and every time for every user after logon to the R/3 system.

Function Exit : EXIT_SAPLSUSF_001 .

Every dialog user passes through this function module after logon, It can be used to execute individual customer checks and send messages to the user.

TABLE USR02 CONTAINS LOGON DATA and can be used in this exit to get the user logon data and take necessary actions as required by the customer requirement and even LOG_OFF (not recommended by SAP).

STEPS REQUIRED FOR IMPLEMETING THE EXIT

1) Open CMOD(Project maintenance) Transaction. Enter a project name starting with Z. Press enter.

2) Goto Enhancement window by clicking the enhancement button in the application tool bar.

3) Write SUSR0001 in the enhancement column and press enter.

4) Goto Components window (It will show all the exits included in this enhancement), in our case only one Function Exit will be shown.

5) Double click on the Function exit EXIT_SAPLSUSF_001.

The following function source code will be displayed in the function editor

FUNCTION EXIT_SAPLSUSF_001.

*"----


""Lokale Schnittstelle:

*"----


INCLUDE ZXUSRU01.

ENDFUNCTION.

6) Double click on the include ZXUSRU01 .If it will ask to create the include say yes .

7)Write the following code in the include.

DATA W_TEXT(30) TYPE C.

DATA W_DATE(10) TYPE C.

WRITE sy-datum TO W_DATE DD/MM/YYYY.

CONCATENATE ' Date is ' W_DATE INTO W_TEXT.

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

title = 'Welcome to Paradise !'

txt1 = 'Have A Nice Day'

txt2 = W_TEXT

  • TXT3 = ' '

  • TXT4 = ' '

8)Save the include and activate it .Activate the Project also by going to the menu in CMOD transaction. Now The user exit SUSR0001 has been implemented and is ready to use.

9) Logon to the R/3 system . A dialog box will appear with the message

Welcome to Paradise ! with date .

NOTE: BAPIs like BAPI_USER_GET_DETAIL can also be used to get user info or directly read from tables USR02 etc.

Hope this resolves your query.

Reward all the helpful answers.

Regards