551 Scrap Example For BAPI_GOODSMVT_CREATE

Have a requirement to create a 551 movement to do a GI to scrap. However, since this requires a cost center I can't get BAPI_GOODSMVT_CREATE to work. Is there any other function or BAPI to call to avoid doing it via call transaction? 

Resolution:

I have a program that has been working good for some time. Here is the code. Check below:

* 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.
    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.

  if not gm_retmtd is initial.
    commit work and wait.
    call function 'DEQUEUE_ALL'.
  else.
    commit work and wait.
    call function 'DEQUEUE_ALL'.
    message i013.
  endif.

ABAP Tips

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.