Application Development and Automation 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: 
Read only

Question for BAPI_GOODSMVT_CREATE

Former Member
0 Likes
1,574

Hi Experts

I use BAPI_GOODSMVT_CREATE to cancel PO GR(The movetype is 102), then an error happen,the error message is 'Deficit of PU GR quantity 3 EA : 1100000020 3301 0001 Q',But 0001 have 13 EA 1100000020 Unrestricted use. Can you tell me why? Thanks

BR

Chris.

4 REPLIES 4
Read only

vinod_vemuru2
Active Contributor
0 Likes
826

Hi,

U have to use BAPI_GOODSMVT_CANCEL to cancel the GR.BAPI_GOODSMVT_CREATE is to create the document.

Check below sample code. Here u have to pass GR number and fiscal year. It will create cancellation document.

After this u can use ur FM to recreate GR.


FORM reverse_gr.

  DATA: li_return   TYPE STANDARD TABLE OF bapiret2,
        lwa_headret TYPE bapi2017_gm_head_ret,
        lwa_return  TYPE bapiret2,
        l_mblnr     TYPE bapi2017_gm_head_02-mat_doc,
        l_mjahr     TYPE bapi2017_gm_head_02-doc_year.

  CLEAR:   l_mjahr,so_mblnr.
  REFRESH: i_msg[].
  MOVE po_mjahr TO l_mjahr.

  LOOP AT so_mblnr.
    CLEAR:   l_mblnr, lwa_headret.
    REFRESH: li_return[].
    MOVE:    so_mblnr-low TO l_mblnr.

    CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
         EXPORTING
              materialdocument = l_mblnr
              matdocumentyear  = l_mjahr
         IMPORTING
              goodsmvt_headret = lwa_headret
         TABLES
              return           = li_return.

*lwa_headret will contain the cancellation document number. It will be
*INITIAL if cancellation is failed
    CHECK lwa_headret IS INITIAL.
    CLEAR lwa_return.
    LOOP AT li_return  INTO lwa_return
                       WHERE type EQ c_e
                       OR    type EQ c_a.
      CLEAR  wa_msg.
      MOVE   lwa_return-message TO wa_msg-message.
      APPEND wa_msg TO i_msg.
      CLEAR lwa_return.
    ENDLOOP.
    CLEAR so_mblnr.
  ENDLOOP.

ENDFORM.                    " reverse_gr

Hope it is clear.

Thanks,

Vinod.

Read only

Former Member
0 Likes
826

Hi Vinod

I want cancel some of them,not all. So I can't use bapi_goodsmvt_cancel. Is there any way to do that?

I can do it by TCODE MB01 and MIGO, Why the TCODE is ok the BAPI is Error?

BR

Chris

Read only

0 Likes
826

Hi Chris,

This BAPI Will reverse only one document at a time. My requirement was i have to reverse many. U call call this BAPI for which u want to reverse GR

Generally this error we will get if u dont have enough stock in storage location/Plant while creating GR. That is why i asked u to use CANCEL BAPI.

Another way to reverse the GR is Doing BDc for transaction MBST.

But i sugest to use BAPI. Because BDC is already absolete.

What is the problem in using CANCEL BAPI? Get back to me i case u need further info.

Thanks,

Vinod.

Read only

Former Member
0 Likes
826

Sample code.

READ TABLE it_afko INTO wa_afko INDEX 1.

LOOP AT it_resb INTO wa_resb.

READ TABLE it_parts INTO wa_parts WITH KEY flg = 'X'

partno = wa_resb-matnr

itemno = wa_resb-posnr.

IF sy-subrc = 0.

wa_migo-RESERV_NO = wa_resb-rsnum.

wa_migo-RES_ITEM = wa_resb-RSPOS.

wa_migo-RES_TYPE = wa_resb-RSART.

wa_migo-MVT_IND = ''.

wa_migo-ENTRY_QNT = wa_parts-REVERSE_QTY.

wa_migo-XSTOB = 'X'.

SELECT SINGLE ISOCODE FROM T006

INTO wa_migo-ENTRY_UOM_ISO

WHERE MSEHI = wa_parts-unit.

APPEND wa_migo TO it_migo.

ENDIF.

ENDLOOP.

wa_head-PSTNG_DATE = sy-datum.

wa_head-DOC_DATE = sy-datum.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = wa_head

GOODSMVT_CODE = '06'

  • TESTRUN = ' '

IMPORTING

  • GOODSMVT_HEADRET =

MATERIALDOCUMENT = LW_DOCNUM

MATDOCUMENTYEAR = LW_DOCYEAR

TABLES

GOODSMVT_ITEM = it_migo[]

  • GOODSMVT_SERIALNUMBER =

RETURN = IT_MIGO_RETURN[]

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

  • IMPORTING

  • RETURN = IT_MIGO_RETURN[]

.

Regards,

Swarup