Upload
jalal-mk
View
232
Download
2
Embed Size (px)
Citation preview
BAPI_GOODSMVT_CREATE to post Goods Movement
The following is an ABAP program making used of the BAPI function BAPI_GOODSMVT_CREATE to do Goods Receipts for Purchase Order after importing the data from an external system.
** BAPI TO Upload Inventory Data** GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order* 02 - MB31 - Goods Receipts for Prod Order* 03 - MB1A - Goods Issue* 04 - MB1B - Transfer Posting* 05 - MB1C - Enter Other Goods Receipt* 06 - MB11** Domain: KZBEW - Movement Indicator* Goods movement w/o reference* B - Goods movement for purchase order* F - Goods movement for production order* L - Goods movement for delivery note* K - Goods movement for kanban requirement (WM - internal only)* O - Subsequent adjustment of "material-provided" consumption* W - Subsequent adjustment of proportion/product unit material*report zbapi_goodsmovement.
parameters: p-file like rlgrap-filename default 'c:\sapdata\TEST.txt'.parameters: e-file like rlgrap-filename default 'c:\sapdata\gdsmvterror.txt'.
parameters: xpost like sy-datum default sy-datum.
data: begin of gmhead. include structure bapi2017_gm_head_01.data: end of gmhead.
data: begin of gmcode. include structure bapi2017_gm_code.data: end of gmcode.
data: begin of mthead. include structure bapi2017_gm_head_ret.data: end of mthead.
data: begin of itab occurs 100. include structure bapi2017_gm_item_create.data: end of itab.
data: begin of errmsg occurs 10. include structure bapiret2.data: end of errmsg.
data: wmenge like iseg-menge,
errflag.
data: begin of pcitab occurs 100, ext_doc(10), "External Document Number mvt_type(3), "Movement Type doc_date(8), "Document Date post_date(8), "Posting Date plant(4), "Plant material(18), "Material Number qty(13), "Quantity recv_loc(4), "Receiving Location issue_loc(4), "Issuing Location pur_doc(10), "Purchase Document No po_item(3), "Purchase Document Item No del_no(10), "Delivery Purchase Order Number del_item(3), "Delivery Item prod_doc(10), "Production Document No scrap_reason(10), "Scrap Reason upd_sta(1), "Update Status end of pcitab.
call function 'WS_UPLOAD' exporting filename = p-file filetype = 'DAT'* IMPORTING* FILELENGTH = tables data_tab = pcitab* EXCEPTIONS* FILE_OPEN_ERROR = 1* FILE_READ_ERROR = 2* NO_BATCH = 3* GUI_REFUSE_FILETRANSFER = 4* INVALID_TYPE = 5* OTHERS = 6 .if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. exit.endif.
gmhead-pstng_date = sy-datum.gmhead-doc_date = sy-datum.gmhead-pr_uname = sy-uname.gmcode-gm_code = '01'. "01 - MB01 - Goods Receipts for Purchase Order
loop at pcitab. itab-move_type = pcitab-mvt_type. itab-mvt_ind = 'B'. itab-plant = pcitab-plant. itab-material = pcitab-material. itab-entry_qnt = pcitab-qty. itab-move_stloc = pcitab-recv_loc. itab-stge_loc = pcitab-issue_loc. itab-po_number = pcitab-pur_doc.
itab-po_item = pcitab-po_item. concatenate pcitab-del_no pcitab-del_item into itab-item_text. itab-move_reas = pcitab-scrap_reason.
append itab.endloop.
loop at itab. write:/ itab-material, itab-plant, itab-stge_loc, itab-move_type, itab-entry_qnt, itab-entry_uom, itab-entry_uom_iso, itab-po_number, itab-po_item, pcitab-ext_doc.endloop.
call function 'BAPI_GOODSMVT_CREATE' exporting goodsmvt_header = gmhead goodsmvt_code = gmcode* TESTRUN = ' '* IMPORTING goodsmvt_headret = mthead* MATERIALDOCUMENT =* MATDOCUMENTYEAR = tables goodsmvt_item = itab* GOODSMVT_SERIALNUMBER = return = errmsg .clear errflag.loop at errmsg. if errmsg-type eq 'E'. write:/'Error in function', errmsg-message. errflag = 'X'. else. write:/ errmsg-message. endif.endloop.
if errflag is initial. commit work and wait. if sy-subrc ne 0. write:/ 'Error in updating'. exit. else. write:/ mthead-mat_doc, mthead-doc_year. perform upd_sta. endif.endif.
*---------------------------------------------------------------------** FORM UPD_STA **---------------------------------------------------------------------** ........ **---------------------------------------------------------------------*form upd_sta. loop at pcitab. pcitab-upd_sta = 'X'.
modify pcitab. endloop.
call function 'WS_DOWNLOAD' exporting filename = p-file filetype = 'DAT'* IMPORTING* FILELENGTH = tables data_tab = pcitab* EXCEPTIONS* FILE_OPEN_ERROR = 1* FILE_READ_ERROR = 2* NO_BATCH = 3* GUI_REFUSE_FILETRANSFER = 4* INVALID_TYPE = 5* OTHERS = 6 .
endform.
*--- End of Program
BAPI_GOODSMVT_CREATE - Post goods movements with MB_CREATE_GOODS_MOVEMENTThis documentation is copyright by SAP AG.
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 updatedin the database. The standard system is configured so that the goods movement is posted immediately, without prior simulation.
Ensure that you transfer the data in the same way as it is managed in the database. For example:
Material number 18-character with leading zeros
Batches with uppercase letters
Ensure that the header data of the material document includes the posting date for all transactions/events listed below. Populate the PSTNG_DATE field (import structure GOODSMVT_HEADER) in the interface BAPI2017_GM_HEAD_01 for this purpose.
Example
Notes
From Release ERP2005 onwards, it is possible to populate customers' own fields in database tables using the BAPI, without carrying out a modification.
The enhancements are passed on to the BAPI in a container and can be processed within the BAPI function module.
Technically, this is realized via an extension parameter (ExtensionIn) (see below or tab page 'Tables -> Long Text') .
Authorization check,,,,
In the MM Inventory Management component, the method does not perform any authorization checks.
Note that the system can also check authorization objects of other applications during the posting of a goods movement, depending on the business transaction.
Transfer
The following information about the material document that is to be created is passed on to the method:
A structure with the 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 made by the function module MB_CREATE_GOODS_MOVEMENT.
Confirmations
Messages are returned in the Return parameter. The parameter documentation shows the return codes and their meanings.
Further information
Which fields must be populated during the various transactions/events?
The following example scenarios illustrate which fields have to be populated for which business transactions/events (code).
There are the following types of transactions/events:
1. GM_Code 01: Goods receipt for purchase order2. GM_Code 02: Goods receipt for production order3. GM_Code 03: Goods issue4. GM_Code 04: Transfer posting5. GM_Code 05: Other goods receipt6. GM_Code 06: Reversal of goods movements7. GM_Code 07: Subsequent adjustment with regard to a subcontract order
Entering the movement indicator
Depending on the transaction, you must enter the following in the movement indicator field:
GM_Code 01 (Goods receipt for purchase order): B
GM_Code 02 (Goods receipt for production order): F
For all other transactions, leave the field blank.
For 1: GM_Code 01: Goods receipt for purchase order
Purchase order known
The following fields must be populated:
o Purchase order
o Purchase order item
o Movement type
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry or quantity proposal
The following fields may have to be populated (this is not a complete list):
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and no automatic batch assignment has been set up)
o Storage location (if no storage location us specified in the purchase order item)
The following fields can be populated (this is not a complete list):
o Stock type
o Item text
o Unloading point
o Delivery completed indicator
The following fields must not be populated (this is not a complete list):
o Account assignment fields (the account assignment is adopted from the purchase order)
o Reservation
o Receiving/issuing material
o Receiving/issuing plant
o Receiving/issuing storage location
In the case of a purchase order item with the item category "subcontracting", only the GR item is to be passed on in the interface. The GI items are determined automatically in the system.
Purchase order unknown: Shipping notification known
The following fields must be populated:
o Delivery
o Delivery item
o Movement type
Other fields as under "Purchase order known". The system determines the relevant purchase order item via the delivery/delivery item.
Purchase order unknown: Purchase order is to be created automatically
The following fields must be populated:
o Material number
o Plant
o Storage location
o Vendor
o Movement type
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry
The following fields may have to be populated (this is not a complete list):
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and batches are not assigned automatically)
The following fields can be populated (this is not a complete list):
o Stock type
o Item text
o Unloading point
You cannot populate the following fields (this is not a complete list):
o Account assignment fields (automatic creation of purchase order items with account assignment is not supported)
o Reservation
o Receiving/issuing material
o Receiving/issuing plant
o Receiving/issuing storage location
Purchase order unknown: A purchase order is not to be created
The following fields must be populated:
o Material number
o Plant
o Storage location
o Vendor
o Movement type
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry
The following fields may have to be populated in some cases (this is not a complete list)
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and automatic assignment of batch numbers is not set)
The following fields can be populated (this is not a complete list)
o Special stock indicator
o Item text
o Unloading point
o Goods recipient
The following fields cannot be populated (this is not a complete list)
o Account assignment fields (automatic creation of purchase order items with account assignment is not supported)
o Reservation
o Receiving/issuing material
o Receiving/issuing plant
o Receiving/issuing storage location
o Receiving/issuing batch
The input combinations listed above for the GM_CODE 01 can be combined within an input table so thatthey can be posted in a material document. Items can also be posted for different purchase orders, provided that all the purchase orders relate to the same vendor.
Transfer of subcontracting components
When the end product (ordered material of a subcontract order) is posted using movement type 101, thepopulated unique identification of the document line (LINE_ID) is additionally needed for the transfer of the subcontracting components. More information on LINE_ID and PARENT_ID The following fields must be populated for the components:
o Unique identification of the document line
o Identification of the immediately superordinate line
o Material number
o Plant
o Storage location
o Quantity in unit of entry
The following fields can be filled for the components:
o All other fields in the method that are included in this list.
The following fields cannot be populated for the components:
o 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:
o REF_DOC_IT (LFPOS): Item of a reference document
o REF_DOC (LFBNR): Document number of a reference document
o REF_DOC_YR (LFBJA): Fiscal year of a reference document
Only if you transfer these fields can you be sure that the link to the original goods movement is retained.
For 2 GM_Code 02: Goods receipt for production order
The following fields have to be populated:
o Order
o Movement type
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry or quantity proposal
The following fields may have to be populated in some cases (this is not a complete list):
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and automatic batch number assignment is not set)
o Storage location (if storage location has not been specified in the order)
The following fields can be populated (this is not a complete list):
o Order item (co-product)
o Stock type
o Item text
o Unloading point
o "Delivery completed" indicator
The following fields cannot be populated (this is not a complete list):
o Account assignment fields (the account assignments are adopted from the purchase order)
o Reservation
o Receiving/issuing material
o Receiving/issuing plant
o Receiving/issuing storage location
o Receiving/issuing batch
For 3 GM_Code 03: Goods issue
Goods issue without reference to a reservation
The following fields must be populated:
o Material number
o Plant
o Storage location
o Movement type
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry
The following fields may have to be populated in some cases (this is not a complete list):
o Special stock (e.g. sales order, project, vendor etc.)
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and automatic batch number assignment is not set)
o Account assignment fields
The following fields can be populated (this is not a complete list):
o Special stock indicator
o Item text
o Unloading point
o Goods recipient
The following fields cannot be populated (this is not a complete list):
o Reservation
o Receiving/issuing material
o Receiving/issuing plant
o Receiving/issuing storage location
o Receiving/issuing batch
Goods issue with reference to a reservation
The following fields must to be populated:
o Reservation number
o Reservation item
o Record type of the reservation
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry
The following fields may have to be populated in some cases (this is not a complete list):
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and automatic batch number assignment is not set)
o Storage location (if not planned in the reservation)
The following fields can be populated (this is not a complete list):
o Special stock indicator
o Item text
o Unloading point
o Goods recipient
The following fields cannot be populated (this is not a complete list):
o Movement type
o Material
o Plant
o Account assignment fields
For 4 GM_Code 04: Transfer posting
Transfer posting without reference to a reservation
The following fields must be populated:
o Material number
o Plant
o Storage location
o Movement type
o Movement indicator
o Quantity in unit of entry
o ISO code unit of measurement for unit of entry
The following fields may have to be populated in some cases (this is not a complete list):
o Receiving material
o Receiving plant
o Receiving storage location
o Receiving batch (if material is handled in batches and you want to change batches)
o Receiving/issuing special stock (e.g. sales order, project, vendor etc.)
o Minimum shelf life expiration date (if set up in the system)
o Reason for movement (if set up in the system)
o Batch (if the material is handled in batches and automatic batch number assignment is not set)
The following fields can be populated (this is not a complete list):
o Special stock indicator
o Item text
o Account assignment fields (for automatic posting lines: expense/income from stock transfer)
The following fields cannot be populated (this is not a complete list):
o 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 populate the BAPI_GM_ITEM_CREATE-XSTOBfield in the interface (import table GOODSMVT_ITEM). In this case, thesystem 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 Cancelmethod) you can only transfer the BAPI_GM_ITEM_CREATE_XSTOB field if itis populated. 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 with regard to a subcontract order
Ordered material of subcontract order
The following fields must be populated:
o Unique identification of document line (can be freely assigned)
o Posting date in document header
o Document number of purchasing document
o Item number of purchasing document
o Material number,,,,
o Plant,,,,
o Movement type (select movement type 121)
o 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 must be populated:
o Unique identification of document line (can be freely assigned)
o Identification of the immediately superordinate line
o Plant
o Material number,,,,
o Quantity in unit of entry; can also be negative
The following fields can be populated:
o Storage location
o All other fields in the method that are included in this list.
The following fields may not be populated:
o 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:
o REF_DOC_IT (LFPOS): Item of a reference document
o REF_DOC (LFBNR): Document number of a reference document
o REF_DOC_YR (LFBJA): Fiscal year of a reference document
Only if you transfer these fields can you be sure that the link to the original goods movement is retained.
Parameters
EXTENSIONINGOODSMVT_CODEGOODSMVT_HEADERGOODSMVT_HEADRETGOODSMVT_ITEMGOODSMVT_REF_EWMGOODSMVT_SERIALNUMBERGOODSMVT_SERV_PART_DATAMATDOCUMENTYEARMATERIALDOCUMENTRETURNTESTRUN