‎2016 Aug 01 10:25 PM
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?
‎2016 Aug 01 10:34 PM
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
‎2016 Aug 01 10:53 PM
*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.
* LOOP AT lt_ret1 INTO lt_ret3.
* IF lt_ret3-type = 'E'.
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.
‎2016 Aug 02 2:18 AM
‎2016 Aug 02 2:49 AM
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:".
‎2016 Aug 02 3:42 AM
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.
‎2016 Aug 02 4:33 AM
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.
‎2016 Aug 02 7:09 AM
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.
‎2016 Aug 02 12:54 PM
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
‎2016 Aug 02 4:52 PM
@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.
‎2016 Aug 02 5:21 PM
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
‎2016 Aug 03 1:22 AM
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?
‎2016 Aug 04 9:26 PM
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
‎2016 Aug 09 8:06 PM
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.