Sunday, June 22, 2008

BAPI For Goods Movement

BAPI FOR GOODS REECIPT FOR FOC MATERIAL
Bapi example for goods movement 511


We have a requirement to make a z-transaction to receive material on free of goods .technically FOC material has 511 movement in t-mb1c , FOC material comes without any reference to purchase order but against a vendor code..

There were two technical solution one was to make BDC and another was to find a suitable BAPI for goods receipt.
BAPIs are always preferred as they have standard coding checks while posting the document .Also BAPIs have a test run environment which checks for any kind of error before posting .To sum up we found BAPI for FOC “BAPI_GOODSMVT_CREATE ”.
T-CODE BAPIà MATERIAL MANAGEMENT à INVENTORY MANAGEMENT à GOODS RECEIPT à CREATE FROM DATA SEE THE F.M.

In this document I am only considering only that aspects(technical fields and implementations) of BAPI which I used as per my requirement. In my case I have a gate entry before Goods receipt for FOC , based on Gate entry number number we have to make BAPI.

Lets talk about the structure of BAPI: -
1. Goods movement header: This structure contains the header data of the material document that is to be created. PSTNG_DATE : Date which is used when entering the document in Financial Accounting or Controlling. Value = sy-datum. DOC_DATE: The document date is the date on which the original document was issued. Value = Gate entry bill date. REF_DOC_NO: The reference document number can contain the document number of the customer/vendor. However it may contain a different value. Value = bill no of vendor as on gate entry. BILL_OF_LADING: this field doesn’t appear in t-mb1c but while posting data this filed is capture in mkpf , so we decided to pass gate entry number to this field so as to make record that goods receipt for this gate entry has been made. HEADER_TXT: Manually input by the user.
2. Goods Movement Code: This parameter transfers the new key assignment of the GM_CODE to the relevant transactions in Inventory Management. Assign code to transaction for BAPI goods movement. Indicates the assignment of the code for the R/3 transaktionfor BAPIs for goods movements.
Dependencies:Using this method, the system does not support goods movements that are initiated by other application components. These include:
· Goods issue for delivery
· Completion confirmation in production
· Usage decision in QM
GM_CODE: 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:
GM_Code 01: Goods receipt for purchase order
GM_Code 02: Goods receipt for production order
GM_Code 03: Goods issue
GM_Code 04: Transfer posting
GM_Code 05: Other goods receipts
GM_Code 06: Reversal of goods movements
GM_Code 07: Subsequent adjustment to a subcontract order
In our case GM_CODE = ‘05’
3. TESTRUN = SPACE (FOR LIVE POSTING) / ‘X’ FOR TEST CASE FOR CHECKING ANY ERROR BEFORE POSTING.
4. Goods movement Item:
MATERIAL: From Gate Entry Number , multiple records of material PLANT: input value STGE_LOC: input . MOVE_TYPE = '511'.
VENDOR = LIFNR_1. "lifnr in format 000002502
ITEM_TEXT = input
ENTRY_QNT = equals gate entry material quantity but in changed mode for goods receipt.
ENTRY_UOM = MARA-MEINS
5 .GOODS MOVEMENT HEADER : This structure transfers the fields that are filled to the initiator when the material document was successfully posted.
MAT_DOC : Number of Material Document DOC_YEAR: Material Document Year
6 .RETURN: This table contains the return codes from the method call.
Default : There are numerous error messages, which cannot be explained in detail here. If errors occured during this method, the "Return" table is filled. Note that errors at header level are characterized by an item number =0. If the method was carried out without errors occuring, the "Return" table is reset to empty.
MOVE DATA OF RETURN INTO ITAB_RETUNR AND WRITE TO LIST.
NOTE: WHEN BAPI IS SUCCESSFUL WE MUST USE “COMMIT WORK*******************SAMPLE CODE***********************
GOODSMVT_HEADER_H-PSTNG_DATE = SY-DATUM.
GOODSMVT_HEADER_H-DOC_DATE = BLDAT.
GOODSMVT_HEADER_H-REF_DOC_NO = LFBNR .
GOODSMVT_HEADER_H-GR_GI_SLIP_NO = MBLNR.
GOODSMVT_HEADER_H-BILL_OF_LADING = MBLNR.
GOODSMVT_HEADER_H-HEADER_TXT = HEADER_TXT.

GOODSMVT_ITEM_I-PLANT = PLANT.
GOODSMVT_ITEM_I-STGE_LOC = STGE_LOC.
GOODSMVT_ITEM_I-MOVE_TYPE = '511'.

GOODSMVT_ITEM_I-VENDOR = LIFNR_1. "lifnr in format 000002502

LOOP AT ITAB.
GOODSMVT_ITEM_I-MATERIAL = ITAB-MATNR.
GOODSMVT_ITEM_I-ENTRY_QNT = ITAB-ENTRY_QNT.
GOODSMVT_ITEM_I-ITEM_TEXT = ITAB-MENGE.
SELECT SINGLE * FROM MARA WHERE MATNR = ITAB-MATNR.
IF SY-SUBRC = 0.
GOODSMVT_ITEM_I-ENTRY_UOM = MARA-MEINS.
ENDIF.
APPEND GOODSMVT_ITEM_I.
ENDLOOP.
GOODSMVT_CODE_H-GM_CODE = '05'.
TESTRUN_H = SPACE.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GOODSMVT_HEADER_H
GOODSMVT_CODE = GOODSMVT_CODE_H
* TESTRUN = 'X'
IMPORTING
* GOODSMVT_HEADRET =
MATERIALDOCUMENT = MATERIALDOCUMENT_O
MATDOCUMENTYEAR = DOC_YEAR
TABLES
GOODSMVT_ITEM = GOODSMVT_ITEM_I
* GOODSMVT_SERIALNUMBER =
RETURN = RETURN_O .


LEAVE TO LIST-PROCESSING.
WRITE:/ MATERIALDOCUMENT_O,
/ DOC_YEAR.
LOOP AT RETURN_O.
WRITE: / RETURN_O-MESSAGE,
/ RETURN_O-MESSAGE_V1,
/ RETURN_O-MESSAGE_V2,
/ RETURN_O-MESSAGE_V3,
/ RETURN_O-MESSAGE_V4.

ENDLOOP.

IF SY-SUBRC NE 0.
COMMIT WORK.
ENDIF.

No comments: