Wednesday, February 2, 2011

Working with User Exits

Enter the transaction VA01.

Go to menu System and select sub item status.

We will get the name of the program as (SAPMV45A).

Now go to SE38 Editor and type the program name as SAPM45A.

And select subobjects - attributes radio button and press Display.

Note the package name. In this case, it is VA

Now go to SMOD Transaction (SMOD is used to find the enhancements and user exits.)

Here if we enter the enhancement name it results the list of user exit names.

But we don’t known the Enhancement name so press the Utilities > Find menu option.

Press Execute .

In the above enhancements our program name SAPMV45A Matches four enhancements.

So, In the below enhancements we have to check the right one.

  • V45A0001 - Determine alternative materials for product selection

  • V45A0002 - Predefine sold-to party in sales document

  • V45A0003 - Collector for customer function module pool MV45A

  • V45A0004 - Copy packing proposal into outbound Delivery.

My Analysis :

Every Function Module for Enhancement supplies some Import and Export Parameters.

Through which we get some values.

V45A0001 – The Description of this enhancement tell us that it determines the alternative materials for product selection. (i.e., If one material is not available what is the other material that has to be used as an alternative. So it is item specific).

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

If we observe the Importing parameters

  1. There is no way to get VBAK – EBELN (Sales Order No.) and other header data form VBAK.

So, this user exit is not useful.

V45A0002 - By Description we understand that we can predefine sold-to party in the sales document. (i.e., it is used to populate the field sold-to party through user-exit while entering the data. ) But our requirement comes after entering the data in the screen and save button is pressed.

FUNCTION EXIT_SAPMV45A_002.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_TVAK) LIKE TVAK STRUCTURE TVAK
*" VALUE(I_TVTA) LIKE TVTA STRUCTURE TVTA
*" VALUE(I_VKGRP) LIKE VBAK-VKGRP
*" VALUE(I_VKBUR) LIKE VBAK-VKBUR

And even the importing parameters are not useful for us.

V45A0004 - Copy packing proposal Into Out bound delivery. This description implies that whenever we create a Delivery Order from Sales Order it copies the packing proposal Based on the already created Sales order. So, there is no chance for us to save the data while we create or change a Sales order.

V45A0003 - Collector for customer function module pool MV45A - This description some what looks good . But description there is no functionality mentioned. So, let us drill down.

We have 2 exits.

Function module Short Text

EXIT_SAPMV45A_003 Rev.Rec.: Copy Requirements An Header

EXIT_SAPMV45A_004 Rev.Rec.: Field Modification Sales

FUNCTION EXIT_SAPMV45A_004.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_SCREEN_NAME) LIKE FELD-NAME
*" VALUE(I_VBAP) LIKE VBAP STRUCTURE VBAP
*" VALUE(I_VBUP) LIKE VBUPVB STRUCTURE VBUPVB
*" VALUE(I_SCREEN_GROUP4) LIKE FELD-GRP4
*" VALUE(I_T180_AKTYP) LIKE T180-AKTYP

From Exit 004 Description and Importing parameters we can clearly see that this exit is used for Field modifications.

EXIT_SAPMV45A_003 - From the Description and Importing parameters we get the header data that can be used for our requirement.

FUNCTION EXIT_SAPMV45A_003.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(XVBAK) LIKE VBAK STRUCTURE VBAK
*" VALUE(XVBUK) LIKE VBUK STRUCTURE VBUK
*" VALUE(XKOMK) LIKE KOMK STRUCTURE KOMK

The purpose of SMOD is to find User Exits.

Once we find the user exits, We go to CMOD. The purpose of the CMOD is to register what we are going to do in the particular enhancement. So, at the time of up gradation it will be easy to retain the code.

click on Create.

Now in the next screen (see below), click on Save and then on “Enhancement assignments)

Now enter your enhancement name, click on Save and then on “Components”

Now double click on the required function exit

data: gt_exit type zexit,
gs_vbeln TYPE zexit-vbeln,
gs_inr TYPE vbak-netwr,
gs_loc type vbak-waerk value 'INR'.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
date = sy-datum
foreign_amount = xvbak-netwr
foreign_currency = xvbak-waerk
local_currency = gs_loc
RATE = 0
TYPE_OF_RATE = 'M'
READ_TCURR = 'X'
IMPORTING
EXCHANGE_RATE =
FOREIGN_FACTOR =
LOCAL_AMOUNT = gs_inr
LOCAL_FACTOR =
EXCHANGE_RATEX =
FIXED_RATE =
DERIVED_RATE_TYPE =
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

if gs_inr > '1000'.
gt_exit-zstatus = 'High Value'.
elseif
gs_inr > '100' and
gs_inr < '1000'.
gt_exit-zstatus = 'Normal Value'.
elseif
gs_inr < '100'.
gt_exit-zstatus = 'Low Value'.
endif.

gt_exit-vbeln = xvbak-vbeln.
gt_exit-vkorg = xvbak-vkorg.
gt_exit-vtweg = xvbak-vtweg.
gt_exit-spart = xvbak-spart.

insert into zexit values gt_exit.
clear gt_exit.


No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites