Suppose you want to put a validation on a particular field then you can use Field exit.
There are two types of field exits, Global and local.
Global Field EXIT (suffix 0)
Which is applicable for screens.
LOCAL Field EXIT: (with suffix 1-9, A-Z)
Which is applicable to a particular screen (that means, if you want to create a validation for batch field in MSC1n only, the same validation will not be applicable for other screens like VL32N, MB1C etc.)
Let’s take a simple example:
The requirement is to put a validation on field Production allocation in Basic data1 tab of Material Master. (See the below screen shot)
IT should give an error message when user enters the value ‘RDC’ in the Production Allocation field.
You can create a field exit for such kind of requirements.
There are two ways to create field exit:
Option 1:
1) For field exits in R/3 4.6C, execute transaction CMOD. Then type PRFB in the command field.
2) On the top menu…click on Field exit-> create ->enter the name of data element
3) Enter the data element required for screen field to be mandatory and Execute
4) Another screen comes with a function module name FIELD_EXIT_name of data element
5) Click create and save it to corresponding function group
6) You will get a function module with
import parameter as: INPUT
export parameter as: OUTPUT
7) In the source code write the code: for validation
8)Again to activate execute transaction CMOD. Then type
PRFB in the command field. on the top menu…click on Field
exit->Activate
now wherever data element is used the mandatory check will
come but you need it only for your program, so in the same
screen click on Assign prog./screen tab and write the name
of the program and screen number where you want the
particular check
Option 2
You can also run the report RSMODPRF to create a field exit.
For this example we will create a GLOBAL Field exit. So it will validate Production version for all the screen where-ever it is used.(Note : will are going to use option No 2 to create this field exit for this tutorial.)
Step1
Go to SE38 and run program RSMODPRF.
Enter the data element name as KOSCH: you can find out the data element name using F1 help for that particular field: and Press F8.
Step2:
It will open the Function builder screen with FM name: FIELD_EXIT_KOSCH (FIELD_EXIT_<dataelement>_Suffix)
Just click on create button and create a FM with the following code:
(Note: it will ask for Function group name, you can create your own Function group and use it here)
If you check the IMPORT and EXPORT data, you can see the INPUT and OUTPUT.it is nothing but the value of the field.
if
input = ‘RDC’.
message
‘RDC type is not allowed’
type
‘E’.
endif.
Step 3:
Activate this Function module and click on back button.
and execute the report RSMODPRF without the data element and suffix.
It will display the below list: find out your exit
Select that entry and activate it using menu bar FIELD EXITà ACTIVATE
Now it’s time to test it…
Go to MM02 enter any material name and select Basic data 1.and enter production type as RDC.Press Enter.