11-26-2008 3:51 AM
Hi experts,
I use the bapi: BAPI_PO_CREATE to create a new po, code:
data: it_po_header like bapiekkoc occurs 0 with header line,
it_po_items like bapiekpoc occurs 0 with header line,
it_po_item_add_data like bapiekpoa occurs 0 with header line,
it_po_item_schedules like bapieket occurs 0 with header line,
it_po_item_account_assignment like bapiekkn occurs 0 with header line,
it_return like bapireturn occurs 0 with header line.
data: tmp_purnum like bapiekkoc-po_number.
data: tmp_ebelp like ekpo-ebelp.
refresh: it_po_header, it_po_items, it_po_item_add_data, it_po_item_schedules, it_po_item_account_assignment, it_return.
it_po_header-doc_date = sy-datum.
it_po_header-doc_type = v_doc_type
it_po_header-doc_cat = 'F'.
it_po_header-co_code = c_co_code.
it_po_header-purch_org = c_purch_org.
it_po_header-pur_group = v_pur_group.
it_po_header-vendor = v_vendor.
append it_po_header.
it_po_items-po_item = 10.
it_po_items-material = wa_itab-material.
it_po_items-acctasscat = 'M'.
it_po_items-short_text = wa_itab-short_text.
it_po_items-plant = wa_itab-plant.
it_po_items-unit = wa_itab-unit.
it_po_items-tax_code = wa_itab-tax_code.
it_po_items-net_price = wa_itab-net_price.
it_po_items-price_unit = wa_itab-price_unit.
it_po_items-orderpr_un = wa_itab-orderpr_un.
it_po_items-po_price = 'X'.
append it_po_items.
it_po_item_add_data-po_item = 10.
it_po_item_add_data-gr_ind = 'X'.
it_po_item_add_data-ir_ind = 'X'.
append it_po_item_add_data.
it_po_item_schedules-po_item = 10.
it_po_item_schedules-serial_no = 1.
it_po_item_schedules-deliv_date = sy-datum.
it_po_item_schedules-quantity = wa_itab-quantity.
it_po_item_schedules-preq_no = wa_itab-preq_no.
it_po_item_schedules-preq_item = wa_itab-preq_item.
append it_po_item_schedules.
it_po_item_account_assignment-po_item = 10.
it_po_item_account_assignment-serial_no = 1.
it_po_item_account_assignment-quantity = wa_itab-quantity.
+it_po_item_account_assignment-g_l_acct = '1211010000'.+
it_po_item_account_assignment-sd_doc = wa_itab-sd_doc.
it_po_item_account_assignment-sdoc_item = wa_itab-sdoc_item.
append it_po_item_account_assignment.
clear tmp_purnum.
call function 'BAPI_PO_CREATE'
exporting
po_header = it_po_header
importing
purchaseorder = tmp_purnum
tables
po_items = it_po_items
po_item_add_data = it_po_item_add_data
po_item_schedules = it_po_item_schedules
po_item_account_assignment = it_po_item_account_assignment
return = it_return.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
the error show can not assign the code '1211010000'. but I use me21n it is ok, How can I do? thanks!
11-26-2008 4:10 AM
hi..
check whether the gl ac no '1211010000' exists in
SKA1 database table. field is saknr.
regards,
Padma
11-26-2008 5:06 AM
hi
here is some sample code to help you.you will have to substitute valid values for a couple variables.
constants : c_x value 'X'.
data: del_date type sy-datum.
data: pohead type bapimepoheader.
data: poheadx type bapimepoheaderx.
data: exp_head type bapimepoheader.
data: return type table of bapiret2 with header line.
data: poitem type table of bapimepoitem with header line.
data: poitemx type table of bapimepoitemx with header line.
data: posched type table of bapimeposchedule with header line.
data: poschedx type table of bapimeposchedulx with header line.
data: ex_po_number type bapimepoheader-po_number.
Header Level Data
pohead-comp_code = '0010'.
pohead-doc_type = 'NB' .
pohead-creat_date = sy-datum .
pohead-vendor = '0000012345'.
pohead-purch_org = '1000'.
pohead-pur_group = 'EMG'.
pohead-langu = sy-langu .
pohead-doc_date = sy-datum.
poheadx-comp_code = c_x.
poheadx-doc_type = c_x.
poheadx-creat_date = c_x.
poheadx-vendor = c_x.
poheadx-langu = c_x.
poheadx-purch_org = c_x.
poheadx-pur_group = c_x.
poheadx-doc_date = c_x.
Item Level Data
poitem-po_item = 1.
poitem-material = '000000000040001000'.
poitem-plant = '0006'.
poitem-stge_loc = '6000'.
poitem-quantity = 1.
append poitem.
poitemx-po_item = 1.
poitemx-po_itemx = c_x.
poitemx-material = c_x.
poitemx-plant = c_x .
poitemx-stge_loc = c_x .
poitemx-quantity = c_x .
poitemx-tax_code = c_x .
poitemx-item_cat = c_x .
poitemx-acctasscat = c_x .
append poitemx.
Schedule Line Level Data
posched-po_item = 1.
posched-sched_line = 1.
posched-del_datcat_ext = 'D'.
del_date = sy-datum + 1.
write del_date to posched-delivery_date.
posched-deliv_time = '000001'.
posched-quantity = 1.
append posched.
poschedx-po_item = 1.
poschedx-sched_line = 1.
poschedx-po_itemx = c_x.
poschedx-sched_linex = c_x.
poschedx-del_datcat_ext = c_x.
poschedx-delivery_date = c_x.
poschedx-quantity = c_x.
append poschedx.
call function 'BAPI_PO_CREATE1'
EXPORTING
poheader = pohead
poheaderx = poheadx
testrun = ' '
IMPORTING
exppurchaseorder = ex_po_number
expheader = exp_head
TABLES
return = return
poitem = poitem
poitemx = poitemx
poschedule = posched
poschedulex = poschedx.
call function 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
if not ex_po_number is initial.
call function 'DEQUEUE_ALL'.
else.
call function 'DEQUEUE_ALL'.
message i036.
endif.
hope this helps
regards
Aakash Banga
11-28-2008 3:35 AM