2012 May 16 4:12 AM
Hi experts,
I am trying to create purchase orders using BAPI_PO_CREATE1. I have passed all required fields in the header, item, schedule line and account assignment tables in the BAPI.
I am passing the account assignment as Q. The BAPI gives me the error "SD document not in database or has been archived". I have not passed any refrenece SD document. I am also able to create PO via ME21N with the exact same data.
Our SAP version is ECC 6.0, so the OSS note 910636 is not relevant.
Any inputs on how to solve this issue is highly appreciated.
Thanks,
Saritha.
2012 May 17 2:27 AM
This issue was solved by passing tax code in POACCNT table. I also deleted the code which was passing the schedule line number to POACCNT table.
Thanks,
Saritha.
Hello Saritha,
Refer sample code using BAPI_PO_CREATE1 --> here ...
For all the input data to the BAPI, ensure that the data format is correct (especially Leading Zeroes) or make use of conversion exits wherever necesary.
If this doesn't resolve the issue, then upload the snippet which has the input parameters for the BAPI.
Regards,
Shyam
2012 May 16 4:30 AM
2012 May 16 4:48 AM
No its not a contract material.
In fact we are not passing a material number as we are creating this PO for requesting a service from a vendor and this case we pass a short text into the item table (field SHORT_TEXT in parameter POITEM) and also specify the account assignment category(field ACCTASSCAT in POITEM) as Q.
2012 May 16 4:41 AM
Hello Saritha,
Refer sample code using BAPI_PO_CREATE1 --> here ...
For all the input data to the BAPI, ensure that the data format is correct (especially Leading Zeroes) or make use of conversion exits wherever necesary.
If this doesn't resolve the issue, then upload the snippet which has the input parameters for the BAPI.
Regards,
Shyam
2012 May 16 5:33 AM
Hi Shyam,
In what scenarios would you populate the services data. and in case of services data how do would u specify the account assignment category?
Thanks,
Saritha.
2012 May 16 4:58 AM
2012 May 16 5:11 AM
LOOP AT it_header INTO st_header.
st_poheader-po_number = st_header-ponumber.
st_poheader-comp_code = p_ccode.
st_poheader-doc_type = st_header-potype.
st_poheader-creat_date = sy-datum.
st_poheader-item_intvl = st_output-itemintvl.
st_poheader-vendor = st_header-vendor.
st_poheader-langu = 'E'.
st_poheader-purch_org = p_ekorg.
st_poheader-pur_group = st_header-purchgrp.
CLEAR g_date.
CONCATENATE g_date st_header-docdate+6(4)
st_header-docdate+3(2) st_header-docdate+0(2)
INTO g_date.
st_poheader-doc_date = g_date.
st_poheader-currency = st_header-currency.
st_poheader-ref_1 = st_header-refname1.
st_poheader-our_ref = st_header-refname2.
st_poheader-pmnttrms = st_header-zterm.
st_poheaderx-po_number = 'X'.
st_poheaderx-comp_code = 'X'.
st_poheaderx-doc_type = 'X'.
st_poheaderx-creat_date = 'X'.
st_poheaderx-item_intvl = 'X'.
st_poheaderx-vendor = 'X'.
st_poheaderx-langu = 'X'.
st_poheaderx-pmnttrms = 'X'.
st_poheaderx-purch_org = 'X'.
st_poheaderx-pur_group = 'X'.
st_poheaderx-currency = 'X'.
st_poheaderx-doc_date = 'X'.
st_poheaderx-ref_1 = 'X'.
st_poheaderx-our_ref = 'X'.
st_poheaderx-pmnttrms = 'X'.
LOOP AT it_output INTO st_output
WHERE ponumber = st_header-ponumber.
st_poitem-po_item = st_output-itemno.
st_poitem-short_text = st_output-shrtxt.
IF NOT st_output-matnr IS INITIAL.
st_poitem-material = st_output-matnr.
ENDIF.
st_poitem-plant = p_plant.
IF NOT st_output-lgort IS INITIAL.
st_poitem-stge_loc = st_output-lgort.
ENDIF.
st_poitem-matl_group = st_output-matkl.
st_poitem-quantity = st_output-menge.
st_poitem-po_unit = st_output-uom.
st_poitem-orderpr_un = st_output-uom.
st_poitem-net_price = st_output-netprice.
st_poitem-tax_code = st_output-taxcode.
st_poitem-item_cat = st_output-item_cat.
IF NOT st_output-knttp IS INITIAL.
st_poitem-acctasscat = st_output-knttp.
ENDIF.
IF st_output-netprice = '0.00'.
st_poitem-free_item = 'X'.
ENDIF.
IF NOT st_output-confcntrl IS INITIAL.
st_poitem-conf_ctrl = st_output-confcntrl.
ENDIF.
APPEND st_poitem TO it_poitem.
st_poitemx-po_item = st_output-itemno.
st_poitemx-po_itemx = 'X'.
st_poitemx-short_text = 'X'.
IF NOT st_output-matnr IS INITIAL.
st_poitemx-material = 'X'.
ENDIF.
st_poitemx-plant = 'X'.
IF NOT st_output-lgort IS INITIAL.
st_poitemx-stge_loc = 'X'.
ENDIF.
st_poitemx-matl_group = 'X'.
st_poitemx-quantity = 'X'.
st_poitemx-po_unit = 'X'.
st_poitemx-orderpr_un = 'X'.
st_poitemx-net_price = 'X'.
st_poitemx-tax_code = 'X'.
st_poitemx-item_cat = 'X'.
IF NOT st_output-knttp IS INITIAL.
st_poitemx-acctasscat = 'X'.
ENDIF.
IF st_output-netprice = '0.00'.
st_poitemx-free_item = 'X'.
ENDIF.
IF NOT st_output-confcntrl IS INITIAL.
st_poitemx-conf_ctrl = 'X'.
ENDIF.
APPEND st_poitemx TO it_poitemx.
st_schedule-po_item = st_output-itemno.
st_schedule-sched_line = st_output-etenr.
CLEAR g_date.
CONCATENATE g_date st_output-eindt+6(4)
st_output-eindt+3(2) st_output-eindt+0(2)
INTO g_date.
st_schedule-delivery_date = g_date.
st_schedule-quantity = st_output-menge.
APPEND st_schedule TO it_schedule.
st_schedulex-po_item = st_output-itemno.
st_schedulex-sched_line = st_output-etenr.
st_schedulex-po_itemx = 'X'.
st_schedulex-sched_linex = 'X'.
st_schedulex-delivery_date = 'X'.
st_schedulex-quantity = 'X'.
APPEND st_schedulex TO it_schedulex.
IF NOT st_output-knttp IS INITIAL.
st_poaccnt-po_item = st_output-itemno.
st_poaccnt-serial_no = st_output-zekkn.
st_poaccnt-quantity = st_output-menge.
IF NOT st_output-glaccnt IS INITIAL.
st_poaccnt-gl_account = st_output-glaccnt.
ENDIF.
st_poaccnt-sched_line = st_output-etenr.
IF NOT st_output-kokrs IS INITIAL.
st_poaccnt-co_area = st_output-kokrs.
ENDIF.
IF NOT st_output-prctr IS INITIAL.
st_poaccnt-profit_ctr = st_output-prctr.
ENDIF.
IF NOT st_output-costctr IS INITIAL.
st_poaccnt-costcenter = st_output-costctr.
ENDIF.
IF NOT st_output-wbselmnt IS INITIAL.
st_poaccnt-wbs_element = st_output-wbselmnt.
ENDIF.
APPEND st_poaccnt TO it_poaccnt.
st_poaccntx-po_item = st_output-itemno.
st_poaccntx-serial_no = st_output-zekkn.
st_poaccntx-po_itemx = 'X'.
st_poaccntx-serial_nox = 'X'.
st_poaccntx-quantity = 'X'.
IF NOT st_output-glaccnt IS INITIAL.
st_poaccntx-gl_account = 'X'.
ENDIF.
st_poaccntx-sched_line = 'X'.
IF NOT st_output-kokrs IS INITIAL.
st_poaccntx-co_area = 'X'.
ENDIF.
IF NOT st_output-prctr IS INITIAL.
st_poaccntx-profit_ctr = 'X'.
ENDIF.
IF NOT st_output-costctr IS INITIAL.
st_poaccntx-costcenter = 'X'.
ENDIF.
IF NOT st_output-wbselmnt IS INITIAL.
st_poaccntx-wbs_element = 'X'.
ENDIF.
APPEND st_poaccntx TO it_poaccntx.
ENDIF.
ENDLOOP.
LOOP AT it_texts INTO st_texts
WHERE ponumber = st_header-ponumber.
IF st_texts-objectid = c_ekko.
st_potxthdr-po_number = st_texts-ponumber.
st_potxthdr-po_item = st_texts-poitem.
st_potxthdr-text_id = st_texts-textid.
st_potxthdr-text_form = st_texts-txtformat.
st_potxthdr-text_line = st_texts-textline.
APPEND st_potxthdr TO it_potxthdr.
ELSE.
st_potxtitm-po_number = st_texts-ponumber.
st_potxtitm-po_item = st_texts-poitem.
st_potxtitm-text_id = st_texts-textid.
st_potxtitm-text_form = st_texts-txtformat.
st_potxtitm-text_line = st_texts-textline.
APPEND st_potxtitm TO it_potxtitm.
ENDIF.
ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = st_poheader
poheaderx = st_poheaderx
IMPORTING
exppurchaseorder = g_ponumber
TABLES
return = it_return
poitem = it_poitem
poitemx = it_poitemx
poschedule = it_schedule
poschedulex = it_schedulex
poaccount = it_poaccnt
poaccountx = it_poaccntx
potextheader = it_potxthdr
potextitem = it_potxtitm.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
* IMPORTING
* RETURN =
.
ENDIF.
ENDLOOP.
Also here is my upload file
| potype | ponumber | pocat | itemno | purchgrp | itemintvl | zterm | currency | vendor | docdate | refname1 | refname2 | matnr | shrtxt | lgort | matkl | menge | uom | netprice | taxcode | confcntrl | itm catgry | knttp | etenr | eindt | zekkn | glaccnt | kokrs | prctr | costctr | wbselmnt | error | messg |
| NB | 1234567890 | F | 00001 | 123 | 00001 | zzzz | USD | 123456 | 16.05.2012 | test | test | testy thing | test | 1.000 | EA | 100.00 | 0 | Q | 0001 | 22.05.2012 | 01 | 123456 | 1234 |
2012 May 16 5:21 AM
Hi Mohan,
In which field you are passing the so?
Can you pass minimum data and see.
Regards,
Madhu.
Message was edited by: Madhu Vadlamani
2012 May 16 5:24 AM
I am not passing sales document number as we do not want create this PO with any reference SD document.
Thanks,
Saritha.
2012 May 16 5:17 AM
I also tried changing the account assignment category from Q to K and the error still exists.
given below is the return table from BAPI
| TYPE | ID | NUMBER | MESSAGE |
| E | MEPO | 46 | Purchase order item 00001 still contains faulty account assignments |
| E | BAPI | 1 | No instance of object type PurchaseOrder has been created. External reference: |
| W | ME | 40 | Can delivery date be met? |
| E | V1 | 302 | SD document is not in the database or has been archived |
2012 May 16 5:42 AM
Hi,
After passing header and item data into the BAPI,Try calling BAPI_TRANSACTION_COMMIT.I guess ,this is the reason for the error "Document is not in the database or has been archived".
Thanks
Naresh
2012 May 16 6:03 AM
Hi Naresh,
I am already calling BAPI_TRANSACTION_COMMIT. Since the BAPI_PO_CREATE1 already gives me errors in the return table, there is no point in doing COMMIT.
Thanks,
Saritha.
2012 May 17 2:27 AM
This issue was solved by passing tax code in POACCNT table. I also deleted the code which was passing the schedule line number to POACCNT table.
Thanks,
Saritha.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |