Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI error for mvmt types 201 and 202

Hi all,

I'm using a bapi BAPI_GOODSMVT_CREATE for the movement type 201 and 202 with the gm_code = '03' for the transaction mb11- Goods movement. But it returns an error u201D Account 400000 requires an assignment to a CO object u201D...I'm unable to resolve this one....I have attached the code below. Please help me in fixing this issue...

if sy-subrc = 0.

*

loop at it_mchb into wa_mchb.

if wa_mchb-clabs gt 0.

clear wa_header.

wa_header-pstng_date = sy-datum. " fill header data

wa_header-doc_date = sy-datum.

wa_code-gm_code = '03'. "fill code data

clear wa_item.

wa_item-material = wa_mchb-matnr. " fillitem data

wa_item-plant = wa_mchb-werks.

wa_item-stge_loc = wa_mchb-lgort.

wa_item-batch = wa_mchb-charg.

wa_item-entry_qnt = wa_mchb-clabs.

wa_item-move_type = '201'.

  • wa_item-entry_uom = wa_mchb-meins.

append wa_item to it_item.

elseif wa_mchb-clabs lt 0.

clear wa_header.

wa_header-pstng_date = sy-datum. " fill header data

wa_header-doc_date = sy-datum.

wa_code-gm_code = '03'. "fill code data

clear wa_item.

wa_item-material = wa_mchb-matnr. " fillitem data

wa_item-plant = wa_mchb-werks.

wa_item-stge_loc = wa_mchb-lgort.

wa_item-batch = wa_mchb-charg.

wa_item-entry_qnt = wa_mchb-clabs.

wa_item-move_type = '202'.

  • wa_item-entry_uom = wa_mchb-meins.

append wa_item to it_item.

endif.

endloop.

clear lv_lin.

describe table it_item lines lv_lin.

if lv_lin = 0.

write : / 'No records found'.

endif.

call function 'BAPI_GOODSMVT_CREATE'

exporting

goodsmvt_header = wa_header

goodsmvt_code = wa_code

importing

materialdocument = lv_matdoc

tables

goodsmvt_item = it_item

return = it_return.

if it_return is initial. " if record created successfully

call function 'BAPI_TRANSACTION_COMMIT'. " commit work

write : / lv_matdoc, 'IS CREATED SUCCESSFULLY' color 5.

loop at it_item into wa_item.

write : / 'Mat :', wa_item-material,'bat :', wa_item-batch.

endloop.

else. " if record is not created successfylly

loop at it_return into wa_return.

write : / wa_return-message color 6.

endloop.

uline.

endif.

else.

write : / 'No Records found' color 7.

endif. " gt_s035 is not initial

Edited by: Arunmozhi_06 on May 30, 2011 12:48 PM

Former Member
replied

Hi,

Did you passing the leading 0's in the cost center field?

and check the below coding..


* Structures for BAPI
  data: gm_header  type bapi2017_gm_head_01.
  data: gm_code    type bapi2017_gm_code.
  data: gm_headret type bapi2017_gm_head_ret.
  data: gm_item    type table of
                   bapi2017_gm_item_create with header line.
  data: gm_return  type bapiret2 occurs 0.
  data: gm_retmtd  type bapi2017_gm_head_ret-mat_doc.
 
  clear: gm_return, gm_retmtd. refresh gm_return.
 
  perform show_status using 'Scrapping(551) Material'.
 
* Setup BAPI header data.
  gm_header-pstng_date = sy-datum.
  gm_header-doc_date   = sy-datum.
  gm_code-gm_code      = '06'.                              " MB11
 
* Write 551 movement to table
  clear gm_item.
  move '551'        to gm_item-move_type     .
  move xresb-matnr  to gm_item-material.
  move p_bdmng      to gm_item-entry_qnt.
  move xresb-meins  to gm_item-entry_uom.
  move xresb-werks  to gm_item-plant.
  move xresb-lgort  to gm_item-stge_loc.
  move p_grund      to gm_item-move_reas.
 
* Determine cost center per plant
  case xresb-werks.
    when '0004'.
      move '0000041430' to gm_item-costcenter."pass leading zero's in the cost center field
    when '0006'.
      move '0000041630' to gm_item-costcenter.
    when '0007'.
      move '0000041731' to gm_item-costcenter.
    when '0008'.
      move '0000041830' to gm_item-costcenter.
  endcase.
 
  append gm_item.
 
* Call goods movement BAPI
  call function 'BAPI_GOODSMVT_CREATE'
       EXPORTING
            goodsmvt_header  = gm_header
            goodsmvt_code    = gm_code
       IMPORTING
            goodsmvt_headret = gm_headret
            materialdocument = gm_retmtd
       TABLES
            goodsmvt_item    = gm_item
            return           = gm_return.

Maybe there is some config missing for your cost center, or maybe something missing in your code. check above.

Regards,

Dhina,..

Edited by: Dhina DMD on May 31, 2011 8:02 AM

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question