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

Goods Movement reversal using BAPI_GOODSMVT_CREATE - Multiple Times

0 Likes
7,659

Hi All,

I am using BAPI_GOODSMVT_CREATE to post Goods Receipts and also to reverse the Goods Receipt.

I execute the following scenario against the same PO

1) Post a Goods Receipt with Qty 1kg - Success

2) Reverse the Goods Receipt - Success

3) Again Post a Good Receipts with Qty 3kg - Success

4) Reverse the Goods Receipt - Failure

After step 4 it gives be error:

"Deficit of PU GR quantity 3 KG"

The BAPI does not work for multiple reversals against the same PO.

I have also specified the Material Doc no and year for reversal.

Any Suggestions?

Regards,

Ameya

8 REPLIES 8
Read only

0 Likes
3,128

I managed to solve the issue but by using the BAPI_GOODSMVT_CANCEL which works like gem in case of multiple reversals against one PO

Just one query Is there a function difference between Cancellation of PO and Reversal of PO.

Or is it just the difference in usages of the two BAPI's

Thanks,

Ameya

Read only

0 Likes
3,128

Can you explain how did you use BAPI_GOODSMVT_CANCEL against the same PO. What values did you pass and if possible can you show the code

Thanks,

Ash

Read only

Former Member
0 Likes
3,128

Hi Ameya

Go thru the BAPI_GOODSMVT_CREATE code--

**reward if help.**

REPORT ZRICH_0001 .

  • 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 WITH HEADER LINE.

DATA: GM_RETMTD TYPE BAPI2017_GM_HEAD_RET-MAT_DOC.

CLEAR: GM_RETURN, GM_RETMTD. REFRESH GM_RETURN.

  • Setup BAPI header data.

GM_HEADER-PSTNG_DATE = SY-DATUM.

GM_HEADER-DOC_DATE = SY-DATUM.

GM_CODE-GM_CODE = '04'. " MB1A

  • Write 971 movement to table

CLEAR GM_ITEM.

MOVE '412' TO GM_ITEM-MOVE_TYPE .

MOVE 'Q' TO GM_ITEM-SPEC_STOCK.

MOVE '3800533484' TO GM_ITEM-MATERIAL.

MOVE '1' TO GM_ITEM-ENTRY_QNT.

*MOVE 'PC' TO GM_ITEM-ENTRY_UOM.

MOVE '1060' TO GM_ITEM-PLANT.

MOVE '0007' TO GM_ITEM-STGE_LOC.

*MOVE '0901' TO GM_ITEM-MOVE_REAS.

MOVE 'P203601001' TO GM_ITEM-WBS_ELEM.

MOVE 'P203601001' TO GM_ITEM-VAL_WBS_ELEM.

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

ENDIF.

WRITE:/ GM_RETMTD.

LOOP AT GM_RETURN.

WRITE:/ GM_RETURN.

ENDLOOP.

check the BAPI_GOODSMVT_CREATE.

Functionality

You can use this method to create a material document for a goods movement.

You can only create one material document each time you call up the method.

You can use a simulation function before posting the goods movement to check how the data is updated in the database. The standard system is configured so that the goods movement is posted immediately without simulating beforehand.

Ensure that you transfer the data in the same way as it is run in the database, for example,

Material number 18-figure with leading zeros

Batches with uppercase letters

Note that for all transactions/events listed below, the posting date is entered in the header data of the material document. In the BAPI2017_GM_HEAD_01 interface, fill the PSTNG_DATE (import structure GOODSMVT_HEADER) field.

Notes

Authorization check check

In the MM Inventory Management component, the method does not execute any authorization checks.

Note that during a posting of a goods movement, depending on the business transaction of the system, authorization objects of other applications can also be checked.

Transfer

The following information about the material document that is to be created is transferred to the method:

a structure with header data

a structure with the code for the movement

a table with the item data

a table with the serial numbers

The posting is carried out in the SAP R/3 via the MB_CREATE_GOODS_MOVEMENT function module.

Confirmations

Messages are returned in the Return parameter. The parameter documentation shows the return codes and their meanings.

Further Information

The method can only carry out your function if no error messages were generated in the Return table. This is the case if the header data and all the items were processed successfully.

Transaction control is not implemented. The calling program therefore has to execute the Commit Work itself after this method has been successfully called (in other words, if no errors were reported in the Return parameter).

Which fields have to be filled during the various transactions/ events?

The following sample scenarios demonstrate which fields have to be filled for which business transactions/events (code).

There are the following types of transactions/events:

1. GM_Code 01: Goods receipt for purchase order

2. GM_Code 02: Goods receipt for production order

3. GM_Code 03: Goods issue

4. GM_Code 04: Transfer posting

5. GM_Code 05: Other goods receipts

6. GM_Code 06: Reversal of goods movements

7. GM_Code 07: Subsequent adjustment to a subcontract order

Entering the movement indicator

Depending on the transaction, you must enter the following in the movement indicator:

GM_Code 01 (Goods receipt for purchase order): B

GM_Code 02 (Goods receipt for production order): F

For all other transactions, you leave the field blank.

For 1: GM_Code 01: Goods receipt for purchase order

Purchase order known

The following fields have to be filled:

Purchase order

Purchase order item

Movement type

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry or

quantity proposal

The following fields may have to be filled in some cases (incomplete listing):

Shelf life expiration date (if it has been configured like this in the system)

Reason for movement (if it has been configured like this in the system)

Batch (if the material is handled in batches and batch numbers are not assigned automatically)

Storage location (if a storage location has not been specified in the purchase order item)

The following fields can be filled (incomplete listing):

Stock type

Item text

Unloading point

Delivery completed indicator

You cannot fill the following fields (incomplete listing):

Account assignment fields (account assignment is adopted from the purchase order)

Reservation

Receiving/issuing material

Receiving/issuing plant

Receiving/issuing storage location

In the case of a purchase order item with the "subcontracting" item category, only the GR item in the interface is to be transferred. The system automatically determines GI items.

Purchase order unknown: Shipping notification known

The following fields have to be filled:

Delivery

Delivery item

Movement type

Other fields, such as those under "Purchase order known". The system determines the relevant purchase order item via the delivery/delivery item.

Purchase order unknown: Purchase order should be created automatically

The following fields have to be filled:

Material number

Plant

Storage location

Vendor

Movement type

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry

The following fields may have to be filled in some cases (incomplete listing):

Shelf life expiration date (if it has been configured like this in the system)

Reason for movement (if it has been configured like this in the system)

Batch (if the material is handled in batches and batches are not assigned automatically)

The following fields can be filled (incomplete listing):

Stock type

Item text

Unloading point

You cannot fill the following fields (incomplete listing):

Account assignment fields (automatic creation of purchase order items with account assignment is not supported)

Reservation

Receiving/issuing material

Receiving/issuing plant

Receiving/issuing storage location

Purchase order unknown: A purchase order should not be created

The following fields have to be filled:

Material number

Plant

Storage location

Vendor

Movement type

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry

The following fields may have to be filled in some cases (incomplete listing):

Shelf life expiration date (if it has been configured like this)

Reason for movement (if it has been configured like this)

Batch (if the material is handled in batches and automatic assignment of batch numbers is not set)

The following fields can be filled (incomplete listing):

Special stock indicator

Item text

Unloading point

Goods recipient

The following fields cannot be filled (incomplete listing):

Account assignment fields (automatic creation of purchase order items with account assignment is not supported)

Reservation

Receiving/issuing material

Receiving/issuing plant

Receiving/issuing storage location

Receiving/issuing batch

The input combinations listed above for the GM_CODE 01 can be combined within an input table so that they can be posted in a material document. Items can also be posted for different purchase orders, provided that all the purchase orders refer to the same vendor.

Transfer of subcontracting components

During the posting of the ordered material of a subcontract order with movement type 101, for the transfer of the subcontracting components, the filled unique identification of the document line (LINE_ID) is also required.

More information on LINE_ID and PARENT_ID

The following fields have to be filled for the components:

Unique identification of the document line

Identification of the immediately superior line

Material number

Plant

Storage location

Quantity in unit of entry

The following fields can be filled for the components:

All other fields in the method that are included in this list.

The following fields cannot be filled for the components:

All fields that are not included in the list above. The movement indicator must be initial.

Additional fields in goods-receipt-based invoice verification

When you post a goods receipt to purchase order with movement type 102, an issue with reference to a previously posted goods issue, the following fields must also be transferred:

REF_DOC_IT (LFPOS): Item of a reference document

REF_DOC (LFBNR): Document number of a reference document

REF_DOC_YR (LFBJA): Fiscal year of a reference document

Only when you transfer these fields is it guaranteed that the reference to the original goods movement stay the same.

For 2 GM_Code 02: Goods receipt for production order

The following fields have to be filled:

Order

Movement type

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry or

quantity proposal

The following fields may have to be filled in some cases (incomplete listing):

Shelf life expiration date (if the system has been configured like this)

Reason for movement (if the system has been configured like this)

Batch (if the material is handled in batches and automatic batch number assignment is not set)

Storage location (if storage location has not been specified in the order)

The following fields can be filled (incomplete listing):

Order item (co-product)

Stock type

Item text

Unloading point

"Delivery completed" indicator

The following fields cannot be filled (incomplete listing):

Account assignment fields (the account assignments are adopted from the purchase order)

Reservation

Receiving/issuing material

Receiving/issuing plant

Receiving/issuing storage location

Receiving/issuing batch

For 3 GM_Code 03: Goods issue

Goods issue without reference to a reservation

The following fields have to be filled:

Material number

Plant

Storage location

Movement type

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry

The following fields may have to be filled in some cases (incomplete listing):

Special stock (e.g. sales order, project, vendor etc.)

Shelf life expiration date (if the system is configured like this)

Reason for movement (if the system has been configured like this)

Batch (if the material is handled in batches and automatic batch number assignment is not set)

Account assignment fields

The following fields can be filled (incomplete listing):

Special stock indicator

Item text

Unloading point

Goods recipient

The following fields cannot be filled (incomplete listing):

Reservation

Receiving/issuing material

Receiving/issuing plant

Receiving/issuing storage location

Receiving/issuing batch

Goods issue with reference to a reservation

The following fields have to be filled:

Reservation number

Reservation item

Record type of the reservation

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry

The following fields may have to be filled in some cases (incomplete listing):

Shelf life expiration date (if this has been configured in the system)

Reason for movement (if this has been configured in the system)

Batch (if the material is handled in batches and automatic batch number assignment is not set)

Storage location (if not planned in the reservation)

The following fields can be filled (incomplete listing):

Special stock indicator

Item text

Unloading point

Goods recipient

The following fields cannot be filled (incomplete listing):

Movement type

Material

Plant

Account assignment fields

For 4 GM_Code 04: Transfer posting

Transfer posting without reference to a reservation

The following fields have to be filled:

Material number

Plant

Storage location

Movement type

Movement indicator

Quantity in unit of entry

ISO code unit of measurement for unit of entry

The following fields may have to be filled in some cases (incomplete listing):

Receiving material

Receiving plant

Receiving storage location

Receiving batch (if material is handled in batches and you want to change batches)

Receiving/issuing special stock (e.g. sales order, project, vendor etc.)

Shelf life expiration date (if this has been configured in the system)

Reason for movement (if this has been configured in the system)

Batch (if the material is handled in batches and automatic batch number assignment is not set)

The following fields can be filled (incomplete listing):

Special stock indicator

Item text

Account assignment fields (for automatic posting lines: Expense/income from stock transfer)

The following fields cannot be filled (incomplete listing):

Reservation

Transfer posting with reference to a reservation

See goods issue with reference to a reservation

For 5 GM_Code 05: Other goods receipts

Other goods receipt without reference to a reservation

See goods issue without reference to a reservation

Other goods receipt with reference to a reservation

See goods issue with reference to a reservation

For 6 GM_Code 06: Reversal of goods movements

You can use the Cancel method to reverse goods movements. But you may also want to cancel a goods movement without referring to a material document (see the Cancel method).

If you want to work without referring to the document, you have to fill the field BAPI_GM_ITEM_CREATE-XSTOB in the interface (import table GOODSMVT_ITEM). In this case, the system converts the movement type assigned in the interface to the reversal movement type. Alternatively, you can set the reversal movement type in the interface. In this case, the BAPI_GM_ITEM_CREATE_XSTOB field must be transferred blank.

If you want to cancel a goods movement with reference to a reservation (without using the Cancel method) you can only transfer the field BAPI_GM_ITEM_CREATE_XSTOB if it is filled. Movement types are not transferred when you post with reference to a reservation, as the movement type is contained in the reservation item.

For 7. GM_Code 07: Subsequent adjustment to a subcontract order

Ordered material of subcontract order

The following fields have to be filled:

Unique identification of document line (can be assigned to anything)

Posting date in document header

Document number of purchasing document

Item number of purchasing document

Material number check

Plant check

Movement type (select movement type 121)

Movement indicator (must be O)

Further entries are not allowed. The entry quantity for the ordered material of a subcontract order must be zero.

Components

The following fields have to be filled:

Unique identification of document line (can be assigned to anything)

Identification of the immediately superior line

Plant

Material number check

Quantity in unit of entry; can also be negative

The following fields can be filled:

Storage location

All other fields in the method that are included in this list.

The following fields may not be filled:

All fields that are not in the list above. The movement indicator must be blank.

More information on LINE_ID and PARENT_ID

Additional fields in goods-receipt-based invoice verification

When you post a subsequent adjustment, the following fields must also be transferred:

REF_DOC_IT (LFPOS): Item of a reference document

REF_DOC (LFBNR): Document number of a reference document

REF_DOC_YR (LFBJA): Fiscal year of a reference document

Only when you transfer these fields is it guaranteed that the reference to the original goods movement stays the same.

Read only

0 Likes
3,128

Hi,

But, I did not understand how does this answer my question.

Regards,

Ameya

Read only

0 Likes
3,128

Hi Ameya,

I have one problem with BAPI_GOODSMVT_CANCEL , i just red ur query .. so i wnats to ask one thing.

ie .. i working with cancel BAPI, iam just just executing the BAPI directly for testing. Not implimenting any other program.

For me its asking REASON , how to pass the REASON , dont have any import paramater to pass the REASON code in the CACEL BAPI ..

How to do that pls help me....

Regards,

pandu.

Read only

0 Likes
3,128

Hi,

Movement type specific Reason code setting are done in SPRO inside MM

There's an setting where you can specify whether reason code is mandatory or not.

I do not have an access to SAP server right now, I would be able to give you the full path tomorrow.

Regards,

Ameya

Read only

denisbridger
Explorer
0 Likes
3,128

I have just discovered this issue myself, but unfortunately started with test data that had already be reversed so that I got the deficit of PU GR stock error from the beginning.

I fail to see how this question has been answered as there has not been an explantion of why the BAPI cannot "find" the recieved stock after the first reversal. This is surely a problem in the BAPI itself.

The Cancel method is a superior method for cancelling MatDoc, but in my circumstance it does not have custom processing that was added to the Create method.

Has anyone discovered why the BAPI cannot find the material? Is there an open ticket on this?

Read only

Former Member
0 Likes
3,128

Cancellation is not exactly same as reversal.

technically you can reverse partial qtys but cancellation is always for full quantity and i don't it's functional impact.

you passed materail doc , material year . you should pass materail doc item also.

post with GM code 01 ,

pass all details as like GR for PO with BWART = 102 or any reversal movement type like 110 which is relevant.

then pass below fields as well.

from Mahajan's post:

When you post a goods receipt to purchase order with movement type 102, an issue with reference to a previously posted goods issue, the following fields must also be transferred:

REF_DOC_IT (LFPOS): Item of a reference document

REF_DOC (LFBNR): Document number of a reference document

REF_DOC_YR (LFBJA): Fiscal year of a reference document

quantity calculations:

Get PO history from EKBE and calcuate what qtys can be reversed for given article doc.

for ex:

suppose we have two GRs and their reversals as like below.

( all  fields from EKBE )

for given PO item , we get below details:

BELNRBWARTMENGELFBNR
GR110110GR1
GR210110GR1
GR31022GR1
GR41023GR1
GR51021GR2
GR61026GR2

Now we can have two items in GOODSMVT_ITEM  each for GR1 and GR2

for GR1 we can reverse qty up to 10 - ( 2+ 3) = 5.

likewise for GR2, we can reverse qty up to 10 - (1 + 6) = 3.

Now about PO qty deficit error:

if we don't pass article doc , item and year, BAPI will by default fetch first GR against that PO item and check the qtys which obviously won't match.