Checking equipment number before PO saved
when user determine quantity in a Purchase Order (PO), must be followed by maintaining equipment number in Item texts.
In short term, the amount of equipment number must be the same with PO quantity, if it’s not, the PO creation must be prevented.
i do the combination between 2 method in BADI implementation because the prevention to create a PO will be done when CHECK method is executed while the item text (long text) reading process will be done when PROCESS_ITEM method is executed.
why i use this BADI, because through this BADI, we can get the real time data which has been inputted by user.
What i do exactly is to force CHECK method to call PROCESS_ITEM method.

These are the steps..
- Go to transaction code SE15
- Choose Enhancements > Business Add-ins > Definitions
- Type ME_PROCESS_PO_CUST in BAdI Name and then Execute
- Choose to display the BAdI
- And then go to the Menu Bar and select Implementation > Create
- Do as the naming convention document told you to give the name for Implementation Name
- After that, insert these codes below in method PROCESS_ITEM and CHECK
PROCESS_ITEM
*—————————————————————–*
*>>>>> BEGIN FSEPM001
*—————————————————————–*
* FSEPM001 : Checking equipment number before PO saved
*—————————————————————–*data: re_data type mepoitem,
r_item type range of mepoitem-ebelp.
data: lt_data type table of mepoitem.data: ld_mtart type mtart,
ld_sernp type serail,
ld_ebelp type string,
ld_menge type i,
ld_line type i,
ld_message type string value ‘Please maintain equipment number in item number’,
ld_check type c.
data: t_line type table of mmpur_textlines,
ld_formatted type mmpur_bool.if im_item is not initial.
“get the item data
call method im_item->get_data
receiving
re_data = re_data.import ld_check to ld_check from memory id re_data-ebeln.
check ld_check = ‘X’.
select single mtart
into ld_mtart
from mara
where matnr = re_data-matnr and mtart = ‘ERSA’.
select single sernp
into ld_sernp
from marc
where matnr = re_data-matnr and sernp = ‘ZPM1′ and werks = re_data-werks.if ld_mtart is initial.
message e001(zmcpm0001) with ‘Material Type is not ”ERSA”’.
endif.if ld_sernp is initial.
message e001(zmcpm0001) with ‘Serial Number profile is not ”ZPM1”’.
else.“-Get item text
call method im_item->if_longtexts_mm~get_text
exporting
im_tdid = ‘F01′
importing
ex_textlines = t_line
ex_text_formatted = ld_formatted.describe table t_line lines ld_line.
ld_menge = re_data-menge.
if ld_line <> ld_menge.
call function ‘CONVERSION_EXIT_ALPHA_OUTPUT’
exporting
input = re_data-ebelp
importing
output = re_data-ebelp.
ld_ebelp = re_data-ebelp.
endif.free: ld_mtart, ld_sernp.
clear: t_line.
endif.delete from memory id re_data-ebeln.
if ld_ebelp is not initial.
concatenate ld_message ld_ebelp into ld_message separated by space.
message e001(zmcpm0001) with ld_message.
endif.
endif.
*—————————————————————–*
* >>>>>END FSEPM001
*—————————————————————–*
CHECK
*—————————————————————–*
*>>>>> BEGIN FSEPM001
*—————————————————————–*
* FSEPM001 : Checking equipment number before PO saved
*—————————————————————–*
DATA: gf_me_process_po_cust TYPE REF TO if_ex_me_process_po_cust,
gf_me_process_po_cust_active(1).DATA: l_instance_cust LIKE gf_me_process_po_cust.
DATA: re_header TYPE mepoheader,
re_items TYPE purchase_order_items,
ld_mepoitem TYPE mepoitem,
re_items2 TYPE purchase_order_item.
CONSTANTS ld_check TYPE c VALUE ‘X’.CALL METHOD im_header->get_data
RECEIVING
re_data = re_header.CALL METHOD im_header->get_items
RECEIVING
re_items = re_items.LOOP AT re_items INTO re_items2 .
po_item = po_item_obj-item->get_data( ).
IF gf_me_process_po_cust_active IS INITIAL.
gf_me_process_po_cust ?= cl_badi_mm=>get_instance(’ME_PROCESS_PO_CUST’ ).
IF NOT gf_me_process_po_cust IS INITIAL.
gf_me_process_po_cust_active = ‘Y’.
ELSE.
gf_me_process_po_cust_active = ‘N’.
ENDIF.
ENDIF.
IF gf_me_process_po_cust_active EQ ‘Y’.
l_instance_cust = gf_me_process_po_cust.
ENDIF.EXPORT ld_check FROM ld_check TO MEMORY ID re_header-ebeln.
CALL METHOD l_instance_cust->process_item
EXPORTING
im_item = re_items2-item.
ENDLOOP.*—————————————————————–*
* >>>>>END FSEPM001
*—————————————————————–*

Leave a Reply