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_OUTB_DELIVERY_CREATE_STO issue

Former Member
0 Likes
10,534

Hi All,

I am creating a new PO using BAPI_PO_CREATE1, this PO is generating successfully, after this PO is created I am passing this new PO number to BAPI_OUTB_DELIVERY_CREATE_STO, as stock_trans_item-ref_number = New PO number. But no new delivery is being created and I get error message as "No instance of object type OutboundDelivery has been created. External reference:" . But when I pass the same PO number in this BAPI using SE37, delivery is created successfully. I am not able to figure out the reason behind it. Can someone help me with this issue?

13 REPLIES 13
Read only

Former Member
0 Likes
6,331

Hello Singh,

Can you try to add Commit and wait for 5 seconds so that all the tables will settle in the background and updated. Or sometimes you might need extra fields such as any reference field. Paste code here, so that we can check and suggest.

Thanks,

HIran

Read only

0 Likes
6,331

*Create Purchase Order.

*  IF ls_poheader IS NOT INITIAL.

*    CLEAR: gv_ponum.

*    REFRESH gt_return.

CALL FUNCTION 'BAPI_PO_CREATE1'

  EXPORTING

POHEADER =  ls_poheader

POHEADERX =  ls_poheaderx

TABLES

RETURN = lt_ret1

POITEM = lt_poitem

POITEMX = lt_poitemx

   POSCHEDULE = lt_poschedule

POSCHEDULEX = lt_poschedulex

          .

    READ TABLE lt_ret1 WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT          = 'X'

* IMPORTING

* RETURN        = lt_ret2

          .

WAIT UP TO 5 SECONDS.

  1. ELSE.

*  LOOP AT lt_ret1 INTO lt_ret3.

*    IF lt_ret3-type = 'E'.

  1. ENDIF.

     LOOP AT lt_ret1 INTO lt_ret3.

      IF lt_ret3-type = 'S'.

        lv_p_order = lt_ret3-message_v2.

      ls_order-ref_doc = lv_p_order.

      ENDIF.

      EXIT.

      ENDLOOP.

      Append ls_order to lt_order.

      CLEAR: ls_order.

* Create Delivery

IF NOT lt_order[] IS INITIAL.

CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_STO'

* EXPORTING

* SHIP_POINT =

* DUE_DATE =

* DEBUG_FLG =

* NO_DEQUEUE = ' '

* IMPORTING

* DELIVERY = lv_deli

* NUM_DELIVERIES          =

  TABLES

    STOCK_TRANS_ITEMS = lt_order

* SERIAL_NUMBERS          =

* EXTENSION_IN =

* DELIVERIES =

* CREATED_ITEMS           =

* EXTENSION_OUT           =

RETURN = lt_return.

BREAK-POINT.

      READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT          = 'X'

* IMPORTING

* RETURN        = lt_ret2

          .

WAIT UP TO 5 SECONDS.

  1. ENDIF.
Read only

0 Likes
6,331

Please check whether there are any return values type "E"?

Read only

0 Likes
6,331

There is only one msg in BAPI_OUTB_DELIVERY_CREATE_STO, return and thats type 'E' with text "No instance of object type OutboundDelivery has been created. External reference:".

Read only

0 Likes
6,331

TRy to clear that error the commit statement is not working because sy-subrc ne 0.

or


Try to skip only this particular error message but not all the error messages. let me know if it worked.

Thanks,

HIran.

Read only

Former Member
0 Likes
6,331

Hi J Singh,

Are you testing this code for multiple data ? Try below code. Also if your code in inside loop CLEAR all the variable before main loop start and also REFRESH all internal tables which is passed to BAPI before start of main loop.

CALL FUNCTION 'BAPI_PO_CREATE1'

   EXPORTING

POHEADER ls_poheader

POHEADERX ls_poheaderx

TABLES

RETURN = lt_ret1

POITEM = lt_poitem

POITEMX = lt_poitemx

    POSCHEDULE = lt_poschedule

POSCHEDULEX = lt_poschedulex

           .

     READ TABLE lt_ret1 WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

   ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT          = 'X'

           .

WAIT UP TO 5 SECONDS.

      LOOP AT lt_ret1 INTO lt_ret3.

       IF lt_ret3-type = 'S'.

         lv_p_order = lt_ret3-message_v2.

         ls_order-ref_doc = lv_p_order.                   

       Append ls_order to lt_order.

       EXIT.

       ENDIF.

      ENDLOOP.

       CLEAR: ls_order.

ENDIF.

* Create Delivery

IF NOT lt_order[] IS INITIAL.

CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_STO'

   TABLES

     STOCK_TRANS_ITEMS = lt_order

RETURN = lt_return.

       READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc 0.

  

   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

   EXPORTING

     WAIT          = 'X'.

WAIT UP TO 5 SECONDS.

ENDIF.

Read only

Former Member
0 Likes
6,331

Hi J. Singh,

Kindly check below example.

report  zz_test_create_sto.

parameters: vbeln like ekko-ebeln OBLIGATORY memory id bes,

            vstel like tvst-vstel,

            logsys like tbdls-logsys default 'NONE'.

data: lf_vbeln type vbeln_vl,

      lf_num type vbnum,

      ls_deli type bapishpdelivnumb,

      lt_deli type table of bapishpdelivnumb,

      lt_order type table of bapidlvreftosto,

      ls_order type bapidlvreftosto,

      ls_itm type bapidlvitemcreated,

      lt_itm type table of bapidlvitemcreated,

      ls_ext type bapiparex,

      lt_extin type table of bapiparex,

      lt_extout type table of bapiparex,

      ls_ret type bapiret2,

      lt_return type table of bapiret2.

* StockTransItems (here: complete STO)

ls_order-ref_doc = vbeln.

append ls_order to lt_order.

* ExtensionIn

ls_ext = 'My additional input'.

append ls_ext to lt_extin.

* Synchronous RFC

call function 'BAPI_OUTB_DELIVERY_CREATE_STO'

   DESTINATION logsys

    EXPORTING

       SHIP_POINT              = vstel

*     DUE_DATE                 =

*     DEBUG_FLG               =

  importing

     delivery                = lf_vbeln

    num_deliveries          = lf_num

  tables

    stock_trans_items       = lt_order

    extension_in            = lt_extin

     deliveries              = lt_deli

    created_items           = lt_itm

    extension_out           = lt_extout

     return                  = lt_return

          .

write: / 'Delivery:', lf_vbeln,

       / 'NumDeliveries:', lf_num,

       / 'Deliveries:'.

loop at lt_deli into ls_deli.

  write ls_deli-deliv_numb.

endloop.

if not lt_itm[] is initial.

  write: / 'CreatedItems:'.

  loop at lt_itm into ls_itm.

    write: / ls_itm-ref_doc,

             ls_itm-ref_item,

             ls_itm-deliv_numb,

             ls_itm-deliv_item,

             ls_itm-material,

             ls_itm-dlv_qty,

             ls_itm-sales_unit,

             ls_itm-sales_unit_iso.

  endloop.

endif.

if not lt_return[] is initial.

  write: / 'Return:'.

  loop at lt_return into ls_ret.

    write: / ls_ret-type, ls_ret-id, ls_ret-number,

             ls_ret-message,

           /.

  endloop.

endif.

if not lt_extout[] is initial.

  write: / 'ExtensionOut:'.

  loop at lt_extout into ls_ext.

    write: / ls_ext.

  endloop.

endif.

* COMMIT WORK

if not lf_vbeln is initial.

  commit work.

endif.

Read only

Ashokv
Explorer
0 Likes
6,331

Hi,

It seems to be a timing issue as purchase order still may be in some background task. Try calling next bapi in update task or by triggering job after some time.

Regards,

Ashok

Read only

Former Member
0 Likes
6,331

@Hiren, tried to skip that error but same result. Anyway if bapi return is "No delivery created" than it gets committed or not would give no result.

@Pravin Right now I am using date with just one record, but still I am refreshing all tables before loop.

@Dhreendra I have to pass PO number to generate Delivery.

@Ashok How do I call BAPI in update task, can you please explain a bit more.

One more thing guys, I am adding this code in IF_EX_LE_SHP_DELIVERY_PROC~SAVE_AND_PUBLISH_BEFORE_OUTPUT, if this makes any difference.

Read only

Former Member
0 Likes
6,331

I have a similar issue that I am researching but I was able to overcome the same by using the below approach.

1. Call PO create.

2. Commit With wait (dont add any additional wait times)

3. Create a wrapper FM (lets say ZFM1)for the STO creation. This ZFM1 will have the code for STO creation. Call ZFM1 "IN SEPARATE TASK" with destination as "NONE". You can as well receive the results from the ZFM1 if required (Check the syntax for the same). Based on return table commit the STO inside the ZFM1.

You should also research "Set Update Task To Local".

Thanks,

Vikram.M

Read only

0 Likes
6,331

I have created a wrapper FM, now the issue is when I try to call this FM in my code using 'IN SEPARATE TASK' I get an error saying perform can not be created in global class. And I am writing this code in BADI implementation method.

Now, Can a private method be created? If so than how and should whole code move to new private method or just this FM call?

Read only

0 Likes
6,331

I am not getting the issue about perform. The idea is within the badi method, you should call a FM in separate task. All the data that is required for the FM should be passed from the badi method to the FM.

Hope I am making sense, if not can you add some screen shots?

Thanks,

Vikram.M

Read only

0 Likes
6,331

Yes I tried FM as a separate task. But it is hitting another COMMIT STATEMENT in background that is in a separate, in use custom FM.