Skip to Content
Technical Articles
Author's profile photo Enio Rafael

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.

Assigned tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Quynh Doan Manh
      Quynh Doan Manh

      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?

      Author's profile photo Enio Rafael
      Enio Rafael
      Blog Post Author

      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.

       

      Author's profile photo Alexandre Henrat
      Alexandre Henrat

      Hi,

      For the record, the field-control logic is explained in OSS note 2287838

      Author's profile photo Michael Bennett
      Michael Bennett

       

      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

       

      Author's profile photo Carlos Wagner Moçatto
      Carlos Wagner Moçatto

      What a nice document dear Enio Rafael.

      congrats for sharing here with all of us.

      take care

      Moçatto

       

      Author's profile photo Kellen Yan
      Kellen Yan

      Nice,Very helpful article.

      But How to quickly find the corresponding number of ME21N field.

      Regards,

      Kellen

      Author's profile photo LUIS RODRIGO ARELLANO ANONALES
      LUIS RODRIGO ARELLANO ANONALES

      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

      ME22N

      Is there a way to find the right field?

      Thanks in advance

       
      Author's profile photo Harshit Varshney
      Harshit Varshney
      In the end of function MEPOBADI_FS_ITEM include the implicit enhancement.

       

      LOOP AT ch_fieldselection INTO w_fieldselection WHERE metafield '132'. " Disabled Batch Field
                    w_fieldselection-fieldstatus '*' .
                    MODIFY ch_fieldselection FROM w_fieldselection.
                    CLEAR w_fieldselection.
                ENDLOOP.