6
Split quantity automatically in MIGO I have a very odd requirement. In transaction MIGO, if user makes a goods movement referenced by a purchase order and if moved quantity is greater than po quantity, line item will be splitted into two items. There's a "Split Qty" button on screen and I examined the process but didn't have any luck to accomplish this automatically. Has anybody did that before? Correct Answer by Kerem Kayacan on Sep 22, 2010 9:04 AM Here is what I did. I will paste the code here. If it is not clear, let me know. Function group: MIGO Enhancement spot: ES_SAPLMIGO Enhancement point: LINE_MODIFY_04 DATA: lv_action TYPE goaction, lv_refdoc TYPE refdoc, lv_remain type bsmng, begin of ls_zeil, zeile type mblpo, global_counter type MIGO_GLOBAL_COUNTER, end of ls_zeil, lt_zeil like table of ls_zeil, lv_zeile type mblpo. if sy-tcode eq 'MIGO'. "Action and refdoc comes from MB_MIGO_BADI. "This check is not obligatory CALL FUNCTION 'ZMM_EXPORT_ACTION' IMPORTING ACTION = lv_action REFDOC = lv_refdoc. if lv_action eq 'A01' AND lv_refdoc eq 'R01' and cs_goitem-ebeln is not initial. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = cs_goitem-zeile IMPORTING OUTPUT = lv_zeile. lv_remain = cs_goitem-bsmng - cs_goitem-wemng. IF cs_goitem-erfmg gt lv_remain. okcode = 'MIGO_OK_SPLIT_QUAN'.

Migo

Embed Size (px)

DESCRIPTION

MIGO Enhancement

Citation preview

Page 1: Migo

Split quantity automatically in MIGOI have a very odd requirement. In transaction MIGO, if user makes a goods movement referenced by a purchase order and if moved quantity is greater than po quantity, line item will be splitted into two items. There's a "Split Qty" button on screen and I examined the process but didn't have any luck to accomplish this automatically. Has anybody did that before?

Correct Answer by Kerem Kayacan  on Sep 22, 2010 9:04 AMHere is what I did. I will paste the code here. If it is not clear, let me know. Function group: MIGOEnhancement spot: ES_SAPLMIGOEnhancement point: LINE_MODIFY_04   DATA:  lv_action TYPE goaction,  lv_refdoc TYPE refdoc,  lv_remain type bsmng,  begin of ls_zeil,    zeile type mblpo,    global_counter type MIGO_GLOBAL_COUNTER,  end of ls_zeil,  lt_zeil like table of ls_zeil,  lv_zeile type mblpo.

  if sy-tcode eq 'MIGO'.       "Action and refdoc comes from MB_MIGO_BADI.   "This check is not obligatory  CALL FUNCTION 'ZMM_EXPORT_ACTION'   IMPORTING     ACTION        = lv_action     REFDOC        = lv_refdoc.

  if lv_action eq 'A01' AND lv_refdoc eq 'R01' and     cs_goitem-ebeln is not initial.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'    EXPORTING      input         = cs_goitem-zeile   IMPORTING     OUTPUT        = lv_zeile.

  lv_remain = cs_goitem-bsmng - cs_goitem-wemng.

  IF cs_goitem-erfmg gt lv_remain.

    okcode = 'MIGO_OK_SPLIT_QUAN'.

    CALL FUNCTION 'ZMM_SET_AUTOSPLIT'      EXPORTING        autosplit       = 'X'.

    CALL FUNCTION 'ZMM_SET_GOITEM'      EXPORTING        goitem        = cs_goitem        tabix         = sy-tabix.

    CALL FUNCTION 'ZMM_GET_SPLITTED_LINES'

Page 2: Migo

     IMPORTING       ET_ZEILE       = lt_zeil.

    read table lt_zeil into ls_zeil with key zeile = cs_goitem-zeile.    IF sy-subrc ne 0.      ls_zeil-zeile = cs_goitem-zeile.      ls_zeil-global_counter = cs_goitem-global_counter.      append ls_zeil to lt_zeil.      "Send to MB_MIGO_BADI which line is splitted      CALL FUNCTION 'ZMM_SET_SPLITTED_LINES'        EXPORTING          it_zeile       = lt_zeil.    ENDIF.

  ENDIF."IF cs_goitem-erfmg gt lv_remain.

  endif.  "if lv_action eq 'A01' AND lv_refdoc eq 'R01'.

  ENDIF."if sy-tcode eq 'MIGO'. Enhancement spot: ES_SAPLMIGOEnhancement point: POPUP_CALL_03   LOOP AT lt_fieldmapping INTO l_fieldname.    CONCATENATE 'GOITEM-' l_fieldname INTO l_tmp_fieldname.    l_status = lcl_migo_screenmodification=>get(                 i_global_counter = ps_goitem-global_counter                 i_field          = l_tmp_fieldname               ).    IF l_status < lcl_migo_screenmodification=>c_input.      l_status = lcl_migo_screenmodification=>c_invisible.    ELSE.      l_status = lcl_migo_screenmodification=>c_visible.    ENDIF.    CONCATENATE 'GOSPLIT-' l_fieldname INTO l_fieldname.    CALL METHOD lcl_migo_screenmodification=>set      EXPORTING        i_fields = l_fieldname        i_status = l_status.  ENDLOOP.* Default values for the new lines                          "354046  MOVE-CORRESPONDING ps_goitem TO ps_gosplit_default.  CLEAR ps_gosplit_default-erfmg.* Call the popup. Width and height are set automatically.   "354046

  DATA: auto_split TYPE c LENGTH 1,        ls_goitem  type goitem,        lv_tabix   type sytabix.  CALL FUNCTION 'ZMM_GET_AUTOSPLIT'   IMPORTING     AUTOSPLIT       = auto_split.

  if auto_split IS INITIAL.    CALL SCREEN 1000 STARTING AT 5 1.  ELSE.    CALL FUNCTION 'ZMM_GET_GOITEM'     IMPORTING       GOITEM        = ls_goitem       tabix         = lv_tabix.    move-corresponding ls_goitem to gosplit.    gosplit-erfmg = ls_goitem-bsmng - ls_goitem-wemng.    CALL METHOD oref_split_quantity->pai_loop.    gosplit-erfmg = ls_goitem-erfmg -

Page 3: Migo

      ( ls_goitem-bsmng - ls_goitem-wemng ).    clear gosplit-split_line.    CALL METHOD oref_split_quantity->pai_loop.    p_selected_line = lv_tabix.    ps_goitem = ls_goitem.    CALL METHOD oref_split_quantity->pai_end.    CALL FUNCTION 'ZMM_SET_AUTOSPLIT'      EXPORTING        autosplit       = space.  ENDIF.

Page 4: Migo

Function group global data:FUNCTION-POOL zmm_migo_badi.        "MESSAGE-ID ..

types:begin of gst_zeil,  zeile type mblpo,  global_counter type MIGO_GLOBAL_COUNTER,end of gst_zeil,gtt_zeil type table of gst_zeil.

data gt_zeil type gtt_zeil.

data: gs_goitem type goitem,      gv_tabix  type sytabix.

DATA:gv_action TYPE GOACTION,gv_refdoc TYPE REFDOC,gv_autosplit type c length 1.  Function modules:FUNCTION ZMM_EXPORT_ACTION.*"----------------------------------------------------------------------*"*"Local Interface:*"  EXPORTING*"     REFERENCE(ACTION) TYPE  GOACTION*"     REFERENCE(REFDOC) TYPE  REFDOC*"----------------------------------------------------------------------

  action = gv_action.  refdoc = gv_refdoc.

ENDFUNCTION.  FUNCTION ZMM_SET_AUTOSPLIT.*"----------------------------------------------------------------------*"*"Local Interface:*"  IMPORTING*"     REFERENCE(AUTOSPLIT) TYPE  CHAR1*"----------------------------------------------------------------------

  gv_autosplit = autosplit.

ENDFUNCTION.  

Page 5: Migo

FUNCTION ZMM_SET_GOITEM.*"----------------------------------------------------------------------*"*"Local Interface:*"  IMPORTING*"     REFERENCE(GOITEM) TYPE  GOITEM*"     VALUE(TABIX) TYPE  SYTABIX*"----------------------------------------------------------------------

  gs_goitem = goitem.  gv_tabix  = tabix.

ENDFUNCTION.  FUNCTION ZMM_GET_SPLITTED_LINES.*"----------------------------------------------------------------------*"*"Local Interface:*"  EXPORTING*"     REFERENCE(ET_ZEILE)*"----------------------------------------------------------------------

  et_zeile = gt_zeil.

ENDFUNCTION.  FUNCTION ZMM_SET_SPLITTED_LINES.*"----------------------------------------------------------------------*"*"Local Interface:*"  IMPORTING*"     REFERENCE(IT_ZEILE)*"----------------------------------------------------------------------

  gt_zeil = it_zeile.

ENDFUNCTION.  FUNCTION ZMM_GET_AUTOSPLIT.*"----------------------------------------------------------------------*"*"Local Interface:*"  EXPORTING*"     REFERENCE(AUTOSPLIT) TYPE  CHAR1*"----------------------------------------------------------------------

  autosplit = gv_autosplit.

ENDFUNCTION.

Page 6: Migo

  FUNCTION ZMM_GET_GOITEM.*"----------------------------------------------------------------------*"*"Local Interface:*"  EXPORTING*"     REFERENCE(GOITEM) TYPE  GOITEM*"     REFERENCE(TABIX) TYPE  SYTABIX*"----------------------------------------------------------------------

  goitem = gs_goitem.  tabix  = gv_tabix.

ENDFUNCTION.