Application Development and Automation 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: 
Read only

User Exit

Former Member
0 Likes
2,520

Does anyone have any documents.. how to guides etc about how to write a User Exit for an incoming IDoc.

Basically there are a few fields that will need to be populated upon the IDoc coming into the System and before it is saved... so we want to have a user exit to do this...

3 REPLIES 3
Read only

Former Member
0 Likes
1,257

Following is about User Exits Documentation

Strategic Location of User Exits

User exits are available at strategic points in the IDoc programs to handle customer extensions. SAP controls these locations, and they are guaranteed to exist with the same functionality on an upgrade. An explanation of the commonly used user exits for outbound as well as inbound processing follows. Note that some of these may not be available for every process and some processes may have additional user exits.

Outbound IDoc Processing

• A user exit is available after each segment is populated. This exit allows you to add custom logic for any of your extended segments. Technically, the same user exit is invoked after every segment is filled. Therefore, in your user exit program you must check the name of the current segment being processed.

• A user exit is also available after the system populates the control record information. This exit allows you to modify any control information that may be necessary. For example, if you have extended an IDoc, you will populate the IDoc type using this user exit. This user exit lends itself to creativity. For example, you can use it to create a variant of your message type to allow special processing or to determine recipients dynamically.

• A user exit is also available after the system has completely filled out the control record and data records. This exit allows you to make any final adjustments to the data being sent out.

Inbound IDoc Processing

• A user exit is available when a customer segment is encountered. This exit allows you to add custom logic for any of your extended segments.

• A user exit is also available after the system populates the status records and is about to return control back to the ALE layer. This exit allows you to modify any status records or add additional status records.

Common Process

• A user exit is located in the routine that creates a physical IDoc in the system. Technically, the exit is called in the EDI_DOCUMENT_OPEN_FOR_CREATE function module, which creates a control record. This user exit is invoked for inbound as well as outbound IDocs. It can be used to modify control record information in the IDoc. This exit is typically used to make global changes to your IDocs. For example, you could modify the control record on outbound IDocs for any specific information desired by your EDI subsystem. This user exit (EXIT_SAPLEDI1_001) is implemented in enhancement SIDOC001.

• Another user exit is available in the ALE service layer during version change of incoming and outgoing IDocs. The exit is not especially valuable on outbound, because the system takes care of the version change. On the other hand, on inbound, for example, if you are on 3.0F and you are receiving IDocs from a back-level system 3.0A, then you could modify the segment to include additional fields that may be required in the application for 3.0F. This user exit (EXIT_SAPLBD11_001) is implemented in enhancement ALE00001.

Steps to Locate User Exits

The first and foremost task before you can start programming is to identify the specific user exit that you should use. User exits in the system are grouped under enhancements. Refer to the appendix for a list of enhancements for the commonly used IDoc programs. If you do not know the enhancement, the steps are listed later in "Determining SAP Enhancements." After you identify the correct enhancement, finding the appropriate user exit is very simple, as described in the following steps:

1. Execute transaction SMOD.

2. Enter your enhancement name and click on the Components button.

3. Click on Display to see the various components that are effectively user exits. Click on any one and then click on the Documentation button to view the documentation. If no documentation is available, then you are at the mercy of documentation in the SAP code to determine the intent behind the user exit.

Following is the sample code for User Exits

----


  • INCLUDE ZXVSVU02 *

----


  • In this scenario, data in the Z1KNVVM segment is read and processed.

  • This user exit is called after the system has already updated the

  • customer master. Therefore data is updated in the SAP tables directly

----


TABLES: KNVV.

DATA: KNVVM LIKE E1KNVVM,

KNA1M LIKE E1KNA1M,

Z1KNVVM LIKE Z1KNVVM.

LOOP AT IDOC_DATA. " loop through all data records

CASE IDOC_DATA-SEGNAM.

WHEN 'E1KNA1M'. " has customer number in it

KNA1M = IDOC_DATA-SDATA.

WHEN 'E1KNVVM'. " has sales org dist ch and division

KNVVM = IDOC_DATA-SDATA.

WHEN 'Z1KNVVM'. " has custom data

Z1KNVVM = IDOC_DATA-SDATA.

  • Always a good idea to make sure we have a valid customer number

SELECT SINGLE * FROM KNVV WHERE KUNNR = KNA1M-KUNNR

AND VKORG = KNVVM-VKORG

AND VTWEG = KNVVM-VTWEG

AND SPART = KNVVM-SPART.

IF SY-SUBRC EQ 0. "customer was found

UPDATE KNVV SET

ZZDELPRTY = Z1KNVVM-ZZDELPRTY

ZZRANK = Z1KNVVM-ZZRANK

WHERE KUNNR = KNA1M-KUNNR AND

VKORG = KNVVM-VKORG AND

VTWEG = KNVVM-VTWEG AND

SPART = KNVVM-SPART.

ELSE.

  • The following lines of code will create a status record

  • with status 51, and a workflow is started

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'ZE'.

IDOC_STATUS-MSGNO = '005'.

IDOC_STATUS-MSGV1 = KNA1M-KUNNR.

APPEND IDOC_STATUS.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

ENDCASE.

ENDLOOP.

Thanks,

Krishna Rao

Read only

Former Member
0 Likes
1,257

USEREXIT

Userxits allow us to add our own functionality to SAP standard program

without modifying it . These are implemented in the form of subroutines and hence are also known as FORM EXITs. The userexits are generally collected in includes and attached to the standard program by the SAP.

All Userexits start with the word USEREXIT_...

FORM USEREXIT_..

z..

ENDFORM.

The problem lies in finding the correct userexit and how to find it if one exists for the 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.

e.g. USEREXIT_SAVE_DOCUMENT_PREPARE

Certain application like SD still provide this form of enhancement using userexit but this practice is no longer being followed for newer extensions

instead they are using EXITs which come bundeled in enhancement packages . Neverthiless existing USEREXITS will be supported by SAP an all the newer versions of SAP.

HOW TO FIND USEREXITS

Userexits can be found in number of ways:

1) To find userexits in SD module , goto object navigator(SE80) and select

development class 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 .

Some examples of userexits in SD(SALES & DISTRIBUTION ) are:

1)ADDING OF NEW FIELDS IN PRICING

In Pricing in SD the fields on the basis of which pricing is done are derived from the FIELD CATALOG which is a structure KOMG .This structure is used to transfer transaction data to the pricing procedure in SD and is also known as communication structure.This structure KOMG consists of two tables KOMK for Header related fields and KOMP for item related fields.

The fields which are not in either of the two tables KOMK and KOMP

cannot be used in pricing .Sometimes a need arises when the pricing

is to be based on some other criteria which is not present in the form of fields in either of the two tables.

This problem can be solved by using USEREXITS which are provided for pricing in SD.

Pricing takes place both when the SALES ORDER ( Transaction VA01) is created as well as when INVOICING ( Transaction VF01) is done.Hence SAP provides 2 userexits ,one for sales order processing which is

USEREXIT_PRICING_PREPARE_TKOMP or

USEREXIT_PRICING_PREPARE_TKOMK

Depending upon which table (KOMK or KOMP) the new fields were inserted we use either of the above two userexits.These userexits are found in include MV45AFZZ of the standard SAP sales order creation program SAPMV45A.

In the case of userexit which will be called when invoicing is done ,these

are provided in the include RY60AFZZ which is in the standard SAP

program SAPMV45A. The name of the userexits are same. i.e

USEREXIT_PRICING_PREPARE_TKOMP or

USEREXIT_PRICING_PREPARE_TKOMK

These userexits are used for passing the data from the communication structure to the pricing procedure, for this we have to fill the newely

created field in the communication structure KOMG for this we fill the code in the above userexit using the MOVE statement after the data that

has to be passed is taken from the database table by using the SELECT statement. The actual structure which is visible in these userexits and which is to be filled for that particular field is TKOMP or TKOMK.

Before the coding for these userexits is done ,it is necessary to create a new field in either of the two tables KOMK or KOMP .For this purpose

includes are provided in each of them .

To create the field in header data(KOMK) the include provided is KOMKAZ

and to create the field in item data(KOMP) the include provided is KOMPAZ.

One possible example for the need of creating new fields can be e.g. Frieght to be based upon transportation zone ,for this no field is available in field catalog and hence it can be created in KOMK and then above userexits can be used to fill the transportation data to it.

2)The other method of finding userexit is to find the word USEREXIT in the

associated program of the transaction for which we want to determine userexit using SE38.

3)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 subfolder under SYSTEM MODIFICATION.

Some other examples of userexits in SD are:

USEREXIT_NUMBER_RANGE

This userexit is used to assign a different internal document number to the

sales order(VA01) when it is created depending on some criteria like a different SALES ORGANIZAION(VKORG) .

USEREXIT_SAVE_DOCUMENT_PREPARE

This userexit is used to insert the ABAP code which will be called when

the document (sales order VA01) is just about to be saved.This userexit is used generally for custom checks on different fields , to display some information before the order will be saved or for making changes to certain fields before the sales order will be saved.

Exits & Enhancements

There are mainly six types of EXITs in sap which have been collected in the form of enhancement packages and attached to standard code in SAP.

These are different from USEREXIT in the way that they are implemented

in the form of FUNCTIONs while in USEREXITS we use form routines for their implementation. These are also sometimes known as function exits .

These start from the word EXIT_ followed by the program name and then followed by a three digit number.

e.g. EXIT_SAPMV45A_002

This exit is found in SD in enhancement V45A0002.

TYPES OF EXITS

1)MENU EXITS

2)FUNCTION EXITS

3)TABLE EXITS

4)SCREEN EXITS

5)KEYWORD EXITS

6)FIELD EXITS

We use SAP transactions CMOD and SMOD to manage exits. Before implementing an exit , it is required to create the project by using CMOD

selecting the enhancement e.g. V45A0002 and selecting the component

(one which fulfills our need) i.e the exit which will be implemented in SMOD and after coding has been done the project has to be activated.

An exit can be coded only once.

FUNCTION EXITS

These are used to add functionality through ABAP code . These start from the word EXIT_programname_NNN ending in a 3 digit number. No access code is required to implement any tupe of exit including function exits.

The function exits are called from the standard SAP program in the form

of ABAP statement

CALL CUSTOMER-FUNCTION 'NNN'

This is in contrast to USEREXITs where PERFORM statement is used to call

the required userexit.

To implement the FUNCTION EXITs first of all the project is created and a suitable enhancement package is selected and from its compnents the function exit to be implemented is selected and on double clicking it the exit code will appear in ABAP EDITOR(se38) where a Z include will be found and the customer code should be entered in this include.

e.g.

ADDING A DEFAULT SOLD-TO-PARTY in Sales Order Creation

To show a default sold-to-party in this field when the user creates a sales order (VA01) we can use a function exit .This function exit is located

in enhancement no V45A0002 . Before we can choose the exit we have to

create a project in CMOD after that enter V45A0002 in the enhancement field and click on the components . In the components you will see the

exit EXIT_SAPMV45A_002 . This exit is used for our purpose.

Double clicking on this exit will takes us to function builder (SE37) . This

function exit has one exporting parameters and two importing parameters, we are interested in exporting parameter which is E_KUNNR

of type KNA1-KUNNR i.e if we move the desired customer name to this

structure(E_KUNNR) it will be shown in the field as the default value when we create the sales order.

This function also contains a customer include ZXVVA04 . This include

will be used to write our custom code .

Double clicking on this include and it will prompt us that this include does not exists do you want to create this object ,select yes and the include will be created .In this include we can write our own code that will fill the field E_KUNNR.

e.g. E_KUNNR = 301.

Activate the include and Activate the project. Now when ever the SALES ORDER will be created , sold-to-party field will come up with a predefined

customer .

FIELD EXITS

The field exits are managed,created,activated through program RSMODPRF. The field exit is associated with a data element existing in ABAP dictionary and hence to the screen field using that data element.

The format of field exit is :

FIELD_EXIT_dataelement_A-Z or 0-9

If a particular screen and program name is not specified than the field exit will effect all the screens containing that data element.

The function module associated with field exit shows two parameters

INPUT and OUTPUT. Input parameter contains the data passed to the field exit when the field exit was invoked by the R/3 , We can write our own code to change the output parameter depending upon our requirements.

Before the field exit can have any effect the system profile parameter

ABAP/FIELDEXIT in all the application servers should be set to YES

ABAP/FIELDEXIT = YES.

Regards,

vineela.

Read only

Former Member
0 Likes
1,257

Hi,

You can fill the IDOC segments yourself in the user exit and use 'MASTER_IDOC_DISTRIBUTE' to actually create the IDOC. The call is a simple one as follows.

code

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

master_idoc_control = i_edidc

TABLES

communication_idoc_control = i_com_edidc

master_idoc_data = i_edidd

EXCEPTIONS

error_in_idoc_control = 1

error_writing_idoc_status = 2

error_in_idoc_data = 3

sending_logical_system_unknown = 4

OTHERS = 5.

[/code]

'i_edidd' is your internal table containing filled-in IDOC segments.

Regards

Kiran Sure