Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_PO_CREATE1 Error: SD document not in database or has been archived

Former Member
0 Likes
3,110

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,570

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.

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.

12 REPLIES 12
Read only

Former Member
0 Likes
2,570

Maybe the material you are using is referring to a Contract

Read only

0 Likes
2,570

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.

Read only

ShyamPindiproli
Active Participant
0 Likes
2,570

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

Read only

0 Likes
2,570

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.

Read only

madhu_vadlamani
Active Contributor
0 Likes
2,570

Hi Mohan,

Please paste your code.

Regards,

Madhu.

Read only

0 Likes
2,570

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

potypeponumberpocatitemnopurchgrpitemintvlztermcurrencyvendordocdaterefname1refname2matnrshrtxtlgortmatklmengeuomnetpricetaxcodeconfcntrlitm catgryknttpetenreindtzekknglaccntkokrsprctrcostctrwbselmnterrormessg
NB1234567890F0000112300001zzzzUSD12345616.05.2012testtest
testy thing
test1.000EA100.00

0Q000122.05.201201123456

1234
Read only

0 Likes
2,570

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

Read only

0 Likes
2,570

I am not passing sales document number as we do not want create this PO with any reference SD document.

Thanks,
Saritha.

Read only

Former Member
0 Likes
2,570

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

TYPEIDNUMBERMESSAGE
EMEPO46Purchase order item 00001 still contains faulty account assignments
EBAPI1No instance of object type PurchaseOrder has been created. External reference:
WME40Can delivery date be met?
EV1302SD document  is not in the database or has been archived
Read only

0 Likes
2,570

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

Read only

0 Likes
2,570

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.

Read only

Former Member
0 Likes
2,571

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.