02-24-2006 5:53 PM
Hi folks!
I´m from Brazil, and I´m trying to use the BAPI_GOODSMVT_CREATE for create a Subsbsequent Adjustment Purchase Order as in MIGO. In Brazil, when the R/3 system creates a document material, the document number (docnum) is created too. But the BAPI doesn´t create this document number...Can anyone help me? Is this a configuration error?
Sorry my english...
Thanks,
Éder.
02-24-2006 6:21 PM
check this code..
REPORT Z_BAPI_GM .
*
* 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
parameters: p-file like rlgrap-filename default
'c:Norandex-ReynoldsIbcstrans_demo3.txt'.
parameters: xpost like sy-datum default sy-datum.
TABLES : EKKO, EKPO.
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,
code(10), "I code
branch(3), "Branch #
pur_doc(6), "Purchase Document No
po_item(3), "Purchase Document Item No
material(10), "Material Number
qty(7), "Quantity
post_date(6), "Posting Date
date_rec(6), "Receiving date
vendor(6), "Vendor Number
filler(1), "Filler
prog_code(1), "Program Code
action_cd(1), "Action code
unit_cost(6), "Cost
descr(20), "Descr
filler3(5), "Filler
invoice(5), "Invoice Number
codis_part(10), "Codis Part
flag(1), "Flag
filler1(54), "Filler
region(3), "region
branch1(3), "Branch
filler2(10), "Filler
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 = xpost.
gmhead-doc_date = xpost.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'. "01 - MB01 - Goods Receipts for Purchase Order
loop at pcitab.
select single ekko~ebeln ekpo~ebelp ekpo~matnr ekpo~werks
INTO (itab-po_number,itab-po_item,itab-material,itab-plant)
from ekko inner join ekpo on ekko~ebeln = ekpo~ebeln
where IHREZ EQ pcitab+1(9).
CHECK SY-SUBRC EQ 0.
itab-move_type = '101'.
itab-mvt_ind = 'B'.
itab-entry_qnt = '1.000'.
itab-stge_loc = '0001'.
append itab.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gmhead
goodsmvt_code = gmcode
* TESTRUN = 'X'
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.
refresh ITAB.
endloop.
Regards
vijay
02-24-2006 6:52 PM
Hi Vijay! Thanks for your help!
I am creating the material document via BAPI but the BAPI doesn´t creates the document number (docnum). However the MIGO creates a material document (mblnr) and a document number(docnum). This is a brazilian configuration, but the BAPI doesn´t obey this configuration...
I´m using gm_code = '07' . "Subsequent adjustment to a
subcontract order.
Any help will be welcome!
02-24-2006 7:08 PM
Hi,
you can try with LSMW , with the following attribute..
Object 0110 Goods movement
Method 0000
Program Name RM07MMBL
Program Type B Batch Input
or else you can run the program directly with the input file <b>RM07MMBL</b>
for LSMW help check this..
http://www.scmexpertonline.com/downloads/SCM_LSMW_StepsOnWeb.doc
Regards
vijay
02-24-2006 7:14 PM
Hello,
We have used 'BAPI_GOODSMVT_CREATE' for few applications. It does work well and creates Material documents just like MIGO. In order to accomplishment the movements, you need to have Material Documents created. What does the BAPI return in the RETURN parameter?
Thanks,
Venu
02-24-2006 7:41 PM
Hi Venu,
The BAPI creates the material document, the RETURN table returns empty, but the document material (docnum) isn´t created. I go to try to execute the Vijay´s solution, but if you have an idea of what is the problem...
Thanks!
02-24-2006 11:39 PM
Hello,
Do you use BAPI_TRANSACTION_COMMIT or 'commit work and wait' after the BAPI call?
I think the material document is not getting saved.
Thanks,
Venu