Monday 3 October 2016

How to create a custom TAB for MIGO Item Details

I have implemented a custom tab in MIGO, you can follow the steps.

My requirement was to add a new tab named “Warranty” in MIGO.

Step1 : Create a custom table to store the data of  “Warranty”  tab

How to create a custom TAB for MIGO Item Details

The first four fields should be the key fields, and the rest fields are your required custom fields.

Step 2: create a structure with the custom field you require on the MIGO.

How to create a custom TAB for MIGO Item Details

Step 3: open structure GOITEM and append the same custom structure into it as shown below.

How to create a custom TAB for MIGO Item Details

Step 4: Create another structure and append the table created in Step-1.

How to create a custom TAB for MIGO Item Details

Step 5:  Create a Table type of the structure created in step-4 as shown below.

How to create a custom TAB for MIGO Item Details

Step 6: go to SE80 and create a program as shown below. This screen must contain two screen.

How to create a custom TAB for MIGO Item Details

How to create a custom TAB for MIGO Item Details

Step 7: SE19 -> Badi Name: MB_MIGO_BADI
Press Create Impl. Button and create Implementation: ZMIGO_WARRENTY as shown below.

How to create a custom TAB for MIGO Item Details

Step 8: Create a Class : ZCLASS_MIGO_WARRENTY as shown below.
Step 9: Maintain the following attributes in your Class Interface as shown below.

How to create a custom TAB for MIGO Item Details

Step 10: Write the following codes for the methods shown below.

How to create a custom TAB for MIGO Item Details

(a) for   IF_EX_MB_MIGO_BADI~INIT
METHOD if_ex_mb_migo_badi~init.
  APPEND gf_class_id TO ct_init.ENDMETHOD.

(b) for  IF_EX_MB_MIGO_BADI~PBO_DETAIL
METHOD if_ex_mb_migo_badi~pbo_detail.
  DATA: wa_extdata  TYPE zst_warrenty.
  DATA :gf_class_id TYPE migo_class_id.
  gf_class_id = 'ZCLASS_MIGO_WARRENTY'.
  CHECK i_class_id = gf_class_id.
  IF g_no_input IS INITIAL.
    e_cprog   = 'ZSAPMZMM_MIGO_WARENTY'.
    e_dynnr   = '9001'.                     "External fields: Input
    e_heading = 'Warranty'(001).
  ELSE.
    e_cprog   = 'ZSAPMZMM_MIGO_WARENTY'.
    e_dynnr   = '9002'.                     "External fields: Display
    e_heading = 'Warranty'(001).
  ENDIF.
  g_line_id = i_line_id.
  READ TABLE gt_extdata INTO wa_extdata WITH KEY line_id = g_line_id.
  IF sy-subrc = 0 AND wa_extdata-mblnr IS NOT INITIAL AND wa_extdata-mjahr IS NOT INITIAL AND wa_extdata-zeile IS NOT INITIAL.
    SELECT SINGLE * FROM ztb_warrenty
    CLIENT SPECIFIED INTO CORRESPONDING FIELDS OF wa_extdata
    WHERE mandt = sy-mandt
    AND   mblnr = wa_extdata-mblnr
    AND   mjahr = wa_extdata-mjahr
    AND   zeile = wa_extdata-zeile.
    SET PARAMETER ID: 'ZWARANTY' FIELD wa_extdata-zzwarnt,
                      'ZWARBEGD' FIELD wa_extdata-zzwbegd,
                      'ZWARENDD' FIELD wa_extdata-zzwendd.
  ELSE.
    SET PARAMETER ID: 'ZWARANTY' FIELD space,
                      'ZWARBEGD' FIELD space,
                      'ZWARENDD' FIELD space.
  ENDIF.ENDMETHOD.

(c) for   IF_EX_MB_MIGO_BADI~PAI_DETAIL
METHOD if_ex_mb_migo_badi~pai_detail.
    e_force_change = 'X'.ENDMETHOD.

(d) for   IF_EX_MB_MIGO_BADI~LINE_MODIFY
METHOD if_ex_mb_migo_badi~line_modify.
  DATA: ls_extdata  TYPE zst_warrenty.
  IF cs_goitem-mblnr IS NOT INITIAL AND cs_goitem-mjahr IS NOT INITIAL AND cs_goitem-zeile IS NOT INITIAL.
    ls_extdata-line_id  = i_line_id.
    ls_extdata-mblnr    = cs_goitem-mblnr.
    ls_extdata-mjahr    = cs_goitem-mjahr.
    ls_extdata-zeile    = cs_goitem-zeile.
    ls_extdata-zzwarnt  = cs_goitem-zzwarnt.
    ls_extdata-zzwbegd  = cs_goitem-zzwbegd.
    ls_extdata-zzwendd  = cs_goitem-zzwendd.
    DELETE gt_extdata WHERE line_id = ls_extdata-line_id.
    INSERT ls_extdata INTO TABLE gt_extdata.
  ELSE.
    ls_extdata-line_id  = i_line_id.
    ls_extdata-zzwarnt  = cs_goitem-zzwarnt.
    ls_extdata-zzwbegd  = cs_goitem-zzwbegd.
    ls_extdata-zzwendd  = cs_goitem-zzwendd.
    DELETE gt_extdata WHERE line_id = ls_extdata-line_id.
    INSERT ls_extdata INTO TABLE gt_extdata.
  ENDIF.ENDMETHOD.

(e) for   IF_EX_MB_MIGO_BADI~RESET
METHOD if_ex_mb_migo_badi~reset.
  CLEAR: gt_extdata,
         g_no_input,
         gs_exdata_header,
         g_cancel,
         g_line_id.ENDMETHOD.

(f) for   IF_EX_MB_MIGO_BADI~POST_DOCUMENT
METHOD if_ex_mb_migo_badi~post_document.
  DATA: wa_warrenty TYPE ztb_warrenty,
        it_warrenty TYPE TABLE OF ztb_warrenty,
        wa_mseg     TYPE mseg,
        wa_extdata  TYPE zst_warrenty.

  LOOP AT it_mseg INTO wa_mseg.
    READ TABLE gt_extdata INTO wa_extdata WITH KEY line_id = wa_mseg-line_id.
    IF sy-subrc = 0.
      MOVE-CORRESPONDING wa_mseg TO wa_extdata.
      MOVE-CORRESPONDING wa_extdata TO wa_warrenty.
      APPEND wa_warrenty TO it_warrenty.
    ENDIF.
  ENDLOOP.
  MODIFY ztb_warrenty FROM TABLE it_warrenty.
ENDMETHOD.

(g) for   IF_EX_MB_MIGO_BADI~CHECK_ITEM
METHOD if_ex_mb_migo_badi~check_item.
  DATA: wa_extdata  TYPE zst_warrenty,
        ls_bapiret TYPE bapiret2.

  READ TABLE gt_extdata INTO wa_extdata WITH TABLE KEY line_id = i_line_id.
  IF wa_extdata-zzwarnt IS INITIAL.
    ls_bapiret-type       = 'E'.
    ls_bapiret-id         = 'M7'.
    ls_bapiret-number     = '895'.
    ls_bapiret-message_v1 = 'Enter warranty condition'(002).
    APPEND ls_bapiret TO et_bapiret2.
  ENDIF.
  IF wa_extdata-zzwarnt = 'YES' AND ( wa_extdata-zzwbegd IS INITIAL OR wa_extdata-zzwendd IS INITIAL OR ( wa_extdata-zzwbegd GT wa_extdata-zzwendd ) ).
    ls_bapiret-type       = 'E'.
    ls_bapiret-id         = 'M7'.
    ls_bapiret-number     = '895'.
    ls_bapiret-message_v1 = 'Enter appropriate warranty Start and End date'(003).
    APPEND ls_bapiret TO et_bapiret2.
  ENDIF.
ENDMETHOD.

(h) for   IF_EX_MB_MIGO_BADI~MODE_SET
METHOD if_ex_mb_migo_badi~mode_set.
  CLEAR : g_no_input.
  IF i_action = 'A04' .
    g_no_input = 'X'.
  ENDIF.

  IF i_action = 'A03'.
    g_cancel = 'X'.
  ENDIF.ENDMETHOD.
Note: Leave the other Methods blank. Do not write any thing in that.

Step 11: Open MIGO , you will be able to see the new tab “WARRANTY” as shown below.

How to create a custom TAB for MIGO Item Details

The system will store the data of your custom screen into the table created in Step-1.

9 comments:

  1. Great post Ms. Sabrina. Already bookmarked for future reference.

    ReplyDelete
  2. Nice Post. Thank you Ms. Sabrina Pinto. :)

    ReplyDelete
  3. Very helpful post thank you Ms. Sabrina

    ReplyDelete
  4. WHILE activation PBO of 9002 screen it giving error GOITEM-ZZLIFNR is unknown

    ReplyDelete
  5. Plz declare Goitem at top of custom program like,

    TABLES: GOITEM.

    it would resolve your error.

    ReplyDelete
  6. Nice One... please attach clear pic so that it will be easy to follow

    ReplyDelete
  7. Hi,

    I have one requirement to add a tab with table control based on ztable in ME51N , i have added table control in screen , but unable to find out / create TOP include to declare global data ,

    Please, Help.

    ReplyDelete
  8. Nice post. How can I do this with MSEG table not Z table ?
    I have appended structure(Z*) in the mseg and goitem.
    I cannot update it_mseg in IF_EX_MB_MIGO_BADI~POST_DOCUMENT .
    Please, help.

    ReplyDelete