Technical Articles
Disable standard field in ME22N,ME21N
Hi everyone.
I saw a lot of questions about how to disable a standard field in ME22N and ME21N. So I decided to share my solution for this problem.
First of all, SAP don’t offer an standard way for reach this solution. And in my case i wanted to include some specific code to decide disable or not that field.
Lets solve the problem!
In the end of function MEPOBADI_FS_ITEM include the implicit enhancement.
ENHANCEMENT 1 ZENH_LOCK_PO_STANDARD_FIELD. "active version
data fields type table of zmmt001 with header line.
data field_selection type MMPUR_FS.
data parameters TYPE abap_parmbind_tab.
data param_line TYPE abap_parmbind.
data lock_po type ref to zcl_lock_po_field.
select *
from zmmt001
into table fields.
check not fields[] is initial.
create object lock_po
exporting
im_header = im_header
im_item = im_item.
loop at fields.
READ TABLE ch_fieldselection into field_selection with KEY metafield = fields-field.
check sy-subrc is INITIAL.
call method lock_po->(fields-method)
CHANGING
field_selection = field_selection.
MODIFY TABLE ch_fieldselection from field_selection.
endloop.
ENDENHANCEMENT.
As you can see, there is a table called ZMMT001, which will store the field number and the method that we wanna use to process.
The class ZCL_LOCK_PO_FIELD looks like this
class ZCL_LOCK_PO_FIELD definition
public
final
create public .
public section.
methods CONSTRUCTOR
importing
!IM_HEADER type ref to IF_PURCHASE_ORDER_MM
!IM_ITEM type ref to IF_PURCHASE_ORDER_ITEM_MM .
methods NET_PRICE
changing
!FIELD_SELECTION type MMPUR_FS .
PROTECTED SECTION.
PRIVATE SECTION.
CONSTANTS:
BEGIN OF field_state,
enabled TYPE c VALUE '+',
disabled TYPE c VALUE '*',
invisible TYPE c VALUE '-',
END OF field_state.
DATA po_header TYPE mepoheader .
DATA po_item TYPE mepoitem .
ENDCLASS.
CLASS ZCL_LOCK_PO_FIELD IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_LOCK_PO_FIELD->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IM_HEADER TYPE REF TO IF_PURCHASE_ORDER_MM
* | [--->] IM_ITEM TYPE REF TO IF_PURCHASE_ORDER_ITEM_MM
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
po_header = im_header->get_data( ). "//get header data
po_item = im_item->get_data( ). "//get item
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_LOCK_PO_FIELD->NET_PRICE
* +-------------------------------------------------------------------------------------------------+
* | [<-->] FIELD_SELECTION TYPE MMPUR_FS
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD net_price.
"//Make your tratatives here
* ....
"//Disable field
field_selection-fieldstatus = field_state-disabled.
ENDMETHOD.
ENDCLASS.
Thats it! if you have some thing to say, please, say.
Thanks,
Enio.
thankyou for sharing knowledge. May I ask where is this function (MEPOBADI_FS_ITEM) called? from its name look like it only affect on item level, what about header?
Hi Quynh.
Yes, the function MEPOBADI_FS_ITEM is called for every item, as you can see in the print below
About header, the function that you can use is MEPOBADI_FS_HEADER. As i could see, it works exactly like item. So you can use the same implementation.
Thanks for the question,
Enio.
Hi,
For the record, the field-control logic is explained in OSS note 2287838
Hi,
Would a transaction variant with screen variants allow you to do something similar without code? We lock down many fields in ME29N using a screen variants as part of a transaction variant set by transaction SHD0.
Regards,
Michael
What a nice document dear Enio Rafael.
congrats for sharing here with all of us.
take care
Moçatto
Nice,Very helpful article.
But How to quickly find the corresponding number of ME21N field.
Regards,
Kellen
Hi,
Thanks for the article.
Can we use the functionality to lock fields at position level within the tabs? (i.e. Quantities/Weights tab)
ME22N
Is there a way to find the right field?
Thanks in advance