04-05-2006 2:51 PM
Hi All,
Is there a BAPI for selecting multiple line items in a Purchase Order (based on the material number), updating each one and posting a Goods receipt with one single material document number?
Thanks in advance.
Regards,
Manu.
04-05-2006 2:53 PM
04-05-2006 2:53 PM
04-05-2006 3:00 PM
Hi,
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