Let's say you are in a sales order and have dimension specified. Before saving, you need to determine the weight according to an own algorithm. Or you have your own credit check rules, so before saving you block the order when needed. This code could be found in a user-exit.
There are now four generations of Enhancements.
- Generation 1 is called user exit. These are FORM routines within the code, usually named "userexit…. " that can be filled with own code.
- Generation 2 is called Customer Exit/Function Exit. These are special function calls that are invoked with "CALL CUSTOMER_FUNCTION"; they are defined with transaction SMOD and activated with CMOD. This article will guide you with customer Exit.
- Generation 3: they are called BAdI -- Business Add-in -- and use ABAP dynamic classes instead function calls. They are handled via SE18/SE19 and normally placed in the code via a static method call to class CL_EXIT_HANDLER.
- Generation 4: there is a new concept announced for the NetWeaver 2004s that consolidates all userexits in a common framework.
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
*"----------------------------------------------------------------------
*"*"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
- There is no way to get VBAK – EBELN (Sales Order No.) and other header data form VBAK.
So, this exit is not useful.
V45A0002 - By Description we understand that we can pre-define 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
*"----------------------------------------------------------------------
*"*"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
*"----------------------------------------------------------------------
*"*"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
*"----------------------------------------------------------------------
*"*"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.
2. Implement the exit
Once we find the 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.2. Implement the exit
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'.
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.
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-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.
gt_exit-vkorg = xvbak-vkorg.
gt_exit-vtweg = xvbak-vtweg.
gt_exit-spart = xvbak-spart.
insert into zexit values gt_exit.
clear gt_exit.
clear gt_exit.
Tip: In order to find the project, you can use table MODSAP to get Enhancement if you have function exit
then use table MODACT to get project name with the enhancement that you got above.
No comments:
Post a Comment