Docstoc

MIGO BADI

Document Sample
MIGO BADI Powered By Docstoc
					    MIGO Custom fields add in the transaction and MSEG table

Yes you can do it; I did it with the same BADI method to update to custom fields in MSEG table through
MIGO transaction.

Here is the steps you need to follow:-

1. Create a append structure or you can use the CI include to add fields in MSEG table. I did it though
append structure only.

2. Create a implementation of MB_MIGO_BADI through SE18 or SE19 transaction.

3. Implement the interface IF_EX_MB_MIGO_BADI methods, the details of interface implementations
are described below:-

*Attribute*

GV_VEND_LOT Instance Attribute           Public Type     CHAR1 'X' : Purchase order Type NB (Standard
PO) found

GIT_MSEG        Instance Attribute       Public Type     TY_T_MSEG        Table MSEG

GV_BSART        Instance Attribute       Public Type     ESART Purchasing Document Type

GV_GRMODE Instance Attribute             Public Type     CHAR1 X: Document is of Type GR with PO and
Y : Document with Mat.

GWA_MSEG        Instance Attribute       Public Type     MSEG Document Segment: Material

GC_CLASS_ID Constant            Private Type MIGO_CLASS_ID                Class ID for MIGO Components
(External Detail Screen) 'ZIMP_MB_MIGO_BADI'

GV_LINE_ID      Instance Attribute       Private Type    GOITEM-GLOBAL_COUNTER            LINE_ID of Line
Displayed in Detail

GIT_LINE_ID     Instance Attribute       Private Type    /KYK/TRG_NUMC6           Range Table: NUMC6

GWA_LINE_ID Instance Attribute           Private Type    /KYK/SRG_NUMC6           Range Structure:
NUMC6

GC_X    Constant        Private Type     CHAR1 'X' : Select      'X'

GC_BSART        Constant        Private Type     ESART Purchasing Document Type           'NB'
*************************************************************************************
*****************

IF_EX_MB_MIGO_BADI~INIT

METHOD if_ex_mb_migo_badi~init.

 IF gv_grmode = gc_x.

* Regristration of BAdI-Implementation:

* Append class attribute GF_CLASS_ID (='ZIMP_MB_MIGO_BADI') to

* regristration table.

    APPEND gc_class_id TO ct_init.

 ENDIF.

ENDMETHOD.

*************************************************************************************
******************

IF_EX_MB_MIGO_BADI~PBO_DETAIL

METHOD if_ex_mb_migo_badi~pbo_detail.

* Lines added to do display Vendor lot tab in the item level

* Only for Purchase order type NB (Standard PO)

* Local constants

 DATA : lc_cprog TYPE sycprog VALUE 'ZMMM_MIGO_VENDOR_COO',

      lc_dynnr TYPE sydynnr VALUE '0100'.

*      lc_heading TYPE migo_badi_heading VALUE 'Vendor Lot Number'.

* Read Line item from buffer table

* if sy-subrc =0 then only display vendor lot tab

 READ TABLE git_line_id WITH KEY low = i_line_id

 BINARY SEARCH TRANSPORTING NO FIELDS.

 IF sy-subrc EQ 0 AND ( gv_grmode IS NOT INITIAL
  AND gv_vend_lot = gc_x ).

  e_cprog = lc_cprog. " Program name

  e_dynnr = lc_dynnr. " Screen number

  e_heading = text-001. " Tab Heading

  gv_line_id = i_line_id. " line Item

 ENDIF.

ENDMETHOD.

*************************************************************************************
******************

IF_EX_MB_MIGO_BADI~PAI_DETAIL

METHOD if_ex_mb_migo_badi~pai_detail.

 IF gv_grmode IS NOT INITIAL AND gv_vend_lot = gc_x.

* 'X': The Method LINE_MODIFY Is Processed

  e_force_change = gc_x.

* Reset the Flag for next line item selection

  CLEAR gv_vend_lot.

 ENDIF.

ENDMETHOD.

*************************************************************************************
*****************



IF_EX_MB_MIGO_BADI~LINE_MODIFY

METHOD if_ex_mb_migo_badi~line_modify.



 IF cs_goitem-ebeln IS NOT INITIAL.

* Look for Purchase order number from EKKO and get the Order Type.
* If the Order type is NB (Standard PO) then set the flag GV_VEND_LOT.

  SELECT SINGLE bsart FROM ekko INTO gv_bsart

   WHERE ebeln = cs_goitem-ebeln.

  IF sy-subrc EQ 0 AND gv_bsart = gc_bsart.

   gv_vend_lot = gc_x.

   IF NOT i_line_id IS INITIAL.

    gwa_line_id-low = i_line_id.

   ENDIF.

   IF git_line_id IS NOT INITIAL.

    SORT git_line_id BY low.

   ENDIF.

   READ TABLE git_line_id WITH KEY

   low = i_line_id BINARY SEARCH

   TRANSPORTING NO FIELDS.

   IF sy-subrc <> 0 AND gwa_line_id IS NOT INITIAL.

    APPEND gwa_line_id TO git_line_id.

   ENDIF.

  ELSE.

   CLEAR gv_vend_lot.

  ENDIF.

  CLEAR : gv_bsart,

      gwa_line_id.

 ENDIF.

*************Buffer MSEG table with custom fields **********************

*Item is Adopted in Document
 IF NOT cs_goitem-take_it IS INITIAL.

  CLEAR gwa_mseg.

  MOVE-CORRESPONDING cs_goitem TO gwa_mseg.

  APPEND gwa_mseg TO git_mseg.

 ENDIF.



ENDMETHOD.

*************************************************************************************
************************



METHOD if_ex_mb_migo_badi~post_document.

* Delete duplicate line item if avail in GIT_MSEG table

 SORT git_mseg BY zeile.

 DELETE ADJACENT DUPLICATES FROM git_mseg COMPARING zeile.

* To access these valu in Ennhancement Spot ZENHIMPL_MM_MB_MIGO_BADI_MB

 EXPORT : git_mseg FROM git_mseg TO MEMORY ID 'GIT_MSEG',

      gv_grmode FROM gv_grmode TO MEMORY ID 'GV_GRMODE'.

* Refresh all class content

 CLEAR : gv_vend_lot,

     gv_bsart,

     gv_grmode,

     gwa_mseg,

     gv_line_id,

     gwa_line_id.



 REFRESH : git_mseg,
         git_line_id.



ENDMETHOD.

*************************************************************************************
***********************

METHOD if_ex_mb_migo_badi~mode_set.

* Local Constants

 DATA : lc_a01 TYPE goaction VALUE 'A01', " Goods Receipt

    lc_r01 TYPE refdoc VALUE 'R01', " Purchase order

    lc_a04 TYPE goaction VALUE 'A04', " Display

    lc_r02 TYPE refdoc VALUE 'R02', " Material Document

    lc_y TYPE char1 VALUE 'Y'.      " Indicator for Display material document



* Set mode variable for Good Receipt with Purchase order

 IF i_action = lc_a01 AND i_refdoc = lc_r01.

  gv_grmode = gc_x.

 ELSEIF i_action = lc_a04 AND i_refdoc = lc_r02.

* Set mode variable for Good Receipt with Purchase order

  gv_grmode = lc_y.

 ELSE.

  CLEAR gv_grmode.

 ENDIF.

ENDMETHOD.

*************************************************************************************
**********************

METHOD if_ex_mb_migo_badi~publish_material_item.
 IF ls_goitem-ebeln IS NOT INITIAL.

* Look for Purchase order number from EKKO and get the Order Type.

* If the Order type is NB (Standard PO) then set the flag GV_VEND_LOT.

* This method is used to material document display

  SELECT SINGLE bsart FROM ekko INTO gv_bsart

   WHERE ebeln = ls_goitem-ebeln.

  IF sy-subrc EQ 0 AND gv_bsart = gc_bsart.

   gv_vend_lot = gc_x.

   IF NOT ls_goitem-zeile IS INITIAL.

    gwa_line_id-low = ls_goitem-zeile.

   ENDIF.

   IF git_line_id IS NOT INITIAL.

    SORT git_line_id BY low.

   ENDIF.

   READ TABLE git_line_id WITH KEY

   low = ls_goitem-zeile BINARY SEARCH

   TRANSPORTING NO FIELDS.

   IF sy-subrc <> 0 AND gwa_line_id IS NOT INITIAL.

    APPEND gwa_line_id TO git_line_id.

   ENDIF.

  ELSE.

   CLEAR gv_vend_lot.

  ENDIF.

  CLEAR : gv_bsart,

      gwa_line_id.
 ENDIF.

ENDMETHOD.

*************************************************************************************
**********************

METHOD modify_mseg.



 DATA : lwa_mseg TYPE mseg.

* Check if buffer MSEG table is not initial

* and mode is GR with PO then only update XMSEG from GIT_MSEG

 IMPORT : git_mseg TO git_mseg FROM MEMORY ID 'GIT_MSEG',

      gv_grmode TO gv_grmode FROM MEMORY ID 'GV_GRMODE'.



 IF git_mseg IS NOT INITIAL

  AND gv_grmode = gc_x.

  SORT git_mseg BY zeile.

  LOOP AT xy_mseg INTO lwa_mseg.

* Identify the record and update XMSEG

   CLEAR gwa_mseg.

   READ TABLE git_mseg

   INTO gwa_mseg

   WITH KEY zeile = lwa_mseg-zeile BINARY SEARCH.

   IF sy-subrc EQ 0.

    MODIFY xy_mseg FROM gwa_mseg

    TRANSPORTING zvendlot zcoo WHERE zeile = gwa_mseg-zeile.

   ENDIF.

   CLEAR lwa_mseg.
  ENDLOOP.

* Reset buffer table and mode

  REFRESH git_mseg.

  CLEAR gv_grmode.

 ENDIF.

* Free memory ids

 FREE MEMORY ID : 'GIT_MSEG',

           'GV_GRMODE'.



ENDMETHOD.

*************************************************************************************
********************

4. Now go to the function module MB_POST_GOODS_MOVEMENT andcall the method
modify_msegfrom the implemented class ZCL_IM__MB_MIGO_BADI.

ENHANCEMENT 110 ZENHIMPL_MM_MB_MIGO_BADI_MB. "active version

* Data declaration for badi method

 Data : lo_ZCL_IM__MB_MIGO_BADI TYPE REF TO ZCL_IM__MB_MIGO_BADI.

 CREATE OBJECT lo_ZCL_IM__MB_MIGO_BADI.

 if sy-subrc eq 0 and xmseg[] is NOT INITIAL.

  CALL METHOD lo_zcl_im__mb_migo_badi->modify_mseg

   CHANGING

    xy_mseg = xmseg[].

 endif.

ENDENHANCEMENT.

Regards,

Dhirendra Pandit

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:1371
posted:5/12/2011
language:English
pages:9