Skip to Content

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.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. 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?

    (0) 
    1. Enio Rafael 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.

       

      (0) 

Leave a Reply