Sunday, 29 October 2017

Add Custom Field to Purchase Requisition – MEREQ001

I looked for a detailed document about ME51N-ME52N-ME53N add custom field in SCN but i have not found fully described. That’s why i decided create this blog.


Symptom:


Some customers need to add custom fields for their purchasing request documents then try to copy this field other subsequent purchasing documents such a purchase order. You can benefit from this blog for these requirements.

Related OSS Notes: 


408017 - MERQ001: Implementation sample code
496083 - FAQ: Customer enhancements (user exits) in purchasing

I suggest that please read MEREQ001 enhancement document ! Because, SAP inform you how to design your developments step by step.

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

When you finish explainations of SAP , you will get information about this user-exit.

Sum up ;

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

1 - Append your custom field to CI_EBANDB .

2 - Create subscreen and add custom field to screen number 111.

3 - EXIT_SAPLMEREQ_001 is used to Export Data to Customer Subscreen for

Purchase Requisition(PBO).

4 - EXIT_SAPLMEREQ_003 is used to Import Data from Customer Subscreen for

Purchase Requisition.

5 - If you get DUMP like a –> Runtime error : DBSQL_SQL_ERROR , Exception : CX_SY_OPEN_SQL_DB., go to SE14 for EBEV then ‘Adjust and activate’ !

I created a project for implementation in CMOD named ZMM and MEREQ001 is added such a component. Then you can work on it.

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

SOLUTION :

1 - Add ZZUSER to CI_EBANDB .

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

2 - Create subscreen and fill out modules.

Attributes :

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

Layout :

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

Flow Logic :

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

ABAP Codes :

PBO –> Status module.

*----------------------------------------------------------------------*
*&      Module  STATUS_0111  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0111 OUTPUT.
*/ M.Ozgur Unal - 26.10.2017 - SP IT

*& ZXM02U01 include dan gönderildi.
   IMPORT flag_input FROM MEMORY ID 'Z_FLAG_INPUT_ZXM02U01'.

   LOOP AT SCREEN.
    IF screen-group1 = 'ZPR'.
     IF flag_input = 'X'.
      screen-input = 1.
     ELSE.
      screen-input = 0.
     ENDIF.
      MODIFY SCREEN.
    ENDIF.
   ENDLOOP.

ENDMODULE.

PAI –> Field on request

*----------------------------------------------------------------------*
*&      Module  CHECK_ZZUSER  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE check_zzuser INPUT.
*/ M.Ozgur Unal - 26102017 - SP IT
 DATA : ls_zfi_tek_ony TYPE zfi_tek_ony.

 CHECK NOT ci_ebandb-zzuser IS INITIAL.
 SELECT SINGLE *
   FROM zfi_tek_ony
   INTO ls_zfi_tek_ony
   WHERE zzuser EQ ci_ebandb-zzuser.
 IF sy-subrc IS NOT INITIAL.
   MESSAGE e163(zmm).
 ENDIF.

ENDMODULE.

Note: I did not fill out user_commad_0111 so that there is no details !

3 - Development for EXIT_SAPLMEREQ_001 –>  INCLUDE ZXM02U01 .

*&---------------------------------------------------------------------*
*&  Include           ZXM02U01
*&---------------------------------------------------------------------*

*/ M.Ozgur Unal - 261017 - SP IT

DATA   : ls_mereq_item TYPE mereq_item.
DATA   : cur_activity  TYPE aktvt.

* clear eban values if no PReq item
IF im_req_item IS INITIAL.
  CLEAR: ci_ebandb.
ELSE.
* read item data from system
  ls_mereq_item = im_req_item->get_data( ).

* fill customer field with old values
  ci_ebandb-zzuser    = ls_mereq_item-zzuser.

ENDIF.

CALL METHOD im_req_item->get_activity
  RECEIVING re_aktvt = cur_activity.

CASE cur_activity.
  WHEN 'A'.
  flag_input = space.
  WHEN 'V'.
  flag_input = 'X'.     "Modify
ENDCASE.

* MEREQ001 Enh customer sub screen de kullanılacak.
FREE MEMORY ID 'Z_FLAG_INPUT_ZXM02U01'.
EXPORT flag_input FROM flag_input TO MEMORY ID 'Z_FLAG_INPUT_ZXM02U01'.

4 - Development for EXIT_SAPLMEREQ_003 –>  INCLUDE ZXM02U03 .

*&---------------------------------------------------------------------*
*&  Include           ZXM02U03
*&---------------------------------------------------------------------*

*/ M.Ozgur Unal - 261017 - SP IT

DATA:   l_mereq_item TYPE mereq_item,
        eban         TYPE eban,
        l_aktvt      TYPE aktvt.

IF NOT im_req_item IS INITIAL.
  " read item data from system
  l_mereq_item = im_req_item->get_data( ).

  l_aktvt = im_req_item->get_activity( ).

  IF l_aktvt EQ 'A'.

  ELSEIF l_aktvt EQ 'V' OR l_aktvt EQ 'H'.
   IF l_mereq_item-zzuser NE ci_ebandb-zzuser.
     l_mereq_item-zzuser = ci_ebandb-zzuser.
     ex_changed = 'X'.
   ENDIF.

   IF ex_changed = 'X'.
     CALL METHOD im_req_item->set_data( l_mereq_item ).
   ENDIF.

  ENDIF.

ENDIF.

RESULTS :

Purchase Requisition 

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

EBAN is updated correctly !

SAP ABAP Development, SAP ABAP Live, SAP ABAP Guides

I hope that you will need to copy custom fields to subsequent documents such a purchase order. You have to add same field to subsequent purchasing document and fill out fields in subscreen referance to purchase requisition.

If you want to copy PR custom field to PO custom field with a referance, you can benefit from PBO of customer screen in SAPMM06E 0111 CUSTSCR1 SAPLXM06 0111 ! (Screen exit PO)

Enhancement IMP –> MM06E005 Customer fields in purchasing document .

Read custom field PR.

 IF i_aktyp EQ 'H' OR i_aktyp EQ 'V'
  SELECT SINGLE zzuser
   FROM EBAN
   INTO @DATA(wa_eban)
   WHERE ebeln = ekpo-ebeln
   AND  ebelp = ekpo-ebelp.

  IF sy-subrc IS INITIAL.
   gs_ci_ekpo-zzuser = wa_eban-zzuser.
  ENDIF.
 ENDIF.

No comments:

Post a Comment