Posted: Sat Oct 27, 2007 3:14 pm Post subject: 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.
Code:
*
* 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.
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.
DATA: h_goodsmvt_header LIKE bapi2017_gm_head_01.
DATA: h_goodsmvt_code LIKE bapi2017_gm_code.
DATA: h_goodsmvt_item LIKE bapi2017_gm_item_create
OCCURS 0 WITH HEADER LINE.
DATA: h_goodsmvt_serialnumber LIKE bapi2017_gm_serialnumber
OCCURS 0 WITH HEADER LINE.
*Header data
h_goodsmvt_header-pstng_date = pstng_date.
h_goodsmvt_header-doc_date = doc_date.
h_goodsmvt_header-header_txt = header TEXT
h_goodsmvt_header-ref_doc_no = ref DOC #
*GM_Code 01: Goods receipt for purchase order'.
H_GOODSMVT_CODE = '01'.
*LOOP on item materials
loop AT p_order_goodsmvt WHERE NOT material IS INITIAL.
h_goodsmvt_item-orderid = p_orderid.
h_goodsmvt_item-mvt_ind = p_order_goodsmvt-mvt_ind.
h_goodsmvt_item-move_type = p_order_goodsmvt-move_type.
h_goodsmvt_item-plant = p_plant.
h_goodsmvt_item-stge_loc = p_stge_loc.
h_goodsmvt_item-customer = p_order_goodsmvt-customer.
h_goodsmvt_item-po_number = p_order_goodsmvt-po_number.
h_goodsmvt_item-po_item = p_order_goodsmvt-po_item.
* IF the THERE is AN amount IN the position text fill it into
* amount_lc
if p_order_goodsmvt-item_text = '0.01'.
h_goodsmvt_item-amount_lc = p_order_goodsmvt-item_text.
ENDIF.
* to populate the serial numbers in case the part is serialized
v_matitem = v_matitem + 1.
* SHIFT p_order_goodsmvt-serialno LEFT DELETING LEADING '0'.
IF NOT p_order_goodsmvt-serialno IS INITIAL.
h_goodsmvt_serialnumber-matdoc_itm = v_matitem.
h_goodsmvt_serialnumber-serialno = p_order_goodsmvt-serialno.
APPEND h_goodsmvt_serialnumber.
ENDIF.
IF return_material[] IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = h_x.
ENDIF.
Example 3
Поступление материала к заказу на поставку (Движение 101).
Code:
* Data for BAPI_GOODSMVT_CREATE
DATA: l_gmvt_header TYPE bapi2017_gm_head_01,
l_code TYPE bapi2017_gm_code,
l_gmvt_items LIKE bapi2017_gm_item_create,
lt_gmvt_items LIKE bapi2017_gm_item_create
OCCURS 0 WITH HEADER LINE.
DATA: lt_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
error_occured.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.