Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Post document in MIGO for Item code and its component by calling BAPI_GOODSMVT_CREATE multiple times

Former Member
0 Kudos
667

Hi Gurus,

I have a requirement where in MIGO i have an item with 101 movement type. Also there is a component with movement type 543 for this item code. Now when i click on "POST" it should convert both the materials as NV-<ITEM_CODE> and post at the background.

To achieve this i first used MB_MIGO_BADI for main item having MVT type 101. Inside that i created a functional module in UPDATE TASK and call " BAPI_GOODSMVT_CREATE". It worked well but for another item with MVT type 543 i created a remote functional module with addition IN BACKGROUND TASK AS SEPARATE UNIT in MB_DOCUMENT_BADI's method MB_DOCUMENT_UPDATE.

But i am facing problems like:
1. In method MB_DOCUMENT_UPDATE i am not getting the component data
which i entered in the MIGO's screen.Even i used EXPORT/IMPORT to capture data but it didn't help me.
2. It is going again to same badi MB_DOCUMENT_BADI and thus creating a loop which is not required.

Please help !!!

Thanks in advance...

1 REPLY 1

Former Member
0 Kudos
111

Please find below the source code which i am writing for this logic:

For NV-<Item-code> having movement type 101 ,call ZMMFM_NONVALUE_MIGO in Update task:

DATA: lt_item           TYPE TABLE OF bapi2017_gm_item_create,
lt_bapi_ser      
TYPE TABLE OF bapi2017_gm_serialnumber,
lt_return        
TYPE TABLE OF bapiret2.
*- Work Area Declaration
DATA: ls_header   TYPE bapi2017_gm_head_01,
ls_mseg    
LIKE LINE OF xmseg,
ls_bapi_ser
TYPE bapi2017_gm_serialnumber,
ls_item    
TYPE bapi2017_gm_item_create,
ls_return  
TYPE bapiret2,
ls_mara    
TYPE mara,
ls_serial  
TYPE zmms_serial.
*- Local Variable Declaration
DATA: lv_nonmblnr TYPE mkpf-mblnr,
lv_nonyear 
TYPE mseg-gjahr,
lv_mblnr   
TYPE mseg-mblnr,
lv_gjahr   
TYPE mseg-gjahr.
*- Constants
CONSTANTS: c_nv      TYPE char3    VALUE 'NV-',
c_901    
TYPE bwart    VALUE '901',
c_902    
TYPE bwart    VALUE '902',
c_321    
TYPE bwart    VALUE '321',
c_101    
TYPE bwart    VALUE '101',
c_102    
TYPE bwart    VALUE '102',
c_105    
TYPE bwart    VALUE '105',
c_106    
TYPE bwart    VALUE '106',
c_322    
TYPE bwart    VALUE '322',
c_543    
TYPE bwart    VALUE '543',
c_544    
TYPE bwart    VALUE '544',
c_545    
TYPE bwart    VALUE '545',
c_546    
TYPE bwart    VALUE '546',
c_x      
TYPE char1    VALUE 'X',
c_migo   
TYPE sy-tcode VALUE 'MIGO',
c_migo_gr
TYPE sy-tcode VALUE 'MIGO_GR',
c_qa11   
TYPE sy-tcode VALUE 'QA11',
c_05     
TYPE char2    VALUE '05'.

IF ( im_tcode = c_migo OR im_tcode = c_migo_gr ).
*- Goods Movement Header
ls_header
-pstng_date = im_mkpf-budat.
ls_header
-doc_date   = im_mkpf-bldat.
ls_header
-ref_doc_no = im_mkpf-mblnr.
*- Goods Movement Item
LOOP AT xmseg INTO ls_mseg.
*- Non valuated will not trigger for movemement type 543 and 544
CHECK ls_mseg-bwart <> '543' AND ls_mseg-bwart <> '544'.
*- Checking if the valuated material is of type YSUP or YCIV
CLEAR: ls_mara.
SELECT SINGLE *
FROM mara
INTO ls_mara
WHERE matnr = ls_mseg-matnr.
CHECK ls_mara-mtart = 'YSUP' OR ls_mara-mtart = 'YCON'.

*- If quality inspection is there then we have to omit the line item
CHECK ls_mseg-insmk = ''.
*- Conversion Exit for Non Valuated Material
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input  = ls_mseg-matnr
IMPORTING
output = ls_item-material.
*- Concatenating with NV-
CONCATENATE c_nv ls_item-material INTO ls_item-material.

ls_item
-plant      = ls_mseg-werks.
*- If storage location in not initial
IF ls_mseg-lgort IS NOT INITIAL.
ls_item
-stge_loc   = ls_mseg-lgort.
ELSE. " We are taking the storage location from PO
SELECT SINGLE lgort
FROM ekpo
INTO ls_item-stge_loc
WHERE ebeln = ls_mseg-ebeln AND
ebelp
= ls_mseg-ebelp.
ENDIF.

ls_item
-entry_qnt  = ls_mseg-menge.
ls_item
-entry_uom  = ls_mseg-meins.
ls_item
-po_number  = ls_mseg-ebeln.
ls_item
-po_item    = ls_mseg-ebelp.
ls_item
-ref_doc    = ls_mseg-mblnr.
ls_item
-ref_doc_it = ls_mseg-zeile.
ls_item
-ref_doc_yr = ls_mseg-mjahr.

IF ls_mseg-bwart = c_101 OR ls_mseg-bwart = c_105 OR
ls_mseg
-bwart = c_321 OR ls_mseg-bwart = c_545.
ls_item
-move_type  = c_901. " Creation movement Type

ELSEIF ls_mseg-bwart = c_102 OR ls_mseg-bwart = c_106 OR
ls_mseg
-bwart = c_322 OR ls_mseg-bwart = c_546.
ls_item
-move_type  = c_902. " Cancellation movement type
ENDIF.

APPEND ls_item TO lt_item.
CLEAR:ls_item.
"Assign serial number for line item of NV material
LOOP AT t_serial INTO ls_serial WHERE item_no = ls_mseg-zeile.
ls_bapi_ser
-matdoc_itm = ls_serial-item_no.
ls_bapi_ser
-serialno   = ls_serial-serial_no.
APPEND ls_bapi_ser TO lt_bapi_ser.
CLEAR:ls_bapi_ser.
ENDLOOP.
ENDLOOP.

IF lt_item IS NOT INITIAL AND lt_bapi_ser IS NOT INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header      
= ls_header
goodsmvt_code        
= c_05 “Movement code is 05 for 101 MVT Type
IMPORTING
materialdocument     
= lv_nonmblnr
matdocumentyear      
= lv_nonyear
TABLES
goodsmvt_item        
= lt_item
goodsmvt_serialnumber
= lt_bapi_ser
return                = lt_return.
IF lt_return IS NOT INITIAL.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE ls_return-message TYPE 'E'.
ENDIF.
ENDIF.
ELSEIF lt_item IS NOT INITIAL AND lt_bapi_ser IS INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header      
= ls_header
goodsmvt_code        
= c_05
IMPORTING
materialdocument     
= lv_nonmblnr
matdocumentyear      
= lv_nonyear
TABLES
goodsmvt_item        
= lt_item
*         goodsmvt_serialnumber = lt_bapi_ser
return                = lt_return.
IF lt_return IS NOT INITIAL.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE ls_return-message TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.


For NV-<item code> with movement type 543:

CALL FUNCTION 'ZMMFM_NONVALUE_YFAB' IN BACKGROUND TASK AS SEPARATE UNIT


FUNCTION zmmfm_nonvalue_yfab.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_MKPF) TYPE  MKPF OPTIONAL
*"     VALUE(IM_TCODE) TYPE  SY-TCODE OPTIONAL
*"  TABLES
*"      XMSEG TYPE  TY_T_MSEG OPTIONAL
*"      XMKPF TYPE  TY_T_MKPF OPTIONAL
*"      T_SERIAL TYPE  ZMMT_SERIAL OPTIONAL
*"----------------------------------------------------------------------
*----------------------------------------------------------------------*
*- Declaration
*----------------------------------------------------------------------*
*- Internal Table Declaration
DATA: lt_item           TYPE TABLE OF bapi2017_gm_item_create,
lt_bapi_ser      
TYPE TABLE OF bapi2017_gm_serialnumber,
lt_return        
TYPE TABLE OF bapiret2.

*- Work Area Declaration
DATA: ls_header   TYPE bapi2017_gm_head_01,
ls_mseg    
LIKE LINE OF xmseg,
ls_bapi_ser
TYPE bapi2017_gm_serialnumber,
ls_item    
TYPE bapi2017_gm_item_create,
ls_return  
TYPE bapiret2,
ls_ekko    
TYPE ekko,
ls_mara    
TYPE mara,
ls_serial  
TYPE zmms_serial.

*- Local Variable Declaration
DATA: lv_nonmblnr TYPE mkpf-mblnr,
lv_nonyear 
TYPE mseg-gjahr,
lv_mblnr   
TYPE mseg-mblnr,
lv_gjahr   
TYPE mseg-gjahr.
*- Constants
CONSTANTS: c_nv      TYPE char3    VALUE 'NV-',
c_543    
TYPE bwart    VALUE '543',
c_544    
TYPE bwart    VALUE '544',
c_221    
TYPE bwart    VALUE '221', "Added on 07 June
c_222    
TYPE bwart    VALUE '222', "Added on 07 June
c_x      
TYPE char1    VALUE 'X',
c_migo   
TYPE sy-tcode VALUE 'MIGO',
c_migo_gr
TYPE sy-tcode VALUE 'MIGO_GR',
c_03     
TYPE char2    VALUE '03'.

IF ( im_tcode = c_migo OR im_tcode = c_migo_gr ).
READ TABLE xmkpf INTO im_mkpf INDEX 1.
*- Goods Movement Header
ls_header
-pstng_date = im_mkpf-budat.
ls_header
-doc_date   = im_mkpf-bldat.
ls_header
-ref_doc_no = im_mkpf-mblnr.
*- Goods Movement Item
LOOP AT xmseg INTO ls_mseg.
*     GRN for Non-Valuated material for YFAB type
IF ls_mseg-bwart EQ '543' OR ls_mseg-bwart EQ '544'.
CLEAR ls_ekko.
SELECT SINGLE *
FROM ekko
INTO ls_ekko
WHERE ebeln = ls_mseg-ebeln.
*     Fabrication process
CHECK ls_ekko-bsart EQ 'YFAB'.
*- Checking if the valuated material is of type YSUP
CLEAR: ls_mara.
SELECT SINGLE *
FROM mara
INTO ls_mara
WHERE matnr = ls_mseg-matnr.
CHECK ls_mara-mtart = 'YSUP'.

*- If quality inspection is there then we have to omit the line item
CHECK ls_mseg-insmk = ''.
*- Conversion Exit for Non Valuated Material
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input  = ls_mseg-matnr
IMPORTING
output = ls_item-material.
*- Concatenating with NV-
CONCATENATE c_nv ls_item-material INTO ls_item-material.

ls_item
-plant      = ls_mseg-werks.
ls_item
-stge_loc   = ls_mseg-lgort.
ls_item
-entry_qnt  = ls_mseg-menge.
ls_item
-entry_uom  = ls_mseg-meins.
ls_item
-po_number  = ls_mseg-ebeln.
ls_item
-po_item    = ls_mseg-ebelp.
CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
EXPORTING
input  = ls_mseg-ps_psp_pnr
IMPORTING
output = ls_item-wbs_elem.

CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
EXPORTING
input  = ls_mseg-ps_psp_pnr
IMPORTING
output = ls_item-val_wbs_elem.

ls_item
-ref_doc    = ls_mseg-mblnr.
ls_item
-ref_doc_it = ls_mseg-zeile.
ls_item
-ref_doc_yr = ls_mseg-mjahr.

IF ls_mseg-bwart = c_543.
ls_item
-move_type  = c_221. " Creation movement Type

ELSEIF ls_mseg-bwart = c_544.
ls_item
-move_type  = c_222. " Cancellation movement type
ENDIF.

APPEND ls_item TO lt_item.
CLEAR:ls_item.

CLEAR :ls_serial,ls_bapi_ser.
"Assign serial number for line item of NV material
LOOP AT t_serial INTO ls_serial WHERE item_no = ls_mseg-zeile.
ls_bapi_ser
-matdoc_itm = ls_serial-item_no.
ls_bapi_ser
-serialno   = ls_serial-serial_no.
APPEND ls_bapi_ser TO lt_bapi_ser.
CLEAR:ls_bapi_ser,ls_serial.
ENDLOOP.
ENDIF.
ENDLOOP.

IF lt_item IS NOT INITIAL AND lt_bapi_ser IS NOT INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header      
= ls_header
goodsmvt_code        
= c_03  “Movement code is 03 for 543 MVT Type
IMPORTING
materialdocument     
= lv_nonmblnr
matdocumentyear      
= lv_nonyear
TABLES
goodsmvt_item        
= lt_item
goodsmvt_serialnumber
= lt_bapi_ser
return                = lt_return.

IF lt_return IS NOT INITIAL.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE ls_return-message TYPE 'E'.
ENDIF.
ENDIF.

ELSEIF lt_item IS NOT INITIAL AND lt_bapi_ser IS INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header 
= ls_header
goodsmvt_code   
= c_03
IMPORTING
materialdocument
= lv_nonmblnr
matdocumentyear 
= lv_nonyear
TABLES
goodsmvt_item   
= lt_item
return           = lt_return.

IF lt_return IS NOT INITIAL.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE ls_return-message TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR:ls_header.
REFRESH: lt_item,lt_return,lt_bapi_ser,t_serial.
ENDFUNCTION.


Please check...